Skip to content

Commit

Permalink
🎭 Production image (#101)
Browse files Browse the repository at this point in the history
* Adds missing modules to production image

* Adds OV_DEBUG flag

* Adds more production env vars

* Adds manage.py to docker image

* Try deploy with pwd /app

* Binds prod server to 8000

* Adds s3 media access to production settings

* Fixes s3 custom domain

* Adds s3 url signatures

* Try with QUERYSTRING_AUTH

* Removes OV_ from AWS_ vars

* Actually removes OV_ from AWS_ vars

* Try without custom domain

* Adds frontend config to docker compose
  • Loading branch information
mrharpo authored Nov 16, 2023
1 parent 5fee679 commit ed5de47
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 122 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ RUN apt-get update --yes --quiet && apt-get install --yes --quiet --no-install-r
libwebp-dev \
&& rm -rf /var/lib/apt/lists/*

COPY pyproject.toml pdm.lock README.md ./
COPY ov_wag ov_wag
COPY pyproject.toml pdm.lock README.md manage.py ./
COPY authors authors
COPY cli cli
COPY exhibits exhibits
COPY home home
COPY ov_collections ov_collections
COPY ov_wag ov_wag
COPY search search

### Test ###
Expand Down
2 changes: 1 addition & 1 deletion dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3.8'
services:
wagtail:
ports:
- 8000:80
- 8000:8000
depends_on:
- db
environment:
Expand Down
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,16 @@ services:
volumes:
- db:/var/lib/postgresql/data

front:
image: ov-front
build:
context: ../ov-frontend
target: dev
environment:
- OV_API_URL=http://wagtail:8000
volumes:
- ../ov-frontend:/app
ports:
- 3000:3000
volumes:
db:
12 changes: 8 additions & 4 deletions docker_entrypoints/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/bin/bash

cd /app/
# Build static files for the admin site
python3 manage.py collectstatic --noinput

# Run the production server
gunicorn ov_wag.wsgi:application \
--reload \
--access-logfile /logs/access.log \
--error-logfile /logs/error.log
-b 0.0.0.0:8000 \
--workers 2 \
--forwarded-allow-ips '*' \
--access-logfile - \
--error-logfile -
# --access-logfile /logs/access.log \
# --error-logfile /logs/error.log
2 changes: 1 addition & 1 deletion docker_entrypoints/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
python manage.py migrate --noinput

# NOTE: this is a background process that will keep the container running.
python manage.py runserver 0.0.0.0:80
python manage.py runserver 0.0.0.0:8000
18 changes: 15 additions & 3 deletions ov_wag/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,29 @@

from ov_wag.settings.base import * # noqa F403

DEBUG = False
DEBUG = bool(env.get('OV_DEBUG', False))

SECRET_KEY = env.get('OV_SECRET_KEY')

ALLOWED_HOSTS = env.get('OV_ALLOWED_HOSTS').split(',')

CSRF_TRUSTED_ORIGINS = env.get('OV_TRUSTED_ORIGINS').split(',')
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = bool(env.get('OV_CSRF_COOKIE_SECURE', True))
SESSION_COOKIE_SECURE = bool(env.get('OV_SESSION_COOKIE_SECURE', True))
SECURE_SSL_REDIRECT = False

INSTALLED_APPS += [ # noqa: F405
'storages',
]
# S3 Storage
AWS_STORAGE_BUCKET_NAME = env.get('AWS_STORAGE_BUCKET_NAME')
AWS_ACCESS_KEY_ID = env.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = env.get('AWS_SECRET_ACCESS_KEY')
MEDIA_URL = f'https://s3.amazonaws.com/{AWS_STORAGE_BUCKET_NAME}/'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_S3_FILE_OVERWRITE = False
AWS_S3_SIGNATURE_VERSION = 's3v4'
AWS_QUERYSTRING_AUTH = True

with suppress(ImportError):
from .local import * # noqa F403
197 changes: 90 additions & 107 deletions pdm.lock

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ ov = 'cli:app'

[project.optional-dependencies]
cli = [
"typer~=0.9",
"loguru~=0.7",
"trogon~=0.5",
'typer~=0.9',
'loguru~=0.7',
'trogon~=0.5',
]
production = [
"gunicorn[standard]~=21.2",
'gunicorn[standard]~=21.2',
'django-storages[s3]~=1.14'
]

[build-system]
Expand Down

0 comments on commit ed5de47

Please sign in to comment.