-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from GateNLP/docker_deploy_2
deploy in docker container
- Loading branch information
Showing
18 changed files
with
349 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
frontend/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
FROM continuumio/miniconda3:latest | ||
|
||
ENV PYTHONUNBUFFERED 1 | ||
|
||
RUN apt-get --allow-releaseinfo-change update && \ | ||
apt-get -y install gcc libpq-dev libmagic1 && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
ADD https://github.com/krallin/tini/releases/download/v0.19.0/tini /sbin/tini | ||
RUN addgroup --gid 1001 "gate" && \ | ||
adduser --disabled-password --gecos "GATE User,,," \ | ||
--home /app --ingroup gate --uid 1001 gate && \ | ||
chmod +x /sbin/tini | ||
|
||
COPY --chown=gate:gate environment.yml /app/ | ||
WORKDIR /app | ||
RUN chown --recursive gate:gate /opt/conda/ | ||
USER gate:gate | ||
RUN conda env create --name annotation-tool --file environment.yml | ||
RUN conda install --name annotation-tool gunicorn | ||
|
||
COPY --chown=gate:gate package.json package-lock.json /app/ | ||
COPY --chown=gate:gate frontend/package.json frontend/package-lock.json /app/frontend/ | ||
|
||
SHELL ["conda", "run", "-n", "annotation-tool", "/bin/bash", "-c"] | ||
|
||
RUN npm install --unsafe-perm --only=production | ||
|
||
COPY --chown=gate:gate manage.py /app/ | ||
COPY --chown=gate:gate examples/ /app/examples/ | ||
COPY --chown=gate:gate annotation_tool/ /app/annotation_tool/ | ||
COPY --chown=gate:gate backend/ /app/backend | ||
COPY --chown=gate:gate frontend/ /app/frontend/ | ||
RUN npm run build | ||
RUN python manage.py collectstatic --noinput | ||
|
||
COPY --chown=gate:gate run-server.sh generate-env.sh /app/ | ||
|
||
USER root | ||
ENTRYPOINT [ "/app/run-server.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,36 @@ | ||
import logging | ||
import sys | ||
from .base import * | ||
|
||
# Enable csrf in production | ||
MIDDLEWARE.append( | ||
'django.middleware.csrf.CsrfViewMiddleware' | ||
) | ||
|
||
ALLOWED_HOSTS.append('annotate.gate.ac.uk') | ||
|
||
|
||
LOGGING = { | ||
'version': 1, | ||
'disable_existing_loggers': False, | ||
'formatters': { | ||
'verbose': { | ||
'format': '%(asctime)s %(name)-12s %(levelname)-8s %(message)s', | ||
}, | ||
}, | ||
'handlers': { | ||
'console': { | ||
'level': 'INFO', | ||
'class': 'logging.StreamHandler', | ||
'stream': sys.stdout, | ||
'formatter': 'verbose' | ||
}, | ||
}, | ||
'loggers': { | ||
'': { | ||
'handlers': ['console'], | ||
'level': 'INFO', | ||
'propagate': True, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# "Secret" config for use in the docker container, that takes secrets from environment vars | ||
import os | ||
|
||
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY') | ||
POSTGRES_USERNAME = os.environ.get('DB_USERNAME') | ||
POSTGRES_PASSWORD = os.environ.get('DB_PASSWORD') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
docker build -t annotate-backend:latest . | ||
|
||
docker build -t annotate-static:latest nginx/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
echo "Generating .env file" | ||
./generate-env.sh | ||
|
||
DEPLOY_ENV=$1 | ||
|
||
case $DEPLOY_ENV in | ||
|
||
production|prod) | ||
DJANGO_SETTINGS_MODULE=annotation_tool.settings.production | ||
;; | ||
|
||
staging|stag) | ||
DJANGO_SETTINGS_MODULE=annotation_tool.settings.staging | ||
;; | ||
|
||
*) | ||
exit 1 | ||
;; | ||
esac | ||
|
||
echo "Deploying with DJANGO_SETTINGS_MODULE: $DJANGO_SETTINGS_MODULE" | ||
|
||
DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE docker-compose up -d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
version: "3.9" | ||
|
||
services: | ||
|
||
backend: | ||
image: annotate-backend:latest | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
restart: always | ||
environment: | ||
- DJANGO_SETTINGS_MODULE | ||
- DJANGO_SECRET_KEY | ||
- DJANGO_DB_NAME | ||
- DB_USERNAME | ||
- DB_PASSWORD | ||
# depends_on: | ||
# - db | ||
volumes: | ||
- ./db.sqlite3:/app/db.sqlite3 | ||
- logs/:/logs/ | ||
networks: | ||
- django-nginx | ||
|
||
nginx: | ||
image: annotate-static:latest | ||
build: | ||
context: . | ||
dockerfile: ./nginx/Dockerfile | ||
ports: | ||
- 80:80 | ||
depends_on: | ||
- backend | ||
# - db | ||
networks: | ||
- django-nginx | ||
|
||
|
||
# db: | ||
# image: postgres:12-alpine | ||
# restart: always | ||
# expose: | ||
# - "5432" | ||
# env_file: | ||
# - ./.env | ||
# environment: | ||
# - POSTGRES_USER=postgres | ||
# - POSTGRES_PASSWORD=${PG_SUPERUSER_PASSWORD} | ||
# - DJANGO_DB_NAME | ||
# - DJANGO_DB_USER=${DB_USERNAME} | ||
# - DJANGO_DB_PASSWORD=${DB_PASSWORD} | ||
# - DB_BACKUP_USER | ||
# - DB_BACKUP_PASSWORD | ||
# volumes: | ||
# - postgresql-data:/var/lib/postgresql/data | ||
# - ./create-django-db.sh:/docker-entrypoint-initdb.d/001-create-django-db.sh | ||
|
||
volumes: | ||
logs: | ||
# postgresql-data: | ||
|
||
networks: | ||
django-nginx: | ||
driver: bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/sh | ||
# | ||
# Creates a .env file with random passwords and Django secret key | ||
# | ||
|
||
if [ -f .env ]; then | ||
BAKNAME=$(date +%Y-%m-%d-%H-%M-%S) | ||
echo "Existing .env found - backing up as saved-env.$BAKNAME" | ||
cp .env saved-env.$BAKNAME | ||
fi | ||
|
||
cat > .env <<EOF | ||
PG_SUPERUSER_PASSWORD=$(openssl rand -base64 16) | ||
DJANGO_DB_NAME=annotations_db | ||
DB_USERNAME=gate | ||
DB_PASSWORD=$(openssl rand -base64 16) | ||
DJANGO_SECRET_KEY=$(openssl rand -base64 42) | ||
DB_BACKUP_USER=backup | ||
DB_BACKUP_PASSWORD=$(openssl rand -base64 16) | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM nginx:stable-alpine | ||
RUN rm /etc/nginx/conf.d/default.conf | ||
COPY production.conf /etc/nginx/nginx.conf | ||
COPY --from=backend:latest /app/static /usr/share/nginx/html | ||
COPY --from=backend:latest /app/frontend/ /usr/share/nginx/html/frontend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
user nginx; | ||
worker_processes 1; | ||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http{ | ||
|
||
include /etc/nginx/mime.types; | ||
|
||
upstream annotation_tool { | ||
server backend:8000; | ||
} | ||
|
||
server { | ||
|
||
listen 80; | ||
|
||
location / { | ||
proxy_pass http://annotation_tool; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header Host $host; | ||
proxy_redirect off; | ||
} | ||
|
||
location /static/ { | ||
alias /usr/share/nginx/html/; | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.