diff --git a/backend/.kubernetes/migration/kube.migration.yaml b/backend/.kubernetes/migration/kube.migration.yaml index 6a372286..c1dfdc32 100644 --- a/backend/.kubernetes/migration/kube.migration.yaml +++ b/backend/.kubernetes/migration/kube.migration.yaml @@ -10,7 +10,7 @@ spec: - name: spellbook-migration image: 083767677168.dkr.ecr.us-east-2.amazonaws.com/spellbook-prod-ecr command: ["/bin/sh","-c"] - args: ["python manage.py migrate; python manage.py seed_website_properties; python manage.py clean_jobs;"] + args: ["python manage.py migrate --noinput; python manage.py seed_website_properties; python manage.py clean_jobs;"] env: - name: SECRET_KEY valueFrom: diff --git a/backend/Dockerfile b/backend/Dockerfile index e293ad10..4f2a4f39 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -50,8 +50,8 @@ RUN pip install --no-cache psycopg[binary] gunicorn # copy project COPY --chown=app:app . $APP_HOME -# # change to the app user -# USER app +# change to the app user +USER app ARG SECRET_KEY ENV SECRET_KEY=${SECRET_KEY} @@ -63,7 +63,7 @@ ENV DJANGO_SETTINGS_MODULE=backend.production_settings # run entrypoint.prod.sh EXPOSE 80 ENTRYPOINT ["/bin/sh", "entrypoint.prod.sh"] -RUN echo -e 'gunicorn backend.wsgi:application --bind 0.0.0.0:8000 --workers=3\n' > entrypoint.prod.sh +RUN echo -e 'gunicorn backend.wsgi:application --bind 0.0.0.0:8000\n' > entrypoint.prod.sh ######### @@ -89,11 +89,9 @@ FROM base AS production ADD nginx/production.conf /etc/nginx/nginx.conf +# Switch to user root in order to run nginx on port 80 +USER root + RUN echo -e 'python manage.py collectstatic --no-input --clear\n\ -sleep 3\n\ nginx\n\ -python manage.py migrate --noinput\n\ -python manage.py clean_jobs\n\ -python manage.py export_variants\n\ -python manage.py seed_website_properties\n\ -gunicorn backend.wsgi:application --bind 0.0.0.0:8000\n' > entrypoint.prod.sh +gunicorn backend.wsgi:application --bind 0.0.0.0:8000 --workers=3\n' > entrypoint.prod.sh diff --git a/backend/backend/production_settings.py b/backend/backend/production_settings.py index 65a2e0a8..5beb29cd 100644 --- a/backend/backend/production_settings.py +++ b/backend/backend/production_settings.py @@ -2,9 +2,6 @@ from .settings import * # noqa: F403 from .settings import BASE_DIR, REST_FRAMEWORK import sys -import mimetypes - -mimetypes.add_type("text/css", ".css", True) TESTING = sys.argv[1:2] == ['test'] @@ -14,7 +11,7 @@ DEBUG = False # Security settings -ALLOWED_HOSTS = ['.commanderspellbook.com'] +ALLOWED_HOSTS = ['.commanderspellbook.com', 'localhost'] CSRF_TRUSTED_ORIGINS = [ 'https://commanderspellbook.com', 'http://localhost', diff --git a/backend/docker-compose.prod.yml b/backend/docker-compose.prod.yml new file mode 100644 index 00000000..26a6ddf8 --- /dev/null +++ b/backend/docker-compose.prod.yml @@ -0,0 +1,47 @@ +version: '3.8' + +services: + web: + build: + context: . + target: production + args: + SECRET_KEY: ${SECRET_KEY:-tmp_key} + image: spellbook-backend + ports: + - 80:80 + depends_on: + db: + condition: service_healthy + links: + - db + environment: + SQL_ENGINE: django.db.backends.postgresql + SQL_DATABASE: spellbook_db_test + SQL_USER: test_user + SQL_PASSWORD: test_password + SQL_HOST: db + SQL_PORT: 5432 + DATABASE: postgres + restart: always + + db: + image: postgres:14-alpine + volumes: + - postgres_data:/var/lib/postgresql/data/ + expose: + - 5432 + environment: + PGPORT: 5432 + POSTGRES_USER: test_user + POSTGRES_PASSWORD: test_password + POSTGRES_DB: spellbook_db_test + healthcheck: + test: ["CMD-SHELL", "pg_isready -q -d spellbook_db_test -U test_user" ] + interval: 5s + timeout: 5s + retries: 5 + restart: always + +volumes: + postgres_data: diff --git a/backend/nginx/demo.conf b/backend/nginx/demo.conf index 1875e809..15af7e85 100644 --- a/backend/nginx/demo.conf +++ b/backend/nginx/demo.conf @@ -5,14 +5,13 @@ upstream spellbook { server { listen 80; listen [::]:80; - include /etc/nginx/ssl/*.conf; location / { + proxy_redirect off; proxy_pass http://spellbook; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; - proxy_redirect off; } location /static/ { diff --git a/backend/nginx/production.conf b/backend/nginx/production.conf index 2048c2ed..3196649b 100644 --- a/backend/nginx/production.conf +++ b/backend/nginx/production.conf @@ -1,5 +1,6 @@ events {} http { + include mime.types; server { proxy_read_timeout 1800s; proxy_connect_timeout 1800s; @@ -10,11 +11,11 @@ http { gzip_types text/plain application/json; location / { + proxy_pass http://0.0.0.0:8000; proxy_set_header Host $http_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-Proto $scheme; - proxy_pass http://0.0.0.0:8000; } location /static/ { @@ -25,12 +26,6 @@ http { expires 2h; default_type application/json; } - location ~ '\.css$' { - gzip_static on; - gunzip on; - expires 2h; - default_type text/css; - } } } }