From f00ff0bada3b13f467d4373b8bcfbe155c051c19 Mon Sep 17 00:00:00 2001 From: Stefan Bunde Date: Mon, 7 May 2018 14:26:42 +0200 Subject: [PATCH 1/4] rename target directory for management command collectstatic to collected_static as the files in this directory were collected --- castellum_core/.gitignore | 2 +- castellum_core/Makefile | 3 +++ .../castellum_core/castellum_core/settings/default.py | 2 +- castellum_core/castellum_core/collected_static/.gitkeep | 0 4 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 castellum_core/castellum_core/collected_static/.gitkeep diff --git a/castellum_core/.gitignore b/castellum_core/.gitignore index 874dcc6b3..252596451 100644 --- a/castellum_core/.gitignore +++ b/castellum_core/.gitignore @@ -5,7 +5,7 @@ castellum_core.egg-info/ dist/ htmlcov/ node_modules/ -collectstatic/ +collected_static/ *.pyc *.sqlite3 diff --git a/castellum_core/Makefile b/castellum_core/Makefile index 42a7ca3d4..270f83b7e 100644 --- a/castellum_core/Makefile +++ b/castellum_core/Makefile @@ -17,6 +17,9 @@ makemigrations: createsuperuser: $(MANAGEPY) shell -c "from castellum_auth.models import User; User.objects.filter(username='admin') or User.objects.create_superuser('admin', 'admin@example.com', '123')" +collectstatic: + $(MANAGEPY) collectstatic + install: pip install tox ipdb pip install -e . diff --git a/castellum_core/castellum_core/castellum_core/settings/default.py b/castellum_core/castellum_core/castellum_core/settings/default.py index 78c6e8a17..efee35148 100644 --- a/castellum_core/castellum_core/castellum_core/settings/default.py +++ b/castellum_core/castellum_core/castellum_core/settings/default.py @@ -108,7 +108,7 @@ STATICFILES_FINDERS = [ STATIC_URL = '/static/' -STATIC_ROOT = os.path.join(BASE_DIR, 'collectstatic') +STATIC_ROOT = os.path.join(BASE_DIR, 'collected_static') NPM_ROOT_PATH = os.path.dirname(BASE_DIR) diff --git a/castellum_core/castellum_core/collected_static/.gitkeep b/castellum_core/castellum_core/collected_static/.gitkeep new file mode 100644 index 000000000..e69de29bb -- GitLab From 9dc2c78069242912f41d59018f81e75531ed9a6a Mon Sep 17 00:00:00 2001 From: Stefan Bunde Date: Mon, 7 May 2018 14:47:47 +0200 Subject: [PATCH 2/4] add dockerfile for nginx to create independent container without volumes --- docker-compose.yml | 11 ++++++----- services/nginx/Dockerfile | 6 ++++++ services/nginx/nginx.conf | 25 +++++++++++++++++++++++++ stage/nginx.conf | 17 ----------------- 4 files changed, 37 insertions(+), 22 deletions(-) create mode 100644 services/nginx/Dockerfile create mode 100644 services/nginx/nginx.conf delete mode 100644 stage/nginx.conf diff --git a/docker-compose.yml b/docker-compose.yml index 5acb24b00..75d476376 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,15 +27,16 @@ services: depends_on: - db - ldap + nginx: - image: nginx - volumes: - - ./stage/nginx.conf:/etc/nginx/conf.d/default.conf - - static-content:/static + build: + context: . + dockerfile: ./services/nginx/Dockerfile ports: - - "8000:80" + - "80:80" depends_on: - web + restart: unless-stopped volumes: static-content: diff --git a/services/nginx/Dockerfile b/services/nginx/Dockerfile new file mode 100644 index 000000000..8f6e2290e --- /dev/null +++ b/services/nginx/Dockerfile @@ -0,0 +1,6 @@ +FROM nginx:1.13-alpine + +COPY ./services/nginx/nginx.conf /etc/nginx/nginx.conf +COPY ./castellum_core/castellum_core/collected_static /static + +EXPOSE 80 diff --git a/services/nginx/nginx.conf b/services/nginx/nginx.conf new file mode 100644 index 000000000..52ae83b0b --- /dev/null +++ b/services/nginx/nginx.conf @@ -0,0 +1,25 @@ +events { + worker_connections 1024; +} + + +http { + upstream castellum_core { + server web:9000; + } + + server { + listen *:80; + + location / { + include /etc/nginx/uwsgi_params; + uwsgi_pass castellum_core; + } + + location /static { + include /etc/nginx/mime.types; + alias /static; + autoindex off; + } + } +} diff --git a/stage/nginx.conf b/stage/nginx.conf deleted file mode 100644 index 949d4e1da..000000000 --- a/stage/nginx.conf +++ /dev/null @@ -1,17 +0,0 @@ -server { - listen *:80; - - location / { - include /etc/nginx/uwsgi_params; - uwsgi_pass castellum_core; - } - - location /static { - alias /static; - autoindex off; - } -} - -upstream castellum_core { - server web:9000; -} -- GitLab From 53cf143f3293a46def30b1d377a797885027bb05 Mon Sep 17 00:00:00 2001 From: Stefan Bunde Date: Mon, 7 May 2018 14:58:21 +0200 Subject: [PATCH 3/4] remove unused static commands in docker-compose file --- docker-compose.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 75d476376..b80b65801 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,10 +19,8 @@ services: sh -c " python3 castellum_core/manage.py migrate && python3 castellum_core/manage.py shell -c \"from castellum_auth.models import User; User.objects.filter(username='admin') or User.objects.create_superuser('admin', 'admin@example.com', '123')\" && - python3 castellum_core/manage.py collectstatic --no-input && uwsgi uwsgi.ini" volumes: - - static-content:/code/castellum_core/collectstatic - ./stage/settings.py:/code/castellum_core/castellum_core/settings/stage.py depends_on: - db @@ -37,6 +35,3 @@ services: depends_on: - web restart: unless-stopped - -volumes: - static-content: -- GitLab From be263659e3c0d3c4f8c617d23985475bb03f475e Mon Sep 17 00:00:00 2001 From: Stefan Bunde Date: Mon, 7 May 2018 16:32:32 +0200 Subject: [PATCH 4/4] listen in django container on port 8000 like the django development server --- castellum_core/uwsgi.ini | 2 +- services/nginx/nginx.conf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/castellum_core/uwsgi.ini b/castellum_core/uwsgi.ini index 732c1c885..bea07cb66 100644 --- a/castellum_core/uwsgi.ini +++ b/castellum_core/uwsgi.ini @@ -1,7 +1,7 @@ [uwsgi] chdir=/code/castellum_core wsgi-file=castellum_core/wsgi.py -socket=0.0.0.0:9000 +socket=0.0.0.0:8000 plugin=python3 env=DJANGO_SETTINGS_MODULE=castellum_core.settings.stage uid=uwsgi diff --git a/services/nginx/nginx.conf b/services/nginx/nginx.conf index 52ae83b0b..be2fce62a 100644 --- a/services/nginx/nginx.conf +++ b/services/nginx/nginx.conf @@ -5,7 +5,7 @@ events { http { upstream castellum_core { - server web:9000; + server web:8000; } server { -- GitLab