Add Dockerfile for production deployment
This commit is contained in:
parent
fdcc881f81
commit
9153e2bc73
8 changed files with 84 additions and 15 deletions
8
.dockerignore
Normal file
8
.dockerignore
Normal 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
21
.github/workflows/docker.yml
vendored
Normal 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
26
Dockerfile
Normal 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"]
|
|
@ -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
|
||||
|
|
|
@ -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
9
scripts/setup-node.sh
Executable 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
12
scripts/setup-python.sh
Executable 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
|
|
@ -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
|
||||
|
|
Reference in a new issue