From cf7eac51876ab3307fe093a91ade86d22c32be05 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Tue, 19 Apr 2016 12:20:50 +0200 Subject: [PATCH] refactor app --- app/deploy/crontab.template | 3 - app/deploy/gunicorn.conf.py.template | 8 - app/deploy/local_settings.py.template | 37 ---- app/deploy/my.cnf | 193 -------------------- app/deploy/nginx.conf.template | 55 ------ app/{sandbox => }/local_settings.py | 0 app/manage.py | 8 +- app/{sandbox => }/middleware.py | 0 app/{sandbox => }/routers.py | 0 app/sandbox/__init__.py | 0 app/{deploy/start_app.sh => scripts/app.sh} | 2 +- app/{deploy => scripts}/wait.sh | 0 app/{sandbox => }/settings.py | 4 +- app/{sandbox => }/urls.py | 0 app/wait.py | 2 +- app/wsgi.py | 18 +- docker-compose.yml | 4 +- env/dev.yml | 2 +- app/deploy/nginx-app.conf => etc/nginx.conf | 0 19 files changed, 13 insertions(+), 323 deletions(-) delete mode 100644 app/deploy/crontab.template delete mode 100644 app/deploy/gunicorn.conf.py.template delete mode 100644 app/deploy/local_settings.py.template delete mode 100644 app/deploy/my.cnf delete mode 100644 app/deploy/nginx.conf.template rename app/{sandbox => }/local_settings.py (100%) rename app/{sandbox => }/middleware.py (100%) rename app/{sandbox => }/routers.py (100%) delete mode 100644 app/sandbox/__init__.py rename app/{deploy/start_app.sh => scripts/app.sh} (97%) rename app/{deploy => scripts}/wait.sh (100%) rename app/{sandbox => }/settings.py (99%) rename app/{sandbox => }/urls.py (100%) rename app/deploy/nginx-app.conf => etc/nginx.conf (100%) diff --git a/app/deploy/crontab.template b/app/deploy/crontab.template deleted file mode 100644 index c4af8cf2..00000000 --- a/app/deploy/crontab.template +++ /dev/null @@ -1,3 +0,0 @@ -# Poll Twitter every 5 minutes -# Comment-out if you don't use Mezzanine's Twitter app -*/5 * * * * %(user)s %(manage)s poll_twitter diff --git a/app/deploy/gunicorn.conf.py.template b/app/deploy/gunicorn.conf.py.template deleted file mode 100644 index 257bb979..00000000 --- a/app/deploy/gunicorn.conf.py.template +++ /dev/null @@ -1,8 +0,0 @@ -from __future__ import unicode_literals -import multiprocessing - -bind = "unix:%(proj_path)s/gunicorn.sock" -workers = %(num_workers)s -errorlog = "/home/%(user)s/logs/%(proj_name)s_error.log" -loglevel = "error" -proc_name = "%(proj_name)s" diff --git a/app/deploy/local_settings.py.template b/app/deploy/local_settings.py.template deleted file mode 100644 index d8dc9a06..00000000 --- a/app/deploy/local_settings.py.template +++ /dev/null @@ -1,37 +0,0 @@ -from __future__ import unicode_literals - -SECRET_KEY = "%(secret_key)s" -NEVERCACHE_KEY = "%(nevercache_key)s" -ALLOWED_HOSTS = [%(domains_python)s] - -DATABASES = { - "default": { - # Ends with "postgresql_psycopg2", "mysql", "sqlite3" or "oracle". - "ENGINE": "django.db.backends.postgresql_psycopg2", - # DB name or path to database file if using sqlite3. - "NAME": "%(proj_name)s", - # Not used with sqlite3. - "USER": "%(proj_name)s", - # Not used with sqlite3. - "PASSWORD": "%(db_pass)s", - # Set to empty string for localhost. Not used with sqlite3. - "HOST": "127.0.0.1", - # Set to empty string for default. Not used with sqlite3. - "PORT": "", - } -} - -SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTOCOL", "https") - -CACHE_MIDDLEWARE_SECONDS = 60 - -CACHE_MIDDLEWARE_KEY_PREFIX = "%(proj_name)s" - -CACHES = { - "default": { - "BACKEND": "django.core.cache.backends.memcached.MemcachedCache", - "LOCATION": "127.0.0.1:11211", - } -} - -SESSION_ENGINE = "django.contrib.sessions.backends.cache" diff --git a/app/deploy/my.cnf b/app/deploy/my.cnf deleted file mode 100644 index 7d10856b..00000000 --- a/app/deploy/my.cnf +++ /dev/null @@ -1,193 +0,0 @@ -# MariaDB database server configuration file. -# -# You can copy this file to one of: -# - "/etc/mysql/my.cnf" to set global options, -# - "~/.my.cnf" to set user-specific options. -# -# One can use all long options that the program supports. -# Run program with --help to get a list of available options and with -# --print-defaults to see which it would actually understand and use. -# -# For explanations see -# http://dev.mysql.com/doc/mysql/en/server-system-variables.html - -# This will be passed to all mysql clients -# It has been reported that passwords should be enclosed with ticks/quotes -# escpecially if they contain "#" chars... -# Remember to edit /etc/mysql/debian.cnf when changing the socket location. -[client] -port = 3306 -socket = /var/run/mysqld/mysqld.sock - -# Here is entries for some specific programs -# The following values assume you have at least 32M ram - -# This was formally known as [safe_mysqld]. Both versions are currently parsed. -[mysqld_safe] -socket = /var/run/mysqld/mysqld.sock -nice = 0 - -[mysqld] -skip-host-cache -skip-name-resolve -# -# * Basic Settings -# -user = mysql -pid-file = /var/run/mysqld/mysqld.pid -socket = /var/run/mysqld/mysqld.sock -port = 3306 -basedir = /usr -datadir = /var/lib/mysql -tmpdir = /tmp -lc_messages_dir = /usr/share/mysql -lc_messages = en_US -skip-external-locking -# -# Instead of skip-networking the default is now to listen only on -# localhost which is more compatible and is not less secure. - -bind-address = 0.0.0.0 - -# -# * Fine Tuning -# -max_connections = 100 -connect_timeout = 5 -wait_timeout = 600 -max_allowed_packet = 16M -thread_cache_size = 128 -sort_buffer_size = 4M -bulk_insert_buffer_size = 16M -tmp_table_size = 32M -max_heap_table_size = 32M -# -# * MyISAM -# -# This replaces the startup script and checks MyISAM tables if needed -# the first time they are touched. On error, make copy and try a repair. -myisam_recover_options = BACKUP -key_buffer_size = 128M -#open-files-limit = 2000 -table_open_cache = 400 -myisam_sort_buffer_size = 512M -concurrent_insert = 2 -read_buffer_size = 2M -read_rnd_buffer_size = 1M -# -# * Query Cache Configuration -# -# Cache only tiny result sets, so we can fit more in the query cache. -query_cache_limit = 128K -query_cache_size = 64M -# for more write intensive setups, set to DEMAND or OFF -#query_cache_type = DEMAND -# -# * Logging and Replication -# -# Both location gets rotated by the cronjob. -# Be aware that this log type is a performance killer. -# As of 5.1 you can enable the log at runtime! -#general_log_file = /var/log/mysql/mysql.log -#general_log = 1 -# -# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf. -# -# we do want to know about network errors and such -#log_warnings = 2 -# -# Enable the slow query log to see queries with especially long duration -#slow_query_log[={0|1}] -slow_query_log_file = /var/log/mysql/mariadb-slow.log -long_query_time = 10 -#log_slow_rate_limit = 1000 -#log_slow_verbosity = query_plan - -#log-queries-not-using-indexes -#log_slow_admin_statements -# -# The following can be used as easy to replay backup logs or for replication. -# note: if you are setting up a replication slave, see README.Debian about -# other settings you may need to change. -#server-id = 1 -#report_host = master1 -#auto_increment_increment = 2 -#auto_increment_offset = 1 -#log_bin = /var/log/mysql/mariadb-bin -#log_bin_index = /var/log/mysql/mariadb-bin.index -# not fab for performance, but safer -#sync_binlog = 1 -expire_logs_days = 10 -max_binlog_size = 100M -# slaves -#relay_log = /var/log/mysql/relay-bin -#relay_log_index = /var/log/mysql/relay-bin.index -#relay_log_info_file = /var/log/mysql/relay-bin.info -#log_slave_updates -#read_only -# -# If applications support it, this stricter sql_mode prevents some -# mistakes like inserting invalid dates etc. -#sql_mode = NO_ENGINE_SUBSTITUTION,TRADITIONAL -# -# * InnoDB -# -# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. -# Read the manual for more InnoDB related options. There are many! -default_storage_engine = InnoDB -# you can't just change log file size, requires special procedure -#innodb_log_file_size = 50M -innodb_buffer_pool_size = 256M -innodb_log_buffer_size = 8M -innodb_file_per_table = 1 -innodb_open_files = 400 -innodb_io_capacity = 400 -innodb_flush_method = O_DIRECT -# -# * Security Features -# -# Read the manual, too, if you want chroot! -# chroot = /var/lib/mysql/ -# -# For generating SSL certificates I recommend the OpenSSL GUI "tinyca". -# -# ssl-ca=/etc/mysql/cacert.pem -# ssl-cert=/etc/mysql/server-cert.pem -# ssl-key=/etc/mysql/server-key.pem - -# -# * Galera-related settings -# -[galera] -# Mandatory settings -#wsrep_on=ON -#wsrep_provider= -#wsrep_cluster_address= -#binlog_format=row -#default_storage_engine=InnoDB -#innodb_autoinc_lock_mode=2 -# -# Allow server to accept connections on all interfaces. -# -#bind-address=0.0.0.0 -# -# Optional setting -#wsrep_slave_threads=1 -#innodb_flush_log_at_trx_commit=0 - -[mysqldump] -quick -quote-names -max_allowed_packet = 16M - -[mysql] -#no-auto-rehash # faster start of mysql but no tab completition - -[isamchk] -key_buffer = 16M - -# -# * IMPORTANT: Additional settings that can override those from this file! -# The files must end with '.cnf', otherwise they'll be ignored. -# -!includedir /etc/mysql/conf.d/ diff --git a/app/deploy/nginx.conf.template b/app/deploy/nginx.conf.template deleted file mode 100644 index f99430af..00000000 --- a/app/deploy/nginx.conf.template +++ /dev/null @@ -1,55 +0,0 @@ - -upstream %(proj_name)s { - server unix:%(proj_path)s/gunicorn.sock fail_timeout=0; -} - -server { - - listen 80; - %(ssl_disabled)s listen 443 ssl; - server_name %(domains_nginx)s; - client_max_body_size 10M; - keepalive_timeout 15; - error_log /home/%(user)s/logs/%(proj_name)s_error_nginx.log info; - - %(ssl_disabled)s ssl_certificate conf/%(proj_name)s.crt; - %(ssl_disabled)s ssl_certificate_key conf/%(proj_name)s.key; - %(ssl_disabled)s ssl_session_cache shared:SSL:10m; - %(ssl_disabled)s ssl_session_timeout 10m; - %(ssl_disabled)s ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA; - %(ssl_disabled)s ssl_prefer_server_ciphers on; - - # Deny illegal Host headers - if ($host !~* ^(%(domains_regex)s)$) { - return 444; - } - - location / { - proxy_redirect off; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Protocol $scheme; - proxy_pass http://%(proj_name)s; - } - - location /static/ { - root %(proj_path)s; - access_log off; - log_not_found off; - expires 30d; - } - - location /robots.txt { - root %(proj_path)s/static; - access_log off; - log_not_found off; - } - - location /favicon.ico { - root %(proj_path)s/static/img; - access_log off; - log_not_found off; - } - -} diff --git a/app/sandbox/local_settings.py b/app/local_settings.py similarity index 100% rename from app/sandbox/local_settings.py rename to app/local_settings.py diff --git a/app/manage.py b/app/manage.py index 7102e85f..87ab2e2d 100755 --- a/app/manage.py +++ b/app/manage.py @@ -3,12 +3,6 @@ import os import sys if __name__ == "__main__": - - from mezzanine.utils.conf import real_project_name - - settings_module = "%s.settings" % real_project_name("sandbox") - os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_module) - + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") from django.core.management import execute_from_command_line - execute_from_command_line(sys.argv) diff --git a/app/sandbox/middleware.py b/app/middleware.py similarity index 100% rename from app/sandbox/middleware.py rename to app/middleware.py diff --git a/app/sandbox/routers.py b/app/routers.py similarity index 100% rename from app/sandbox/routers.py rename to app/routers.py diff --git a/app/sandbox/__init__.py b/app/sandbox/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/app/deploy/start_app.sh b/app/scripts/app.sh similarity index 97% rename from app/deploy/start_app.sh rename to app/scripts/app.sh index 320752d6..962cf9a7 100644 --- a/app/deploy/start_app.sh +++ b/app/scripts/app.sh @@ -24,7 +24,7 @@ patterns='*.js;*.css;*.jpg;*.jpeg;*.gif;*.png;*.svg;*.ttf;*.eot;*.woff;*.woff2' chown -R $uid:$gid $media # waiting for other services -sh $app/deploy/wait.sh +sh $app/scripts/wait.sh # waiting for available database # python $app/wait.py diff --git a/app/deploy/wait.sh b/app/scripts/wait.sh similarity index 100% rename from app/deploy/wait.sh rename to app/scripts/wait.sh diff --git a/app/sandbox/settings.py b/app/settings.py similarity index 99% rename from app/sandbox/settings.py rename to app/settings.py index e6285454..e48f9232 100644 --- a/app/sandbox/settings.py +++ b/app/settings.py @@ -189,7 +189,7 @@ MEDIA_URL = "/media/" MEDIA_ROOT = '/srv/media/' # Package/module name to import the root urlpatterns from for the project. -ROOT_URLCONF = "%s.urls" % PROJECT_APP +ROOT_URLCONF = "urls" ################ @@ -306,7 +306,7 @@ OPTIONAL_APPS = ( # ignored in your version control system allowing for settings to be # defined per machine. try: - from .local_settings import * + from local_settings import * except ImportError as e: if "local_settings" not in str(e): raise e diff --git a/app/sandbox/urls.py b/app/urls.py similarity index 100% rename from app/sandbox/urls.py rename to app/urls.py diff --git a/app/wait.py b/app/wait.py index 877edbd3..1fb048ab 100644 --- a/app/wait.py +++ b/app/wait.py @@ -4,7 +4,7 @@ import os, time from django.core.management import call_command up = False -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sandbox.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") while not up: try: diff --git a/app/wsgi.py b/app/wsgi.py index aa519c45..bc6fde2b 100644 --- a/app/wsgi.py +++ b/app/wsgi.py @@ -1,18 +1,10 @@ -""" -WSGI config for diggersdigest project. - -It exposes the WSGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ -""" +#!/usr/bin/python +# -*- coding: utf-8 -*- import os +import sys from django.core.wsgi import get_wsgi_application -from mezzanine.utils.conf import real_project_name - -settings_module = "%s.settings" % real_project_name("sandbox") - -os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_module) +sys.path.append(os.path.dirname('.')) +os.environ.setdefault("DJANGO_SETTINGS_MODULE", 'settings') application = get_wsgi_application() diff --git a/docker-compose.yml b/docker-compose.yml index 21b21924..7ab6d84f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -49,7 +49,7 @@ pgdb: app: build: . - command: /bin/sh deploy/start_app.sh + command: /bin/sh scripts/app.sh volumes: - ./app/:/srv/app - ./lib/mezzanine-agenda/:/srv/lib/mezzanine-agenda @@ -68,7 +68,7 @@ nginx: ports: - "80:80" volumes: - - ./app/deploy/nginx-app.conf:/etc/nginx/conf.d/default.conf + - ./etc/nginx.conf:/etc/nginx/conf.d/default.conf - ./data/var/log/nginx/:/var/log/nginx volumes_from: - data diff --git a/env/dev.yml b/env/dev.yml index ffd7fd27..2236339c 100644 --- a/env/dev.yml +++ b/env/dev.yml @@ -20,7 +20,7 @@ app: - command: /bin/sh deploy/start_app.sh --runserver + command: /bin/sh scripts/app.sh --runserver volumes: - ./app/:/srv/app ports: diff --git a/app/deploy/nginx-app.conf b/etc/nginx.conf similarity index 100% rename from app/deploy/nginx-app.conf rename to etc/nginx.conf -- 2.39.5