[copr] master: simplify configuration - introduce /etc/copr/copr*.conf (6e1179e)

msuchy at fedoraproject.org msuchy at fedoraproject.org
Fri Jun 28 17:01:26 UTC 2013


Repository : http://git.fedorahosted.org/cgit/copr.git

On branch  : master

>---------------------------------------------------------------

commit 6e1179ed1b270eab35d361f9623532453fce07ab
Author: Miroslav Suchý <msuchy at redhat.com>
Date:   Fri Jun 28 18:01:30 2013 +0200

    simplify configuration - introduce /etc/copr/copr*.conf
    
    Now config.py contains just defaults. You should put your own configuration
    into /etc/copr/copr.conf. Initial file is provided.
    Configuration for unit test is taken from /etc/copr/copr_unit_test.conf.
    
    You can always provide your own config by passing COPR_CONFIG environment
    variable. E.g:
    COPR_CONFIG=/etc/copr/copr_devel.conf ./manage.py
    
    This also allow to preserve user configuration when deploying new version of
    copr, while introduce the new defaults.
    
    Direct edit of config.py is not recommended. Especially in production.


>---------------------------------------------------------------

 copr-setup.txt                            |   12 ++++++------
 copr.spec                                 |    8 +++++++-
 coprs_frontend/config/copr.conf           |   29 +++++++++++++++++++++++++++++
 coprs_frontend/config/copr_devel.conf     |   29 +++++++++++++++++++++++++++++
 coprs_frontend/config/copr_unit_test.conf |   29 +++++++++++++++++++++++++++++
 coprs_frontend/coprs/__init__.py          |    5 +++++
 coprs_frontend/coprs/config.py            |    2 +-
 coprs_frontend/manage.py                  |    1 +
 8 files changed, 107 insertions(+), 8 deletions(-)

diff --git a/copr-setup.txt b/copr-setup.txt
index f5a7ad6..266799d 100644
--- a/copr-setup.txt
+++ b/copr-setup.txt
@@ -66,13 +66,13 @@ Frontend:
   - pip install -I  SQLAlchemy MarkupSafe 
   - pip install pytest
 
-- edit credentials in coprs_frontend/coprs/config.py
+- edit credentials /etc/copr/copr.conf (or /etc/copr/copr-devel.conf for development mode)
 - cd /usr/share/copr/coprs_frontend
 - configure DB first - see DB section below
 # for develop setup do:
-- ./manage.py create_db --alembic alembic.ini
+COPR_CONFIG=/etc/copr/copr_devel.conf ./manage.py create_db --alembic alembic.ini
 # for production setup do:
-COPRS_ENVIRON_PRODUCTION=1 ./manage.py create_db  --alembic alembic.ini
+./manage.py create_db  --alembic alembic.ini
 
 - for developing you can run:
   ./manage.py runserver -t <FQDN>
@@ -83,7 +83,7 @@ COPRS_ENVIRON_PRODUCTION=1 ./manage.py create_db  --alembic alembic.ini
 - setenforce 0 (sorry, putting on TODO)
 
 - Add chroots. E.g:
- su - copr-fe -c 'OPRS_ENVIRON_PRODUCTION=1  ./manage.py create_chroot fedora-18-x86_64 fedora-18-i386'
+ su - copr-fe -c './manage.py create_chroot fedora-18-x86_64 fedora-18-i386'
 
 
 DB config
@@ -95,8 +95,8 @@ SQLite
 ~~~~~~
 
 - yum install sqlite
-- in file coprs_frontend/coprs/config.py put:
-  SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.abspath(DATABASE)
+- in file /etc/copr/copr.conf put:
+  SQLALCHEMY_DATABASE_URI = 'sqlite:////usr/share/copr/data/copr.db'
 This will use sqlite db file in /usr/share/copr/data/copr.db (manage.py will create that file)
 - Note that you have to either create db as copr-fe user or you have to run:
   chown copr-fe:copr-fe /usr/share/copr/data/copr.db
diff --git a/copr.spec b/copr.spec
index 19c40f4..088e3f2 100644
--- a/copr.spec
+++ b/copr.spec
@@ -92,6 +92,7 @@ a2x -d manpage -f manpage man/copr-cli.1.asciidoc
 %install
 
 #frontend
+install -d %{buildroot}%{_sysconfdir}
 install -d %{buildroot}%{_datadir}/copr/coprs_frontend
 install -d %{buildroot}%{_datadir}/copr/data/openid_store
 install -d %{buildroot}%{_datadir}/copr/data/openid_store/associations
@@ -102,6 +103,7 @@ install -d %{buildroot}%{_datadir}/copr/data/whooshee/copr_user_whoosheer
 
 cp -a coprs_frontend/* %{buildroot}%{_datadir}/copr/coprs_frontend
 mv %{buildroot}%{_datadir}/copr/coprs_frontend/coprs.conf.example ./
+mv %{buildroot}%{_datadir}/copr/coprs_frontend/config %{buildroot}%{_sysconfdir}/copr
 rm %{buildroot}%{_datadir}/copr/coprs_frontend/CONTRIBUTION_GUIDELINES
 touch %{buildroot}%{_datadir}/copr/data/copr.db
 
@@ -137,7 +139,11 @@ useradd -r -g copr-fe -G copr-fe -d %{_datadir}/copr/coprs_frontend -s /bin/bash
 
 %{_datadir}/copr/coprs_frontend
 %ghost %{_datadir}/copr/data/copr.db
-%config(noreplace)%{_datadir}/copr/coprs_frontend/coprs/config.py
+%{_datadir}/copr/coprs_frontend/coprs/config.py
+
+%defattr(600, copr-fe, copr-fe, 700)
+%dir %{_sysconfdir}/copr
+%config(noreplace)  %{_sysconfdir}/copr/*
 
 %files cli
 %doc LICENSE README.rst
diff --git a/coprs_frontend/config/copr.conf b/coprs_frontend/config/copr.conf
new file mode 100644
index 0000000..576db7b
--- /dev/null
+++ b/coprs_frontend/config/copr.conf
@@ -0,0 +1,29 @@
+# Directory and files where is stored Copr database files
+#DATA_DIR = '/usr/share/copr/data'
+#DATABASE = '/usr/share/copr/data/copr.db'
+#OPENID_STORE = '/usr/share/copr/data/openid_store'
+#WHOOSHEE_DIR = '/usr/share/copr/data/whooshee'
+
+#SECRET_KEY = 'put_some_secret_here'
+#BACKEND_PASSWORD = 'password_here'
+
+# restrict access to a set of users
+#USE_ALLOWED_USERS = False
+#ALLOWED_USERS = ['bonnie', 'clyde']
+
+SQLALCHEMY_DATABASE_URI = 'postgresql+psycopg2://copr-fe:coprpass@/coprdb'
+
+# Token length, defaults to 30 (max 255)
+#API_TOKEN_LENGTH = 30
+
+# Expiration of API token in days
+#API_TOKEN_EXPIRATION = 180
+
+# logging options
+#SEND_LOGS_TO = ['root at localhost']
+#LOGGING_LEVEL = logging.ERROR
+
+DEBUG = False
+SQLALCHEMY_ECHO = False
+
+##CSRF_ENABLED = True
diff --git a/coprs_frontend/config/copr_devel.conf b/coprs_frontend/config/copr_devel.conf
new file mode 100644
index 0000000..cd9eb32
--- /dev/null
+++ b/coprs_frontend/config/copr_devel.conf
@@ -0,0 +1,29 @@
+# Directory and files where is stored Copr database files
+#DATA_DIR = '/usr/share/copr/data'
+#DATABASE = '/usr/share/copr/data/copr.db'
+#OPENID_STORE = '/usr/share/copr/data/openid_store'
+#WHOOSHEE_DIR = '/usr/share/copr/data/whooshee'
+
+#SECRET_KEY = 'put_some_secret_here'
+#BACKEND_PASSWORD = 'password_here'
+
+# restrict access to a set of users
+#USE_ALLOWED_USERS = False
+#ALLOWED_USERS = ['bonnie', 'clyde']
+
+#SQLALCHEMY_DATABASE_URI = 'sqlite:////usr/share/copr/data/copr.db'
+
+# Token length, defaults to 30 (max 255)
+#API_TOKEN_LENGTH = 30
+
+# Expiration of API token in days
+#API_TOKEN_EXPIRATION = 180
+
+# logging options
+#SEND_LOGS_TO = ['root at localhost']
+#LOGGING_LEVEL = logging.ERROR
+
+DEBUG = True
+SQLALCHEMY_ECHO = True
+
+#CSRF_ENABLED = True
diff --git a/coprs_frontend/config/copr_unit_test.conf b/coprs_frontend/config/copr_unit_test.conf
new file mode 100644
index 0000000..0efcc07
--- /dev/null
+++ b/coprs_frontend/config/copr_unit_test.conf
@@ -0,0 +1,29 @@
+# Directory and files where is stored Copr database files
+#DATA_DIR = '/usr/share/copr/data'
+DATABASE = '/usr/share/copr/coprs_frontend/tests/data/copr.db'
+OPENID_STORE = '/usr/share/copr/coprs_frontend/tests/data/openid_store'
+WHOOSHEE_DIR = '/usr/share/copr/coprs_frontend/tests/data/whooshee'
+
+#SECRET_KEY = 'put_some_secret_here'
+#BACKEND_PASSWORD = 'password_here'
+
+# restrict access to a set of users
+#USE_ALLOWED_USERS = False
+#ALLOWED_USERS = ['bonnie', 'clyde']
+
+SQLALCHEMY_DATABASE_URI = 'sqlite:///' + DATABASE
+
+# Token length, defaults to 30 (max 255)
+#API_TOKEN_LENGTH = 30
+
+# Expiration of API token in days
+#API_TOKEN_EXPIRATION = 180
+
+# logging options
+#SEND_LOGS_TO = ['root at localhost']
+#LOGGING_LEVEL = logging.ERROR
+
+#DEBUG = False
+#SQLALCHEMY_ECHO = False
+
+CSRF_ENABLED = False
diff --git a/coprs_frontend/coprs/__init__.py b/coprs_frontend/coprs/__init__.py
index 103d7e1..bb2157f 100644
--- a/coprs_frontend/coprs/__init__.py
+++ b/coprs_frontend/coprs/__init__.py
@@ -15,6 +15,11 @@ elif 'COPRS_ENVIRON_UNITTEST' in os.environ:
     app.config.from_object('coprs.config.UnitTestConfig')
 else:
     app.config.from_object('coprs.config.DevelopmentConfig')
+if os.environ.get('COPR_CONFIG'):
+	app.config.from_envvar('COPR_CONFIG')
+else:
+    app.config.from_pyfile('/etc/copr/copr.conf', silent=True)
+
 
 oid = OpenID(app, app.config['OPENID_STORE'])
 db = SQLAlchemy(app)
diff --git a/coprs_frontend/coprs/config.py b/coprs_frontend/coprs/config.py
index 1b735e4..a84cee6 100644
--- a/coprs_frontend/coprs/config.py
+++ b/coprs_frontend/coprs/config.py
@@ -23,7 +23,7 @@ class Config(object):
     API_TOKEN_EXPIRATION = 180
 
     # logging options
-    SEND_LOGS_TO = []
+    SEND_LOGS_TO = ['root at localhost']
     LOGGING_LEVEL = logging.ERROR
 
 class ProductionConfig(Config):
diff --git a/coprs_frontend/manage.py b/coprs_frontend/manage.py
index 1b798e9..ab811d8 100755
--- a/coprs_frontend/manage.py
+++ b/coprs_frontend/manage.py
@@ -16,6 +16,7 @@ from coprs.logic import coprs_logic
 class TestCommand(Command):
     def run(self, test_args):
         os.environ['COPRS_ENVIRON_UNITTEST'] = '1'
+        os.environ['COPR_CONFIG'] = '/etc/copr/copr_unit_test.conf'
         os.environ['PYTHONPATH'] = '.'
         subprocess.call(['py.test'] + (test_args or []))
 



More information about the copr-devel mailing list