From d5c6d4d0e55a2a1ba3a3e5aafb04fedb9782036e Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Thu, 24 Sep 2015 11:55:59 +0200 Subject: [PATCH] make docker, uswgi and app config more generic --- Dockerfile | 11 +- {diggersdigest => app}/__init__.py | 0 .../deploy/crontab.template | 0 .../deploy/gunicorn.conf.py.template | 0 .../deploy/local_settings.py.template | 0 app/deploy/nginx-app.conf | 29 + .../deploy/nginx.conf.template | 0 app/deploy/start_app.sh | 25 + .../deploy/supervisor.conf.template | 0 app/deploy/wait.sh | 18 + .../diggersdigest/__init__.py | 0 .../diggersdigest/local_settings.py | 0 .../diggersdigest/migrations/__init__.py | 0 .../migrations/blog/0001_initial.py | 0 .../blog/0002_auto_20150527_1555.py | 0 .../blog/0003_blogpost_related_products.py | 0 .../diggersdigest/migrations/blog/__init__.py | 0 .../migrations/shop/0001_initial.py | 0 .../shop/0002_order_callback_uuid.py | 0 .../shop/0003_auto_20150906_1911.py | 0 .../diggersdigest/migrations/shop/__init__.py | 0 .../diggersdigest/settings.py | 12 +- {diggersdigest => app}/diggersdigest/urls.py | 0 {diggersdigest => app}/manage.py | 0 {diggersdigest => app}/records/__init__.py | 0 {diggersdigest => app}/records/admin.py | 0 .../records/management/__init__.py | 0 .../records/management/commands/__init__.py | 0 .../management/commands/populate_db.py | 0 .../records/migrations/0001_initial.py | 0 .../migrations/0002_auto_20150831_1518.py | 0 .../migrations/0003_record_date_text.py | 0 .../migrations/0004_auto_20150904_0733.py | 0 .../migrations/0005_auto_20150904_1309.py | 0 .../migrations/0006_auto_20150907_0835.py | 0 .../records/migrations/0007_record_image.py | 0 .../migrations/0008_auto_20150909_0818.py | 0 .../migrations/0009_remove_record_image.py | 0 .../migrations/0010_auto_20150909_1400.py | 0 .../records/migrations/__init__.py | 0 {diggersdigest => app}/records/models.py | 0 {diggersdigest => app}/records/models_db.py | 0 .../records}/static/css/dig2.css | 0 .../records}/static/img/diggersdigest_400.png | Bin .../records}/static/img/dotted_background.png | Bin .../records}/static/img/favicon.ico | Bin .../records/templatetags/__init__.py | 0 .../records/templatetags/records_tags.py | 0 {diggersdigest => app}/records/tests.py | 0 {diggersdigest => app}/records/views.py | 0 .../accounts/account_profile_update.html | 0 {diggersdigest => app}/templates/base.html | 0 .../templates/blog/blog_post_detail.html | 0 .../templates/blog/blog_post_list.html | 0 .../templates/blog/includes/filter_panel.html | 0 .../templates/email/base.html | 0 .../templates/email/base.txt | 0 .../templates/email/order_receipt.html | 0 .../templates/email/order_receipt.txt | 0 .../templates/email/receipt.html | 0 .../templates/email/receipt_rtl.html | 0 .../templates/errors/404.html | 0 .../templates/errors/500.html | 0 .../templates/includes/editable_form.html | 0 .../templates/includes/editable_loader.html | 0 .../templates/includes/editable_toolbar.html | 0 .../templates/includes/footer_scripts.html | 0 .../templates/includes/form_errors.html | 0 .../templates/includes/form_fields.html | 0 .../templates/includes/language_selector.html | 0 .../templates/includes/pagination.html | 0 .../templates/includes/search_form.html | 0 .../templates/includes/user_panel.html | 0 .../templates/includes/user_panel_header.html | 0 {diggersdigest => app}/templates/index.html | 0 .../templates/pages/category.html | 0 .../templates/pages/index.html | 0 .../templates/pages/menus/admin.html | 0 .../templates/pages/menus/breadcrumb.html | 0 .../templates/pages/menus/dropdown.html | 0 .../templates/pages/menus/footer.html | 0 .../templates/pages/menus/footer_tree.html | 0 .../templates/pages/menus/mobile.html | 0 .../templates/pages/menus/primary.html | 0 .../templates/pages/menus/tree.html | 0 .../templates/pages/page.html | 0 .../templates/pages/richtextpage.html | 0 .../templates/search_results.html | 0 .../templates/shop/base.html | 0 .../templates/shop/billing_shipping.html | 0 .../templates/shop/cart.html | 0 .../templates/shop/checkout.html | 0 .../templates/shop/complete.html | 0 .../templates/shop/confirmation.html | 0 .../shop/includes/order_details.html | 0 .../shop/includes/order_details_rtl.html | 0 .../templates/shop/includes/order_totals.html | 0 .../templates/shop/includes/order_totals.txt | 0 .../shop/includes/payment_fields.html | 0 .../templates/shop/includes/price.html | 0 .../templates/shop/includes/user_panel.html | 0 .../shop/includes/user_panel_header.html | 0 .../templates/shop/order_history.html | 0 .../templates/shop/order_invoice.html | 0 .../templates/shop/order_invoice_pdf.html | 0 .../templates/shop/payment.html | 0 .../templates/shop/product.html | 0 .../templates/shop/wishlist.html | 0 {diggersdigest/diggersdigest => app}/wsgi.py | 0 diggersdigest/deploy/start_app.sh | 27 - diggersdigest/fabfile.py | 685 ------------------ diggersdigest/records_shop/__init__.py | 0 diggersdigest/records_shop/admin.py | 4 - .../records_shop/migrations/0001_initial.py | 26 - .../records_shop/migrations/__init__.py | 0 diggersdigest/records_shop/models.py | 12 - diggersdigest/records_shop/tests.py | 3 - diggersdigest/records_shop/views.py | 3 - docker-compose.yml | 34 +- requirements.txt | 2 + 120 files changed, 109 insertions(+), 782 deletions(-) rename {diggersdigest => app}/__init__.py (100%) rename {diggersdigest => app}/deploy/crontab.template (100%) rename {diggersdigest => app}/deploy/gunicorn.conf.py.template (100%) rename {diggersdigest => app}/deploy/local_settings.py.template (100%) create mode 100644 app/deploy/nginx-app.conf rename {diggersdigest => app}/deploy/nginx.conf.template (100%) create mode 100644 app/deploy/start_app.sh rename {diggersdigest => app}/deploy/supervisor.conf.template (100%) create mode 100644 app/deploy/wait.sh rename {diggersdigest => app}/diggersdigest/__init__.py (100%) rename {diggersdigest => app}/diggersdigest/local_settings.py (100%) rename {diggersdigest => app}/diggersdigest/migrations/__init__.py (100%) rename {diggersdigest => app}/diggersdigest/migrations/blog/0001_initial.py (100%) rename {diggersdigest => app}/diggersdigest/migrations/blog/0002_auto_20150527_1555.py (100%) rename {diggersdigest => app}/diggersdigest/migrations/blog/0003_blogpost_related_products.py (100%) rename {diggersdigest => app}/diggersdigest/migrations/blog/__init__.py (100%) rename {diggersdigest => app}/diggersdigest/migrations/shop/0001_initial.py (100%) rename {diggersdigest => app}/diggersdigest/migrations/shop/0002_order_callback_uuid.py (100%) rename {diggersdigest => app}/diggersdigest/migrations/shop/0003_auto_20150906_1911.py (100%) rename {diggersdigest => app}/diggersdigest/migrations/shop/__init__.py (100%) rename {diggersdigest => app}/diggersdigest/settings.py (98%) rename {diggersdigest => app}/diggersdigest/urls.py (100%) rename {diggersdigest => app}/manage.py (100%) rename {diggersdigest => app}/records/__init__.py (100%) rename {diggersdigest => app}/records/admin.py (100%) rename {diggersdigest => app}/records/management/__init__.py (100%) rename {diggersdigest => app}/records/management/commands/__init__.py (100%) rename {diggersdigest => app}/records/management/commands/populate_db.py (100%) rename {diggersdigest => app}/records/migrations/0001_initial.py (100%) rename {diggersdigest => app}/records/migrations/0002_auto_20150831_1518.py (100%) rename {diggersdigest => app}/records/migrations/0003_record_date_text.py (100%) rename {diggersdigest => app}/records/migrations/0004_auto_20150904_0733.py (100%) rename {diggersdigest => app}/records/migrations/0005_auto_20150904_1309.py (100%) rename {diggersdigest => app}/records/migrations/0006_auto_20150907_0835.py (100%) rename {diggersdigest => app}/records/migrations/0007_record_image.py (100%) rename {diggersdigest => app}/records/migrations/0008_auto_20150909_0818.py (100%) rename {diggersdigest => app}/records/migrations/0009_remove_record_image.py (100%) rename {diggersdigest => app}/records/migrations/0010_auto_20150909_1400.py (100%) rename {diggersdigest => app}/records/migrations/__init__.py (100%) rename {diggersdigest => app}/records/models.py (100%) rename {diggersdigest => app}/records/models_db.py (100%) rename {diggersdigest => app/records}/static/css/dig2.css (100%) rename {diggersdigest => app/records}/static/img/diggersdigest_400.png (100%) rename {diggersdigest => app/records}/static/img/dotted_background.png (100%) rename {diggersdigest => app/records}/static/img/favicon.ico (100%) rename {diggersdigest => app}/records/templatetags/__init__.py (100%) rename {diggersdigest => app}/records/templatetags/records_tags.py (100%) rename {diggersdigest => app}/records/tests.py (100%) rename {diggersdigest => app}/records/views.py (100%) rename {diggersdigest => app}/templates/accounts/account_profile_update.html (100%) rename {diggersdigest => app}/templates/base.html (100%) rename {diggersdigest => app}/templates/blog/blog_post_detail.html (100%) rename {diggersdigest => app}/templates/blog/blog_post_list.html (100%) rename {diggersdigest => app}/templates/blog/includes/filter_panel.html (100%) rename {diggersdigest => app}/templates/email/base.html (100%) rename {diggersdigest => app}/templates/email/base.txt (100%) rename {diggersdigest => app}/templates/email/order_receipt.html (100%) rename {diggersdigest => app}/templates/email/order_receipt.txt (100%) rename {diggersdigest => app}/templates/email/receipt.html (100%) rename {diggersdigest => app}/templates/email/receipt_rtl.html (100%) rename {diggersdigest => app}/templates/errors/404.html (100%) rename {diggersdigest => app}/templates/errors/500.html (100%) rename {diggersdigest => app}/templates/includes/editable_form.html (100%) rename {diggersdigest => app}/templates/includes/editable_loader.html (100%) rename {diggersdigest => app}/templates/includes/editable_toolbar.html (100%) rename {diggersdigest => app}/templates/includes/footer_scripts.html (100%) rename {diggersdigest => app}/templates/includes/form_errors.html (100%) rename {diggersdigest => app}/templates/includes/form_fields.html (100%) rename {diggersdigest => app}/templates/includes/language_selector.html (100%) rename {diggersdigest => app}/templates/includes/pagination.html (100%) rename {diggersdigest => app}/templates/includes/search_form.html (100%) rename {diggersdigest => app}/templates/includes/user_panel.html (100%) rename {diggersdigest => app}/templates/includes/user_panel_header.html (100%) rename {diggersdigest => app}/templates/index.html (100%) rename {diggersdigest => app}/templates/pages/category.html (100%) rename {diggersdigest => app}/templates/pages/index.html (100%) rename {diggersdigest => app}/templates/pages/menus/admin.html (100%) rename {diggersdigest => app}/templates/pages/menus/breadcrumb.html (100%) rename {diggersdigest => app}/templates/pages/menus/dropdown.html (100%) rename {diggersdigest => app}/templates/pages/menus/footer.html (100%) rename {diggersdigest => app}/templates/pages/menus/footer_tree.html (100%) rename {diggersdigest => app}/templates/pages/menus/mobile.html (100%) rename {diggersdigest => app}/templates/pages/menus/primary.html (100%) rename {diggersdigest => app}/templates/pages/menus/tree.html (100%) rename {diggersdigest => app}/templates/pages/page.html (100%) rename {diggersdigest => app}/templates/pages/richtextpage.html (100%) rename {diggersdigest => app}/templates/search_results.html (100%) rename {diggersdigest => app}/templates/shop/base.html (100%) rename {diggersdigest => app}/templates/shop/billing_shipping.html (100%) rename {diggersdigest => app}/templates/shop/cart.html (100%) rename {diggersdigest => app}/templates/shop/checkout.html (100%) rename {diggersdigest => app}/templates/shop/complete.html (100%) rename {diggersdigest => app}/templates/shop/confirmation.html (100%) rename {diggersdigest => app}/templates/shop/includes/order_details.html (100%) rename {diggersdigest => app}/templates/shop/includes/order_details_rtl.html (100%) rename {diggersdigest => app}/templates/shop/includes/order_totals.html (100%) rename {diggersdigest => app}/templates/shop/includes/order_totals.txt (100%) rename {diggersdigest => app}/templates/shop/includes/payment_fields.html (100%) rename {diggersdigest => app}/templates/shop/includes/price.html (100%) rename {diggersdigest => app}/templates/shop/includes/user_panel.html (100%) rename {diggersdigest => app}/templates/shop/includes/user_panel_header.html (100%) rename {diggersdigest => app}/templates/shop/order_history.html (100%) rename {diggersdigest => app}/templates/shop/order_invoice.html (100%) rename {diggersdigest => app}/templates/shop/order_invoice_pdf.html (100%) rename {diggersdigest => app}/templates/shop/payment.html (100%) rename {diggersdigest => app}/templates/shop/product.html (100%) rename {diggersdigest => app}/templates/shop/wishlist.html (100%) rename {diggersdigest/diggersdigest => app}/wsgi.py (100%) delete mode 100644 diggersdigest/deploy/start_app.sh delete mode 100644 diggersdigest/fabfile.py delete mode 100644 diggersdigest/records_shop/__init__.py delete mode 100644 diggersdigest/records_shop/admin.py delete mode 100644 diggersdigest/records_shop/migrations/0001_initial.py delete mode 100644 diggersdigest/records_shop/migrations/__init__.py delete mode 100644 diggersdigest/records_shop/models.py delete mode 100644 diggersdigest/records_shop/tests.py delete mode 100644 diggersdigest/records_shop/views.py diff --git a/Dockerfile b/Dockerfile index 482e1de..0bb171a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,15 +11,14 @@ ENV LANG fr_FR.UTF-8 ENV LANGUAGE fr_FR:fr ENV LC_ALL fr_FR.UTF-8 -RUN mkdir /code +RUN mkdir /opt/app RUN mkdir /opt/src +WORKDIR /opt/app -WORKDIR /code - -ADD requirements.txt /code/ +ADD requirements.txt /opt/app/ RUN pip install -r requirements.txt -ADD requirements-dev.txt /code/ +ADD requirements-dev.txt /opt/app/ RUN pip install -r requirements-dev.txt --src /opt/src -ADD . /code/ +ADD app /opt/app/ diff --git a/diggersdigest/__init__.py b/app/__init__.py similarity index 100% rename from diggersdigest/__init__.py rename to app/__init__.py diff --git a/diggersdigest/deploy/crontab.template b/app/deploy/crontab.template similarity index 100% rename from diggersdigest/deploy/crontab.template rename to app/deploy/crontab.template diff --git a/diggersdigest/deploy/gunicorn.conf.py.template b/app/deploy/gunicorn.conf.py.template similarity index 100% rename from diggersdigest/deploy/gunicorn.conf.py.template rename to app/deploy/gunicorn.conf.py.template diff --git a/diggersdigest/deploy/local_settings.py.template b/app/deploy/local_settings.py.template similarity index 100% rename from diggersdigest/deploy/local_settings.py.template rename to app/deploy/local_settings.py.template diff --git a/app/deploy/nginx-app.conf b/app/deploy/nginx-app.conf new file mode 100644 index 0000000..df8bc0a --- /dev/null +++ b/app/deploy/nginx-app.conf @@ -0,0 +1,29 @@ +server_tokens off; + +server { + listen 80; + server_name nginx; + charset utf-8; + + access_log /var/log/nginx/app-access.log; + error_log /var/log/nginx/app-error.log; + + # max upload size + client_max_body_size 4096M; # adjust to taste + + # Django media + location /media { + alias /opt/media; # your Django project's media files - amend as required + autoindex on; + } + # Django static + location /static { + alias /opt/static; # your Django project's static files - amend as required + autoindex on; + } + + location / { + uwsgi_pass app:8000; + include /etc/nginx/uwsgi_params; + } +} diff --git a/diggersdigest/deploy/nginx.conf.template b/app/deploy/nginx.conf.template similarity index 100% rename from diggersdigest/deploy/nginx.conf.template rename to app/deploy/nginx.conf.template diff --git a/app/deploy/start_app.sh b/app/deploy/start_app.sh new file mode 100644 index 0000000..76303bd --- /dev/null +++ b/app/deploy/start_app.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +# paths +root='/opt' +sandbox=$root'/app/app' +manage=$sandbox'/manage.py' +wsgi=$sandbox'/wsgi.py' +static=$root'/static/' +media=$root'/media/' + +# waiting for other services +sh $sandbox/deploy/wait.sh + +# django init +python $manage migrate --noinput +python $manage collectstatic --noinput + +# static files auto update +watchmedo shell-command --patterns="*.js;*.css" --recursive \ + --command='python '$manage' collectstatic --noinput' $static & + +# app start +uwsgi --socket :8000 --wsgi-file $wsgi --chdir $sandbox --master --processes 4 --threads 2 --py-autoreload 3 + +#python $manage runserver 0.0.0.0:8000 diff --git a/diggersdigest/deploy/supervisor.conf.template b/app/deploy/supervisor.conf.template similarity index 100% rename from diggersdigest/deploy/supervisor.conf.template rename to app/deploy/supervisor.conf.template diff --git a/app/deploy/wait.sh b/app/deploy/wait.sh new file mode 100644 index 0000000..a3341e0 --- /dev/null +++ b/app/deploy/wait.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +apt-get install -y --force-yes netcat + +set -e + +host=$(env | grep _TCP_ADDR | cut -d = -f 2) +port=$(env | grep _TCP_PORT | cut -d = -f 2) + +echo -n "waiting for TCP connection to $host:$port..." + +while ! nc -w 1 $host $port 2>/dev/null +do + echo -n . + sleep 1 +done + +echo 'ok' \ No newline at end of file diff --git a/diggersdigest/diggersdigest/__init__.py b/app/diggersdigest/__init__.py similarity index 100% rename from diggersdigest/diggersdigest/__init__.py rename to app/diggersdigest/__init__.py diff --git a/diggersdigest/diggersdigest/local_settings.py b/app/diggersdigest/local_settings.py similarity index 100% rename from diggersdigest/diggersdigest/local_settings.py rename to app/diggersdigest/local_settings.py diff --git a/diggersdigest/diggersdigest/migrations/__init__.py b/app/diggersdigest/migrations/__init__.py similarity index 100% rename from diggersdigest/diggersdigest/migrations/__init__.py rename to app/diggersdigest/migrations/__init__.py diff --git a/diggersdigest/diggersdigest/migrations/blog/0001_initial.py b/app/diggersdigest/migrations/blog/0001_initial.py similarity index 100% rename from diggersdigest/diggersdigest/migrations/blog/0001_initial.py rename to app/diggersdigest/migrations/blog/0001_initial.py diff --git a/diggersdigest/diggersdigest/migrations/blog/0002_auto_20150527_1555.py b/app/diggersdigest/migrations/blog/0002_auto_20150527_1555.py similarity index 100% rename from diggersdigest/diggersdigest/migrations/blog/0002_auto_20150527_1555.py rename to app/diggersdigest/migrations/blog/0002_auto_20150527_1555.py diff --git a/diggersdigest/diggersdigest/migrations/blog/0003_blogpost_related_products.py b/app/diggersdigest/migrations/blog/0003_blogpost_related_products.py similarity index 100% rename from diggersdigest/diggersdigest/migrations/blog/0003_blogpost_related_products.py rename to app/diggersdigest/migrations/blog/0003_blogpost_related_products.py diff --git a/diggersdigest/diggersdigest/migrations/blog/__init__.py b/app/diggersdigest/migrations/blog/__init__.py similarity index 100% rename from diggersdigest/diggersdigest/migrations/blog/__init__.py rename to app/diggersdigest/migrations/blog/__init__.py diff --git a/diggersdigest/diggersdigest/migrations/shop/0001_initial.py b/app/diggersdigest/migrations/shop/0001_initial.py similarity index 100% rename from diggersdigest/diggersdigest/migrations/shop/0001_initial.py rename to app/diggersdigest/migrations/shop/0001_initial.py diff --git a/diggersdigest/diggersdigest/migrations/shop/0002_order_callback_uuid.py b/app/diggersdigest/migrations/shop/0002_order_callback_uuid.py similarity index 100% rename from diggersdigest/diggersdigest/migrations/shop/0002_order_callback_uuid.py rename to app/diggersdigest/migrations/shop/0002_order_callback_uuid.py diff --git a/diggersdigest/diggersdigest/migrations/shop/0003_auto_20150906_1911.py b/app/diggersdigest/migrations/shop/0003_auto_20150906_1911.py similarity index 100% rename from diggersdigest/diggersdigest/migrations/shop/0003_auto_20150906_1911.py rename to app/diggersdigest/migrations/shop/0003_auto_20150906_1911.py diff --git a/diggersdigest/diggersdigest/migrations/shop/__init__.py b/app/diggersdigest/migrations/shop/__init__.py similarity index 100% rename from diggersdigest/diggersdigest/migrations/shop/__init__.py rename to app/diggersdigest/migrations/shop/__init__.py diff --git a/diggersdigest/diggersdigest/settings.py b/app/diggersdigest/settings.py similarity index 98% rename from diggersdigest/diggersdigest/settings.py rename to app/diggersdigest/settings.py index 7bbd021..ffbe234 100644 --- a/diggersdigest/diggersdigest/settings.py +++ b/app/diggersdigest/settings.py @@ -222,11 +222,9 @@ PAYPAL_TEST = True # MAIN DJANGO SETTINGS # ######################## -SITE_DOMAIN = 'localhost' - # Hosts/domain names that are valid for this site; required if DEBUG is False # See https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['*'] # Local time zone for this installation. Choices can be found here: # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name @@ -315,16 +313,18 @@ STATIC_URL = "/static/" # Don't put anything in this directory yourself; store your static files # in apps' "static/" subdirectories and in STATICFILES_DIRS. # Example: "/home/media/media.lawrence.com/static/" -STATIC_ROOT = os.path.join(PROJECT_ROOT, STATIC_URL.strip("/")) +# STATIC_ROOT = os.path.join(PROJECT_ROOT, STATIC_URL.strip("/")) +STATIC_ROOT = '/opt/static/' # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash. # Examples: "http://media.lawrence.com/media/", "http://example.com/media/" -MEDIA_URL = STATIC_URL + "media/" +MEDIA_URL = "/media/" # Absolute filesystem path to the directory that will hold user-uploaded files. # Example: "/home/media/media.lawrence.com/media/" -MEDIA_ROOT = os.path.join(PROJECT_ROOT, *MEDIA_URL.strip("/").split("/")) +# MEDIA_ROOT = os.path.join(PROJECT_ROOT, *MEDIA_URL.strip("/").split("/")) +MEDIA_ROOT = '/opt/media/' # Package/module name to import the root urlpatterns from for the project. ROOT_URLCONF = "%s.urls" % PROJECT_APP diff --git a/diggersdigest/diggersdigest/urls.py b/app/diggersdigest/urls.py similarity index 100% rename from diggersdigest/diggersdigest/urls.py rename to app/diggersdigest/urls.py diff --git a/diggersdigest/manage.py b/app/manage.py similarity index 100% rename from diggersdigest/manage.py rename to app/manage.py diff --git a/diggersdigest/records/__init__.py b/app/records/__init__.py similarity index 100% rename from diggersdigest/records/__init__.py rename to app/records/__init__.py diff --git a/diggersdigest/records/admin.py b/app/records/admin.py similarity index 100% rename from diggersdigest/records/admin.py rename to app/records/admin.py diff --git a/diggersdigest/records/management/__init__.py b/app/records/management/__init__.py similarity index 100% rename from diggersdigest/records/management/__init__.py rename to app/records/management/__init__.py diff --git a/diggersdigest/records/management/commands/__init__.py b/app/records/management/commands/__init__.py similarity index 100% rename from diggersdigest/records/management/commands/__init__.py rename to app/records/management/commands/__init__.py diff --git a/diggersdigest/records/management/commands/populate_db.py b/app/records/management/commands/populate_db.py similarity index 100% rename from diggersdigest/records/management/commands/populate_db.py rename to app/records/management/commands/populate_db.py diff --git a/diggersdigest/records/migrations/0001_initial.py b/app/records/migrations/0001_initial.py similarity index 100% rename from diggersdigest/records/migrations/0001_initial.py rename to app/records/migrations/0001_initial.py diff --git a/diggersdigest/records/migrations/0002_auto_20150831_1518.py b/app/records/migrations/0002_auto_20150831_1518.py similarity index 100% rename from diggersdigest/records/migrations/0002_auto_20150831_1518.py rename to app/records/migrations/0002_auto_20150831_1518.py diff --git a/diggersdigest/records/migrations/0003_record_date_text.py b/app/records/migrations/0003_record_date_text.py similarity index 100% rename from diggersdigest/records/migrations/0003_record_date_text.py rename to app/records/migrations/0003_record_date_text.py diff --git a/diggersdigest/records/migrations/0004_auto_20150904_0733.py b/app/records/migrations/0004_auto_20150904_0733.py similarity index 100% rename from diggersdigest/records/migrations/0004_auto_20150904_0733.py rename to app/records/migrations/0004_auto_20150904_0733.py diff --git a/diggersdigest/records/migrations/0005_auto_20150904_1309.py b/app/records/migrations/0005_auto_20150904_1309.py similarity index 100% rename from diggersdigest/records/migrations/0005_auto_20150904_1309.py rename to app/records/migrations/0005_auto_20150904_1309.py diff --git a/diggersdigest/records/migrations/0006_auto_20150907_0835.py b/app/records/migrations/0006_auto_20150907_0835.py similarity index 100% rename from diggersdigest/records/migrations/0006_auto_20150907_0835.py rename to app/records/migrations/0006_auto_20150907_0835.py diff --git a/diggersdigest/records/migrations/0007_record_image.py b/app/records/migrations/0007_record_image.py similarity index 100% rename from diggersdigest/records/migrations/0007_record_image.py rename to app/records/migrations/0007_record_image.py diff --git a/diggersdigest/records/migrations/0008_auto_20150909_0818.py b/app/records/migrations/0008_auto_20150909_0818.py similarity index 100% rename from diggersdigest/records/migrations/0008_auto_20150909_0818.py rename to app/records/migrations/0008_auto_20150909_0818.py diff --git a/diggersdigest/records/migrations/0009_remove_record_image.py b/app/records/migrations/0009_remove_record_image.py similarity index 100% rename from diggersdigest/records/migrations/0009_remove_record_image.py rename to app/records/migrations/0009_remove_record_image.py diff --git a/diggersdigest/records/migrations/0010_auto_20150909_1400.py b/app/records/migrations/0010_auto_20150909_1400.py similarity index 100% rename from diggersdigest/records/migrations/0010_auto_20150909_1400.py rename to app/records/migrations/0010_auto_20150909_1400.py diff --git a/diggersdigest/records/migrations/__init__.py b/app/records/migrations/__init__.py similarity index 100% rename from diggersdigest/records/migrations/__init__.py rename to app/records/migrations/__init__.py diff --git a/diggersdigest/records/models.py b/app/records/models.py similarity index 100% rename from diggersdigest/records/models.py rename to app/records/models.py diff --git a/diggersdigest/records/models_db.py b/app/records/models_db.py similarity index 100% rename from diggersdigest/records/models_db.py rename to app/records/models_db.py diff --git a/diggersdigest/static/css/dig2.css b/app/records/static/css/dig2.css similarity index 100% rename from diggersdigest/static/css/dig2.css rename to app/records/static/css/dig2.css diff --git a/diggersdigest/static/img/diggersdigest_400.png b/app/records/static/img/diggersdigest_400.png similarity index 100% rename from diggersdigest/static/img/diggersdigest_400.png rename to app/records/static/img/diggersdigest_400.png diff --git a/diggersdigest/static/img/dotted_background.png b/app/records/static/img/dotted_background.png similarity index 100% rename from diggersdigest/static/img/dotted_background.png rename to app/records/static/img/dotted_background.png diff --git a/diggersdigest/static/img/favicon.ico b/app/records/static/img/favicon.ico similarity index 100% rename from diggersdigest/static/img/favicon.ico rename to app/records/static/img/favicon.ico diff --git a/diggersdigest/records/templatetags/__init__.py b/app/records/templatetags/__init__.py similarity index 100% rename from diggersdigest/records/templatetags/__init__.py rename to app/records/templatetags/__init__.py diff --git a/diggersdigest/records/templatetags/records_tags.py b/app/records/templatetags/records_tags.py similarity index 100% rename from diggersdigest/records/templatetags/records_tags.py rename to app/records/templatetags/records_tags.py diff --git a/diggersdigest/records/tests.py b/app/records/tests.py similarity index 100% rename from diggersdigest/records/tests.py rename to app/records/tests.py diff --git a/diggersdigest/records/views.py b/app/records/views.py similarity index 100% rename from diggersdigest/records/views.py rename to app/records/views.py diff --git a/diggersdigest/templates/accounts/account_profile_update.html b/app/templates/accounts/account_profile_update.html similarity index 100% rename from diggersdigest/templates/accounts/account_profile_update.html rename to app/templates/accounts/account_profile_update.html diff --git a/diggersdigest/templates/base.html b/app/templates/base.html similarity index 100% rename from diggersdigest/templates/base.html rename to app/templates/base.html diff --git a/diggersdigest/templates/blog/blog_post_detail.html b/app/templates/blog/blog_post_detail.html similarity index 100% rename from diggersdigest/templates/blog/blog_post_detail.html rename to app/templates/blog/blog_post_detail.html diff --git a/diggersdigest/templates/blog/blog_post_list.html b/app/templates/blog/blog_post_list.html similarity index 100% rename from diggersdigest/templates/blog/blog_post_list.html rename to app/templates/blog/blog_post_list.html diff --git a/diggersdigest/templates/blog/includes/filter_panel.html b/app/templates/blog/includes/filter_panel.html similarity index 100% rename from diggersdigest/templates/blog/includes/filter_panel.html rename to app/templates/blog/includes/filter_panel.html diff --git a/diggersdigest/templates/email/base.html b/app/templates/email/base.html similarity index 100% rename from diggersdigest/templates/email/base.html rename to app/templates/email/base.html diff --git a/diggersdigest/templates/email/base.txt b/app/templates/email/base.txt similarity index 100% rename from diggersdigest/templates/email/base.txt rename to app/templates/email/base.txt diff --git a/diggersdigest/templates/email/order_receipt.html b/app/templates/email/order_receipt.html similarity index 100% rename from diggersdigest/templates/email/order_receipt.html rename to app/templates/email/order_receipt.html diff --git a/diggersdigest/templates/email/order_receipt.txt b/app/templates/email/order_receipt.txt similarity index 100% rename from diggersdigest/templates/email/order_receipt.txt rename to app/templates/email/order_receipt.txt diff --git a/diggersdigest/templates/email/receipt.html b/app/templates/email/receipt.html similarity index 100% rename from diggersdigest/templates/email/receipt.html rename to app/templates/email/receipt.html diff --git a/diggersdigest/templates/email/receipt_rtl.html b/app/templates/email/receipt_rtl.html similarity index 100% rename from diggersdigest/templates/email/receipt_rtl.html rename to app/templates/email/receipt_rtl.html diff --git a/diggersdigest/templates/errors/404.html b/app/templates/errors/404.html similarity index 100% rename from diggersdigest/templates/errors/404.html rename to app/templates/errors/404.html diff --git a/diggersdigest/templates/errors/500.html b/app/templates/errors/500.html similarity index 100% rename from diggersdigest/templates/errors/500.html rename to app/templates/errors/500.html diff --git a/diggersdigest/templates/includes/editable_form.html b/app/templates/includes/editable_form.html similarity index 100% rename from diggersdigest/templates/includes/editable_form.html rename to app/templates/includes/editable_form.html diff --git a/diggersdigest/templates/includes/editable_loader.html b/app/templates/includes/editable_loader.html similarity index 100% rename from diggersdigest/templates/includes/editable_loader.html rename to app/templates/includes/editable_loader.html diff --git a/diggersdigest/templates/includes/editable_toolbar.html b/app/templates/includes/editable_toolbar.html similarity index 100% rename from diggersdigest/templates/includes/editable_toolbar.html rename to app/templates/includes/editable_toolbar.html diff --git a/diggersdigest/templates/includes/footer_scripts.html b/app/templates/includes/footer_scripts.html similarity index 100% rename from diggersdigest/templates/includes/footer_scripts.html rename to app/templates/includes/footer_scripts.html diff --git a/diggersdigest/templates/includes/form_errors.html b/app/templates/includes/form_errors.html similarity index 100% rename from diggersdigest/templates/includes/form_errors.html rename to app/templates/includes/form_errors.html diff --git a/diggersdigest/templates/includes/form_fields.html b/app/templates/includes/form_fields.html similarity index 100% rename from diggersdigest/templates/includes/form_fields.html rename to app/templates/includes/form_fields.html diff --git a/diggersdigest/templates/includes/language_selector.html b/app/templates/includes/language_selector.html similarity index 100% rename from diggersdigest/templates/includes/language_selector.html rename to app/templates/includes/language_selector.html diff --git a/diggersdigest/templates/includes/pagination.html b/app/templates/includes/pagination.html similarity index 100% rename from diggersdigest/templates/includes/pagination.html rename to app/templates/includes/pagination.html diff --git a/diggersdigest/templates/includes/search_form.html b/app/templates/includes/search_form.html similarity index 100% rename from diggersdigest/templates/includes/search_form.html rename to app/templates/includes/search_form.html diff --git a/diggersdigest/templates/includes/user_panel.html b/app/templates/includes/user_panel.html similarity index 100% rename from diggersdigest/templates/includes/user_panel.html rename to app/templates/includes/user_panel.html diff --git a/diggersdigest/templates/includes/user_panel_header.html b/app/templates/includes/user_panel_header.html similarity index 100% rename from diggersdigest/templates/includes/user_panel_header.html rename to app/templates/includes/user_panel_header.html diff --git a/diggersdigest/templates/index.html b/app/templates/index.html similarity index 100% rename from diggersdigest/templates/index.html rename to app/templates/index.html diff --git a/diggersdigest/templates/pages/category.html b/app/templates/pages/category.html similarity index 100% rename from diggersdigest/templates/pages/category.html rename to app/templates/pages/category.html diff --git a/diggersdigest/templates/pages/index.html b/app/templates/pages/index.html similarity index 100% rename from diggersdigest/templates/pages/index.html rename to app/templates/pages/index.html diff --git a/diggersdigest/templates/pages/menus/admin.html b/app/templates/pages/menus/admin.html similarity index 100% rename from diggersdigest/templates/pages/menus/admin.html rename to app/templates/pages/menus/admin.html diff --git a/diggersdigest/templates/pages/menus/breadcrumb.html b/app/templates/pages/menus/breadcrumb.html similarity index 100% rename from diggersdigest/templates/pages/menus/breadcrumb.html rename to app/templates/pages/menus/breadcrumb.html diff --git a/diggersdigest/templates/pages/menus/dropdown.html b/app/templates/pages/menus/dropdown.html similarity index 100% rename from diggersdigest/templates/pages/menus/dropdown.html rename to app/templates/pages/menus/dropdown.html diff --git a/diggersdigest/templates/pages/menus/footer.html b/app/templates/pages/menus/footer.html similarity index 100% rename from diggersdigest/templates/pages/menus/footer.html rename to app/templates/pages/menus/footer.html diff --git a/diggersdigest/templates/pages/menus/footer_tree.html b/app/templates/pages/menus/footer_tree.html similarity index 100% rename from diggersdigest/templates/pages/menus/footer_tree.html rename to app/templates/pages/menus/footer_tree.html diff --git a/diggersdigest/templates/pages/menus/mobile.html b/app/templates/pages/menus/mobile.html similarity index 100% rename from diggersdigest/templates/pages/menus/mobile.html rename to app/templates/pages/menus/mobile.html diff --git a/diggersdigest/templates/pages/menus/primary.html b/app/templates/pages/menus/primary.html similarity index 100% rename from diggersdigest/templates/pages/menus/primary.html rename to app/templates/pages/menus/primary.html diff --git a/diggersdigest/templates/pages/menus/tree.html b/app/templates/pages/menus/tree.html similarity index 100% rename from diggersdigest/templates/pages/menus/tree.html rename to app/templates/pages/menus/tree.html diff --git a/diggersdigest/templates/pages/page.html b/app/templates/pages/page.html similarity index 100% rename from diggersdigest/templates/pages/page.html rename to app/templates/pages/page.html diff --git a/diggersdigest/templates/pages/richtextpage.html b/app/templates/pages/richtextpage.html similarity index 100% rename from diggersdigest/templates/pages/richtextpage.html rename to app/templates/pages/richtextpage.html diff --git a/diggersdigest/templates/search_results.html b/app/templates/search_results.html similarity index 100% rename from diggersdigest/templates/search_results.html rename to app/templates/search_results.html diff --git a/diggersdigest/templates/shop/base.html b/app/templates/shop/base.html similarity index 100% rename from diggersdigest/templates/shop/base.html rename to app/templates/shop/base.html diff --git a/diggersdigest/templates/shop/billing_shipping.html b/app/templates/shop/billing_shipping.html similarity index 100% rename from diggersdigest/templates/shop/billing_shipping.html rename to app/templates/shop/billing_shipping.html diff --git a/diggersdigest/templates/shop/cart.html b/app/templates/shop/cart.html similarity index 100% rename from diggersdigest/templates/shop/cart.html rename to app/templates/shop/cart.html diff --git a/diggersdigest/templates/shop/checkout.html b/app/templates/shop/checkout.html similarity index 100% rename from diggersdigest/templates/shop/checkout.html rename to app/templates/shop/checkout.html diff --git a/diggersdigest/templates/shop/complete.html b/app/templates/shop/complete.html similarity index 100% rename from diggersdigest/templates/shop/complete.html rename to app/templates/shop/complete.html diff --git a/diggersdigest/templates/shop/confirmation.html b/app/templates/shop/confirmation.html similarity index 100% rename from diggersdigest/templates/shop/confirmation.html rename to app/templates/shop/confirmation.html diff --git a/diggersdigest/templates/shop/includes/order_details.html b/app/templates/shop/includes/order_details.html similarity index 100% rename from diggersdigest/templates/shop/includes/order_details.html rename to app/templates/shop/includes/order_details.html diff --git a/diggersdigest/templates/shop/includes/order_details_rtl.html b/app/templates/shop/includes/order_details_rtl.html similarity index 100% rename from diggersdigest/templates/shop/includes/order_details_rtl.html rename to app/templates/shop/includes/order_details_rtl.html diff --git a/diggersdigest/templates/shop/includes/order_totals.html b/app/templates/shop/includes/order_totals.html similarity index 100% rename from diggersdigest/templates/shop/includes/order_totals.html rename to app/templates/shop/includes/order_totals.html diff --git a/diggersdigest/templates/shop/includes/order_totals.txt b/app/templates/shop/includes/order_totals.txt similarity index 100% rename from diggersdigest/templates/shop/includes/order_totals.txt rename to app/templates/shop/includes/order_totals.txt diff --git a/diggersdigest/templates/shop/includes/payment_fields.html b/app/templates/shop/includes/payment_fields.html similarity index 100% rename from diggersdigest/templates/shop/includes/payment_fields.html rename to app/templates/shop/includes/payment_fields.html diff --git a/diggersdigest/templates/shop/includes/price.html b/app/templates/shop/includes/price.html similarity index 100% rename from diggersdigest/templates/shop/includes/price.html rename to app/templates/shop/includes/price.html diff --git a/diggersdigest/templates/shop/includes/user_panel.html b/app/templates/shop/includes/user_panel.html similarity index 100% rename from diggersdigest/templates/shop/includes/user_panel.html rename to app/templates/shop/includes/user_panel.html diff --git a/diggersdigest/templates/shop/includes/user_panel_header.html b/app/templates/shop/includes/user_panel_header.html similarity index 100% rename from diggersdigest/templates/shop/includes/user_panel_header.html rename to app/templates/shop/includes/user_panel_header.html diff --git a/diggersdigest/templates/shop/order_history.html b/app/templates/shop/order_history.html similarity index 100% rename from diggersdigest/templates/shop/order_history.html rename to app/templates/shop/order_history.html diff --git a/diggersdigest/templates/shop/order_invoice.html b/app/templates/shop/order_invoice.html similarity index 100% rename from diggersdigest/templates/shop/order_invoice.html rename to app/templates/shop/order_invoice.html diff --git a/diggersdigest/templates/shop/order_invoice_pdf.html b/app/templates/shop/order_invoice_pdf.html similarity index 100% rename from diggersdigest/templates/shop/order_invoice_pdf.html rename to app/templates/shop/order_invoice_pdf.html diff --git a/diggersdigest/templates/shop/payment.html b/app/templates/shop/payment.html similarity index 100% rename from diggersdigest/templates/shop/payment.html rename to app/templates/shop/payment.html diff --git a/diggersdigest/templates/shop/product.html b/app/templates/shop/product.html similarity index 100% rename from diggersdigest/templates/shop/product.html rename to app/templates/shop/product.html diff --git a/diggersdigest/templates/shop/wishlist.html b/app/templates/shop/wishlist.html similarity index 100% rename from diggersdigest/templates/shop/wishlist.html rename to app/templates/shop/wishlist.html diff --git a/diggersdigest/diggersdigest/wsgi.py b/app/wsgi.py similarity index 100% rename from diggersdigest/diggersdigest/wsgi.py rename to app/wsgi.py diff --git a/diggersdigest/deploy/start_app.sh b/diggersdigest/deploy/start_app.sh deleted file mode 100644 index a58577f..0000000 --- a/diggersdigest/deploy/start_app.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -app='diggersdigest' - -# paths -root_dir='/code' -app_dir=$root_dir'/'$app -static=$root_dir'/static/' -sandbox=$app_dir -manage=$sandbox'/manage.py' -wsgi=$sandbox'/wsgi.py' - -# waiting for other services -# sh $app_dir/examples/deploy/wait.sh - -# django init -python $manage migrate --noinput -python $manage collectstatic --noinput - -# static files auto update -#watchmedo shell-command --patterns="*.js;*.css" --recursive \ -# --command='python '$manage' collectstatic --noinput' $static & - -# app start -#uwsgi --socket :8000 --wsgi-file $wsgi --chdir $sandbox --master --processes 4 --threads 2 --py-autoreload 3 - -python $manage runserver 0.0.0.0:8000 diff --git a/diggersdigest/fabfile.py b/diggersdigest/fabfile.py deleted file mode 100644 index 7559520..0000000 --- a/diggersdigest/fabfile.py +++ /dev/null @@ -1,685 +0,0 @@ -from __future__ import print_function, unicode_literals -from future.builtins import open - -import os -import re -import sys -from contextlib import contextmanager -from functools import wraps -from getpass import getpass, getuser -from glob import glob -from importlib import import_module -from posixpath import join - -from mezzanine.utils.conf import real_project_name - -from fabric.api import abort, env, cd, prefix, sudo as _sudo, run as _run, \ - hide, task, local -from fabric.context_managers import settings as fab_settings -from fabric.contrib.console import confirm -from fabric.contrib.files import exists, upload_template -from fabric.contrib.project import rsync_project -from fabric.colors import yellow, green, blue, red -from fabric.decorators import hosts - - -################ -# Config setup # -################ - -env.proj_app = real_project_name("diggersdigest") - -conf = {} -if sys.argv[0].split(os.sep)[-1] in ("fab", "fab-script.py"): - # Ensure we import settings from the current dir - try: - conf = import_module("%s.settings" % env.proj_app).FABRIC - try: - conf["HOSTS"][0] - except (KeyError, ValueError): - raise ImportError - except (ImportError, AttributeError): - print("Aborting, no hosts defined.") - exit() - -env.db_pass = conf.get("DB_PASS", None) -env.admin_pass = conf.get("ADMIN_PASS", None) -env.user = conf.get("SSH_USER", getuser()) -env.password = conf.get("SSH_PASS", None) -env.key_filename = conf.get("SSH_KEY_PATH", None) -env.hosts = conf.get("HOSTS", [""]) - -env.proj_name = conf.get("PROJECT_NAME", env.proj_app) -env.venv_home = conf.get("VIRTUALENV_HOME", "/home/%s/.virtualenvs" % env.user) -env.venv_path = join(env.venv_home, env.proj_name) -env.proj_path = "/home/%s/mezzanine/%s" % (env.user, env.proj_name) -env.manage = "%s/bin/python %s/manage.py" % (env.venv_path, env.proj_path) -env.domains = conf.get("DOMAINS", [conf.get("LIVE_HOSTNAME", env.hosts[0])]) -env.domains_nginx = " ".join(env.domains) -env.domains_regex = "|".join(env.domains) -env.domains_python = ", ".join(["'%s'" % s for s in env.domains]) -env.ssl_disabled = "#" if len(env.domains) > 1 else "" -env.vcs_tools = ["git", "hg"] -env.deploy_tool = conf.get("DEPLOY_TOOL", "rsync") -env.reqs_path = conf.get("REQUIREMENTS_PATH", None) -env.locale = conf.get("LOCALE", "en_US.UTF-8") -env.num_workers = conf.get("NUM_WORKERS", - "multiprocessing.cpu_count() * 2 + 1") - -env.secret_key = conf.get("SECRET_KEY", "") -env.nevercache_key = conf.get("NEVERCACHE_KEY", "") - -# Remote git repos need to be "bare" and reside separated from the project -if env.deploy_tool == "git": - env.repo_path = "/home/%s/git/%s.git" % (env.user, env.proj_name) -else: - env.repo_path = env.proj_path - - -################## -# Template setup # -################## - -# Each template gets uploaded at deploy time, only if their -# contents has changed, in which case, the reload command is -# also run. - -templates = { - "nginx": { - "local_path": "deploy/nginx.conf.template", - "remote_path": "/etc/nginx/sites-enabled/%(proj_name)s.conf", - "reload_command": "service nginx restart", - }, - "supervisor": { - "local_path": "deploy/supervisor.conf.template", - "remote_path": "/etc/supervisor/conf.d/%(proj_name)s.conf", - "reload_command": "supervisorctl update gunicorn_%(proj_name)s", - }, - "cron": { - "local_path": "deploy/crontab.template", - "remote_path": "/etc/cron.d/%(proj_name)s", - "owner": "root", - "mode": "600", - }, - "gunicorn": { - "local_path": "deploy/gunicorn.conf.py.template", - "remote_path": "%(proj_path)s/gunicorn.conf.py", - }, - "settings": { - "local_path": "deploy/local_settings.py.template", - "remote_path": "%(proj_path)s/%(proj_app)s/local_settings.py", - }, -} - - -###################################### -# Context for virtualenv and project # -###################################### - -@contextmanager -def virtualenv(): - """ - Runs commands within the project's virtualenv. - """ - with cd(env.venv_path): - with prefix("source %s/bin/activate" % env.venv_path): - yield - - -@contextmanager -def project(): - """ - Runs commands within the project's directory. - """ - with virtualenv(): - with cd(env.proj_path): - yield - - -@contextmanager -def update_changed_requirements(): - """ - Checks for changes in the requirements file across an update, - and gets new requirements if changes have occurred. - """ - reqs_path = join(env.proj_path, env.reqs_path) - get_reqs = lambda: run("cat %s" % reqs_path, show=False) - old_reqs = get_reqs() if env.reqs_path else "" - yield - if old_reqs: - new_reqs = get_reqs() - if old_reqs == new_reqs: - # Unpinned requirements should always be checked. - for req in new_reqs.split("\n"): - if req.startswith("-e"): - if "@" not in req: - # Editable requirement without pinned commit. - break - elif req.strip() and not req.startswith("#"): - if not set(">=<") & set(req): - # PyPI requirement without version. - break - else: - # All requirements are pinned. - return - pip("-r %s/%s" % (env.proj_path, env.reqs_path)) - - -########################################### -# Utils and wrappers for various commands # -########################################### - -def _print(output): - print() - print(output) - print() - - -def print_command(command): - _print(blue("$ ", bold=True) + - yellow(command, bold=True) + - red(" ->", bold=True)) - - -@task -def run(command, show=True, *args, **kwargs): - """ - Runs a shell comand on the remote server. - """ - if show: - print_command(command) - with hide("running"): - return _run(command, *args, **kwargs) - - -@task -def sudo(command, show=True, *args, **kwargs): - """ - Runs a command as sudo on the remote server. - """ - if show: - print_command(command) - with hide("running"): - return _sudo(command, *args, **kwargs) - - -def log_call(func): - @wraps(func) - def logged(*args, **kawrgs): - header = "-" * len(func.__name__) - _print(green("\n".join([header, func.__name__, header]), bold=True)) - return func(*args, **kawrgs) - return logged - - -def get_templates(): - """ - Returns each of the templates with env vars injected. - """ - injected = {} - for name, data in templates.items(): - injected[name] = dict([(k, v % env) for k, v in data.items()]) - return injected - - -def upload_template_and_reload(name): - """ - Uploads a template only if it has changed, and if so, reload the - related service. - """ - template = get_templates()[name] - local_path = template["local_path"] - if not os.path.exists(local_path): - project_root = os.path.dirname(os.path.abspath(__file__)) - local_path = os.path.join(project_root, local_path) - remote_path = template["remote_path"] - reload_command = template.get("reload_command") - owner = template.get("owner") - mode = template.get("mode") - remote_data = "" - if exists(remote_path): - with hide("stdout"): - remote_data = sudo("cat %s" % remote_path, show=False) - with open(local_path, "r") as f: - local_data = f.read() - # Escape all non-string-formatting-placeholder occurrences of '%': - local_data = re.sub(r"%(?!\(\w+\)s)", "%%", local_data) - if "%(db_pass)s" in local_data: - env.db_pass = db_pass() - local_data %= env - clean = lambda s: s.replace("\n", "").replace("\r", "").strip() - if clean(remote_data) == clean(local_data): - return - upload_template(local_path, remote_path, env, use_sudo=True, backup=False) - if owner: - sudo("chown %s %s" % (owner, remote_path)) - if mode: - sudo("chmod %s %s" % (mode, remote_path)) - if reload_command: - sudo(reload_command) - - -def rsync_upload(): - """ - Uploads the project with rsync excluding some files and folders. - """ - excludes = ["*.pyc", "*.pyo", "*.db", ".DS_Store", ".coverage", - "local_settings.py", "/static", "/.git", "/.hg"] - local_dir = os.getcwd() + os.sep - return rsync_project(remote_dir=env.proj_path, local_dir=local_dir, - exclude=excludes) - - -def vcs_upload(): - """ - Uploads the project with the selected VCS tool. - """ - if env.deploy_tool == "git": - remote_path = "ssh://%s@%s%s" % (env.user, env.host_string, - env.repo_path) - if not exists(env.repo_path): - run("mkdir -p %s" % env.repo_path) - with cd(env.repo_path): - run("git init --bare") - local("git push -f %s master" % remote_path) - with cd(env.repo_path): - run("GIT_WORK_TREE=%s git checkout -f master" % env.proj_path) - run("GIT_WORK_TREE=%s git reset --hard" % env.proj_path) - elif env.deploy_tool == "hg": - remote_path = "ssh://%s@%s/%s" % (env.user, env.host_string, - env.repo_path) - with cd(env.repo_path): - if not exists("%s/.hg" % env.repo_path): - run("hg init") - print(env.repo_path) - with fab_settings(warn_only=True): - push = local("hg push -f %s" % remote_path) - if push.return_code == 255: - abort() - run("hg update") - - -def db_pass(): - """ - Prompts for the database password if unknown. - """ - if not env.db_pass: - env.db_pass = getpass("Enter the database password: ") - return env.db_pass - - -@task -def apt(packages): - """ - Installs one or more system packages via apt. - """ - return sudo("apt-get install -y -q " + packages) - - -@task -def pip(packages): - """ - Installs one or more Python packages within the virtual environment. - """ - with virtualenv(): - return run("pip install %s" % packages) - - -def postgres(command): - """ - Runs the given command as the postgres user. - """ - show = not command.startswith("psql") - return sudo(command, show=show, user="postgres") - - -@task -def psql(sql, show=True): - """ - Runs SQL against the project's database. - """ - out = postgres('psql -c "%s"' % sql) - if show: - print_command(sql) - return out - - -@task -def backup(filename): - """ - Backs up the project database. - """ - tmp_file = "/tmp/%s" % filename - # We dump to /tmp because user "postgres" can't write to other user folders - # We cd to / because user "postgres" might not have read permissions - # elsewhere. - with cd("/"): - postgres("pg_dump -Fc %s > %s" % (env.proj_name, tmp_file)) - run("cp %s ." % tmp_file) - sudo("rm -f %s" % tmp_file) - - -@task -def restore(filename): - """ - Restores the project database from a previous backup. - """ - return postgres("pg_restore -c -d %s %s" % (env.proj_name, filename)) - - -@task -def python(code, show=True): - """ - Runs Python code in the project's virtual environment, with Django loaded. - """ - setup = "import os;" \ - "os.environ[\'DJANGO_SETTINGS_MODULE\']=\'%s.settings\';" \ - "import django;" \ - "django.setup();" % env.proj_app - full_code = 'python -c "%s%s"' % (setup, code.replace("`", "\\\`")) - with project(): - if show: - print_command(code) - result = run(full_code, show=False) - return result - - -def static(): - """ - Returns the live STATIC_ROOT directory. - """ - return python("from django.conf import settings;" - "print(settings.STATIC_ROOT)", show=False).split("\n")[-1] - - -@task -def manage(command): - """ - Runs a Django management command. - """ - return run("%s %s" % (env.manage, command)) - - -########################### -# Security best practices # -########################### - -@task -@log_call -@hosts(["root@%s" % host for host in env.hosts]) -def secure(new_user=env.user): - """ - Minimal security steps for brand new servers. - Installs system updates, creates new user (with sudo privileges) for future - usage, and disables root login via SSH. - """ - run("apt-get update -q") - run("apt-get upgrade -y -q") - run("adduser --gecos '' %s" % new_user) - run("usermod -G sudo %s" % new_user) - run("sed -i 's:RootLogin yes:RootLogin no:' /etc/ssh/sshd_config") - run("service ssh restart") - print(green("Security steps completed. Log in to the server as '%s' from " - "now on." % new_user, bold=True)) - - -######################### -# Install and configure # -######################### - -@task -@log_call -def install(): - """ - Installs the base system and Python requirements for the entire server. - """ - # Install system requirements - sudo("apt-get update -y -q") - apt("nginx libjpeg-dev python-dev python-setuptools git-core " - "postgresql libpq-dev memcached supervisor python-pip") - run("mkdir -p /home/%s/logs" % env.user) - - # Install Python requirements - sudo("pip install -U pip virtualenv virtualenvwrapper mercurial") - - # Set up virtualenv - run("mkdir -p %s" % env.venv_home) - run("echo 'export WORKON_HOME=%s' >> /home/%s/.bashrc" % (env.venv_home, - env.user)) - run("echo 'source /usr/local/bin/virtualenvwrapper.sh' >> " - "/home/%s/.bashrc" % env.user) - print(green("Successfully set up git, mercurial, pip, virtualenv, " - "supervisor, memcached.", bold=True)) - - -@task -@log_call -def create(): - """ - Creates the environment needed to host the project. - The environment consists of: system locales, virtualenv, database, project - files, SSL certificate, and project-specific Python requirements. - """ - # Generate project locale - locale = env.locale.replace("UTF-8", "utf8") - with hide("stdout"): - if locale not in run("locale -a"): - sudo("locale-gen %s" % env.locale) - sudo("update-locale %s" % env.locale) - sudo("service postgresql restart") - run("exit") - - # Create project path - run("mkdir -p %s" % env.proj_path) - - # Set up virtual env - run("mkdir -p %s" % env.venv_home) - with cd(env.venv_home): - if exists(env.proj_name): - if confirm("Virtualenv already exists in host server: %s" - "\nWould you like to replace it?" % env.proj_name): - run("rm -rf %s" % env.proj_name) - else: - abort() - run("virtualenv %s" % env.proj_name) - - # Upload project files - if env.deploy_tool in env.vcs_tools: - vcs_upload() - else: - rsync_upload() - - # Create DB and DB user - pw = db_pass() - user_sql_args = (env.proj_name, pw.replace("'", "\'")) - user_sql = "CREATE USER %s WITH ENCRYPTED PASSWORD '%s';" % user_sql_args - psql(user_sql, show=False) - shadowed = "*" * len(pw) - print_command(user_sql.replace("'%s'" % pw, "'%s'" % shadowed)) - psql("CREATE DATABASE %s WITH OWNER %s ENCODING = 'UTF8' " - "LC_CTYPE = '%s' LC_COLLATE = '%s' TEMPLATE template0;" % - (env.proj_name, env.proj_name, env.locale, env.locale)) - - # Set up SSL certificate - if not env.ssl_disabled: - conf_path = "/etc/nginx/conf" - if not exists(conf_path): - sudo("mkdir %s" % conf_path) - with cd(conf_path): - crt_file = env.proj_name + ".crt" - key_file = env.proj_name + ".key" - if not exists(crt_file) and not exists(key_file): - try: - crt_local, = glob(join("deploy", "*.crt")) - key_local, = glob(join("deploy", "*.key")) - except ValueError: - parts = (crt_file, key_file, env.domains[0]) - sudo("openssl req -new -x509 -nodes -out %s -keyout %s " - "-subj '/CN=%s' -days 3650" % parts) - else: - upload_template(crt_local, crt_file, use_sudo=True) - upload_template(key_local, key_file, use_sudo=True) - - # Install project-specific requirements - upload_template_and_reload("settings") - with project(): - if env.reqs_path: - pip("-r %s/%s" % (env.proj_path, env.reqs_path)) - pip("gunicorn setproctitle psycopg2 " - "django-compressor python-memcached") - # Bootstrap the DB - manage("createdb --noinput --nodata") - python("from django.conf import settings;" - "from django.contrib.sites.models import Site;" - "Site.objects.filter(id=settings.SITE_ID).update(domain='%s');" - % env.domains[0]) - for domain in env.domains: - python("from django.contrib.sites.models import Site;" - "Site.objects.get_or_create(domain='%s');" % domain) - if env.admin_pass: - pw = env.admin_pass - user_py = ("from django.contrib.auth import get_user_model;" - "User = get_user_model();" - "u, _ = User.objects.get_or_create(username='admin');" - "u.is_staff = u.is_superuser = True;" - "u.set_password('%s');" - "u.save();" % pw) - python(user_py, show=False) - shadowed = "*" * len(pw) - print_command(user_py.replace("'%s'" % pw, "'%s'" % shadowed)) - - return True - - -@task -@log_call -def remove(): - """ - Blow away the current project. - """ - if exists(env.venv_path): - run("rm -rf %s" % env.venv_path) - if exists(env.proj_path): - run("rm -rf %s" % env.proj_path) - for template in get_templates().values(): - remote_path = template["remote_path"] - if exists(remote_path): - sudo("rm %s" % remote_path) - if exists(env.repo_path): - run("rm -rf %s" % env.repo_path) - sudo("supervisorctl update") - psql("DROP DATABASE IF EXISTS %s;" % env.proj_name) - psql("DROP USER IF EXISTS %s;" % env.proj_name) - - -############## -# Deployment # -############## - -@task -@log_call -def restart(): - """ - Restart gunicorn worker processes for the project. - If the processes are not running, they will be started. - """ - pid_path = "%s/gunicorn.pid" % env.proj_path - if exists(pid_path): - run("kill -HUP `cat %s`" % pid_path) - else: - sudo("supervisorctl update") - - -@task -@log_call -def deploy(): - """ - Deploy latest version of the project. - Backup current version of the project, push latest version of the project - via version control or rsync, install new requirements, sync and migrate - the database, collect any new static assets, and restart gunicorn's worker - processes for the project. - """ - if not exists(env.proj_path): - if confirm("Project does not exist in host server: %s" - "\nWould you like to create it?" % env.proj_name): - create() - else: - abort() - - # Backup current version of the project - with cd(env.proj_path): - backup("last.db") - if env.deploy_tool in env.vcs_tools: - with cd(env.repo_path): - if env.deploy_tool == "git": - run("git rev-parse HEAD > %s/last.commit" % env.proj_path) - elif env.deploy_tool == "hg": - run("hg id -i > last.commit") - with project(): - static_dir = static() - if exists(static_dir): - run("tar -cf static.tar --exclude='*.thumbnails' %s" % - static_dir) - else: - with cd(join(env.proj_path, "..")): - excludes = ["*.pyc", "*.pio", "*.thumbnails"] - exclude_arg = " ".join("--exclude='%s'" % e for e in excludes) - run("tar -cf {0}.tar {1} {0}".format(env.proj_name, exclude_arg)) - - # Deploy latest version of the project - with update_changed_requirements(): - if env.deploy_tool in env.vcs_tools: - vcs_upload() - else: - rsync_upload() - with project(): - manage("collectstatic -v 0 --noinput") - manage("syncdb --noinput") - manage("migrate --noinput") - for name in get_templates(): - upload_template_and_reload(name) - restart() - return True - - -@task -@log_call -def rollback(): - """ - Reverts project state to the last deploy. - When a deploy is performed, the current state of the project is - backed up. This includes the project files, the database, and all static - files. Calling rollback will revert all of these to their state prior to - the last deploy. - """ - with update_changed_requirements(): - if env.deploy_tool in env.vcs_tools: - with cd(env.repo_path): - if env.deploy_tool == "git": - run("GIT_WORK_TREE={0} git checkout -f " - "`cat {0}/last.commit`".format(env.proj_path)) - elif env.deploy_tool == "hg": - run("hg update -C `cat last.commit`") - with project(): - with cd(join(static(), "..")): - run("tar -xf %s/static.tar" % env.proj_path) - else: - with cd(env.proj_path.rsplit("/", 1)[0]): - run("rm -rf %s" % env.proj_name) - run("tar -xf %s.tar" % env.proj_name) - with cd(env.proj_path): - restore("last.db") - restart() - - -@task -@log_call -def all(): - """ - Installs everything required on a new system and deploy. - From the base software, up to the deployed project. - """ - install() - if create(): - deploy() diff --git a/diggersdigest/records_shop/__init__.py b/diggersdigest/records_shop/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/diggersdigest/records_shop/admin.py b/diggersdigest/records_shop/admin.py deleted file mode 100644 index 4a9efbc..0000000 --- a/diggersdigest/records_shop/admin.py +++ /dev/null @@ -1,4 +0,0 @@ -from django.contrib import admin - -# Register your models here. -from .models import RecordProduct diff --git a/diggersdigest/records_shop/migrations/0001_initial.py b/diggersdigest/records_shop/migrations/0001_initial.py deleted file mode 100644 index b35c028..0000000 --- a/diggersdigest/records_shop/migrations/0001_initial.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('records', '0001_initial'), - ('shop', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='RecordProduct', - fields=[ - ('product_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='shop.Product')), - ('record', models.ForeignKey(related_name='record', verbose_name='record', to='records.Record')), - ], - options={ - 'abstract': False, - }, - bases=('shop.product',), - ), - ] diff --git a/diggersdigest/records_shop/migrations/__init__.py b/diggersdigest/records_shop/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/diggersdigest/records_shop/models.py b/diggersdigest/records_shop/models.py deleted file mode 100644 index e0ef9e5..0000000 --- a/diggersdigest/records_shop/models.py +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -from django.db import models -from django.utils.translation import ugettext_lazy as _ - -from cartridge.shop.models import Product, ProductVariation - -from records.models import Record - -class RecordProduct(Product): - record = models.ForeignKey(Record, verbose_name=_('record'), related_name='record') diff --git a/diggersdigest/records_shop/tests.py b/diggersdigest/records_shop/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/diggersdigest/records_shop/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/diggersdigest/records_shop/views.py b/diggersdigest/records_shop/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/diggersdigest/records_shop/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/docker-compose.yml b/docker-compose.yml index 02e1949..95db844 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,9 @@ -dbdata: - image: mysql +media: + image: debian volumes: - - ./mysql:/var/lib/mysql - entrypoint: /bin/echo - command: data only container for db + - ./media/:/opt/media + - ./static/:/opt/static + command: "true" db: image: mysql @@ -12,15 +12,29 @@ db: - MYSQL_DATABASE=diggersdigest - MYSQL_USER=digger - MYSQL_PASSWORD=admin - volumes_from: - - dbdata + volumes: + - ./mysql:/var/lib/mysql -web: +app: build: . - command: /bin/sh diggersdigest/deploy/start_app.sh + command: /bin/sh app/deploy/start_app.sh volumes: - - .:/code + - .:/opt/app + volumes_from: + - media ports: - "8000:8000" links: - db + +nginx: + image: nginx + ports: + - "80:80" + volumes: + - ./app/deploy/nginx-app.conf:/etc/nginx/conf.d/default.conf + - /var/log/nginx + volumes_from: + - media + links: + - app diff --git a/requirements.txt b/requirements.txt index fe436d7..614861a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,5 @@ cartridge==0.10.0 django-uuidfield==0.5.0 django-newsletter==0.5.2 parsedatetime==1.5 +watchdog +uwsgi -- 2.39.5