1
Fork 0

Add Dockerfile for production deployment

This commit is contained in:
Jake Howard 2020-04-25 16:50:04 +01:00
parent fdcc881f81
commit 9153e2bc73
Signed by: jake
GPG Key ID: 57AFB45680EDD477
8 changed files with 84 additions and 15 deletions

8
.dockerignore Normal file
View File

@ -0,0 +1,8 @@
.cache
.mypy_cache
collected-static
env
htmlcov
node_modules
static/build
__pycache__

21
.github/workflows/docker.yml vendored Normal file
View File

@ -0,0 +1,21 @@
name: Docker
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Build container
run: docker build --tag docker.pkg.github.com/${GITHUB_REPOSITORY,,}/website:latest .
- name: Log into GitHub Docker Registry
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login docker.pkg.github.com -u ${GITHUB_REPOSITORY%/*} --password-stdin
if: github.ref == 'master'
- name: Push the Docker container
run: docker push docker.pkg.github.com/${GITHUB_REPOSITORY,,}/website:latest
if: github.ref == 'master'

26
Dockerfile Normal file
View File

@ -0,0 +1,26 @@
FROM node:lts-alpine as build
ENV NODE_ENV production
ENV NPM_CONFIG_PROUCTION false
WORKDIR /app
COPY . /app
RUN ./scripts/setup-node.sh
FROM python:3.8-slim
ENV DEBUG false
WORKDIR /app
COPY . /app
COPY --from=build /app/static/build /app/static/build
RUN ./scripts/setup-python.sh
RUN rm -rf ./static
EXPOSE 8000
CMD ["gunicorn", "-b", "0.0.0.0:8000", "--preload", "--access-logfile", "/dev/stdout", "website.wsgi:application"]

View File

@ -3,3 +3,4 @@ django-debug-toolbar==2.2
whitenoise==5.0.1
brotli==1.0.7
django-environ==0.4.5
gunicorn ==20.0.4

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
export PATH=node_modules/.bin:${PATH}

9
scripts/setup-node.sh Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env sh
export PATH=node_modules/.bin:${PATH}
set -ex
npm ci
./scripts/build-static.sh

12
scripts/setup-python.sh Executable file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -ex
pip install -r requirements.txt
if [ "$DEBUG" != "false" ];
then
pip install -r dev-requirements.txt
fi
python3 ./manage.py collectstatic --noinput --clear -v 2

View File

@ -1,20 +1,12 @@
#!/usr/bin/env bash
set -e
./scripts/setup-node.sh
export PATH=env/bin:${PATH}
set -ex
python3 -m venv env
pip install -r requirements.txt
if [ "$DEBUG" != "false" ];
then
pip install -r dev-requirements.txt
fi
npm ci
./scripts/build-static.sh
./manage.py collectstatic --noinput --clear -v 2
./scripts/setup-python.sh