Skip to content

Commit

Permalink
Fix bug and production settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ldeluigi committed May 19, 2023
1 parent 523dc89 commit cb4a11f
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 24 deletions.
2 changes: 1 addition & 1 deletion backend/.kubernetes/migration/kube.migration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 7 additions & 9 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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


#########
Expand All @@ -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
5 changes: 1 addition & 4 deletions backend/backend/production_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand All @@ -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',
Expand Down
47 changes: 47 additions & 0 deletions backend/docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -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:
5 changes: 2 additions & 3 deletions backend/nginx/demo.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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/ {
Expand Down
9 changes: 2 additions & 7 deletions backend/nginx/production.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
events {}
http {
include mime.types;
server {
proxy_read_timeout 1800s;
proxy_connect_timeout 1800s;
Expand All @@ -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/ {
Expand All @@ -25,12 +26,6 @@ http {
expires 2h;
default_type application/json;
}
location ~ '\.css$' {
gzip_static on;
gunzip on;
expires 2h;
default_type text/css;
}
}
}
}

0 comments on commit cb4a11f

Please sign in to comment.