Add docker files

This commit is contained in:
Pavle Portic 2019-03-23 04:52:49 +01:00
parent 91f6d77135
commit 309e0358f8
Signed by: TheEdgeOfRage
GPG Key ID: 6758ACE46AA2A849
7 changed files with 121 additions and 7 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
static/perks
.env

21
Dockerfile-backend Normal file
View File

@ -0,0 +1,21 @@
# vim: set ft=dockerfile :
FROM python:3.7-alpine
COPY backend /app
WORKDIR /app
EXPOSE 80
RUN set -ex \
&& apk add --no-cache --virtual .build-deps \
gcc \
make \
libc-dev \
musl-dev \
libffi-dev \
&& pip install --no-cache-dir pipenv \
&& pipenv install --system --clear \
&& apk del .build-deps \
&& rm db.sqlite3
CMD ["./entrypoint.sh"]

20
Dockerfile-frontend Normal file
View File

@ -0,0 +1,20 @@
# vim: set ft=dockerfile :
# Stage 1 (Bundling)
FROM node:alpine as builder
COPY frontend /app
WORKDIR /app
RUN set -ex \
&& apk add --no-cache yarn \
&& yarn install \
&& yarn run build
# Stage 2 (Packaging)
FROM nginx:alpine
COPY --from=builder /app/dist /app
COPY nginx.conf /etc/nginx/conf.d
RUN rm /etc/nginx/conf.d/default.conf
EXPOSE 80

11
backend/entrypoint.sh Executable file
View File

@ -0,0 +1,11 @@
#! /bin/sh
#
# entrypoint.sh
# Copyright (C) 2019 pavle <pavle.portic@tilda.center>
#
# Distributed under terms of the BSD-3-Clause license.
#
python manage.py migrate
gunicorn -w 4 --bind 0.0.0.0:80 perktree.wsgi:application

View File

@ -20,16 +20,16 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '^j_x7a7u_#9ruh3p^h=*my_k+asoqob&xq@5n^2n2f(7$#dk(#'
SECRET_KEY = '^j_x7a7u_#9ruh3p^h=*my_k+asoqob&xq@5n^2n2f(7$#dk(#' if os.environ.get('DJANGO_ENV') == 'dev' else os.environ.get('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = os.environ.get('DJANGO_ENV') == 'dev'
ALLOWED_HOSTS = [
'perktree.localhost'
'perktree.localhost',
os.environ.get('APP_HOST'),
]
# Application definition
INSTALLED_APPS = [
@ -78,12 +78,15 @@ WSGI_APPLICATION = 'perktree.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE': os.environ.get('DB_ENGINE', ''),
'NAME': os.path.join(BASE_DIR, os.environ.get('DB_NAME', '')) if os.environ.get('DJANGO_ENV') == 'dev' else os.environ.get('DB_NAME', ''),
'USER': os.environ.get('DB_USER', ''),
'PASSWORD': os.environ.get('DB_PASSWORD', ''),
'HOST': os.environ.get('DB_HOST', ''),
'PORT': os.environ.get('DB_PORT', ''),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

40
docker-compose.yml Normal file
View File

@ -0,0 +1,40 @@
version: "3"
services:
db:
image: mariadb
container_name: perktree-db
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: perktree-root-password
MYSQL_DATABASE: perktree
frontend:
build:
context: .
dockerfile: Dockerfile-frontend
container_name: perktree-frontend
restart: unless-stopped
ports:
- 8019:80
links:
- backend
backend:
build:
context: .
dockerfile: Dockerfile-backend
container_name: perktree-backend
restart: unless-stopped
environment:
SECRET_KEY: ${SECRET_KEY}
DJANGO_ENV: prod
APP_HOST: perktree.theedgeofrage.com
DB_ENGINE: django.db.backends.mysql
DB_NAME: perktree
DB_USER: root
DB_PASSWORD: perktree-root-password
DB_HOST: db
DB_PORT: 3306
links:
- db

18
nginx.conf Normal file
View File

@ -0,0 +1,18 @@
server {
listen 80;
server_name _;
client_max_body_size 5M;
location /api/ {
proxy_pass http://perktree-backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
root /app;
try_files $uri $uri/ /index.html;
}
}