From 484f7c556e77e913dc0ab028687ec57e7cbd73a9 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Wed, 7 Nov 2018 13:31:26 +0100 Subject: [PATCH] docker first try --- .dockerignore | 10 +++++++++ .env.secret.template | 8 ++++++++ .env.template | 3 +++ Dockerfile | 29 ++++++++++++++++++++++++++ docker-compose.yml | 43 +++++++++++++++++++++++++++++++++++++++ nginx/conf.d/Recipes.conf | 17 ++++++++++++++++ update.sh | 3 +++ 7 files changed, 113 insertions(+) create mode 100644 .dockerignore create mode 100644 .env.secret.template create mode 100644 .env.template create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 nginx/conf.d/Recipes.conf create mode 100644 update.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..6975847ed --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +node_modules +npm-debug.log +Dockerfile* +docker-compose* +.dockerignore +.git +.gitignore +README.md +LICENSE +.vscode \ No newline at end of file diff --git a/.env.secret.template b/.env.secret.template new file mode 100644 index 000000000..864b7e5ee --- /dev/null +++ b/.env.secret.template @@ -0,0 +1,8 @@ +DEBUG=1 +ALLOWED_HOSTS=* +SECRET_KEY= +POSTGRES_HOST=db_recipes +POSTGRES_PORT=5432 +POSTGRES_USER=djangodb +POSTGRES_PASSWORD= +POSTGRES_DB=djangodb \ No newline at end of file diff --git a/.env.template b/.env.template new file mode 100644 index 000000000..c95d2e582 --- /dev/null +++ b/.env.template @@ -0,0 +1,3 @@ +VIRTUAL_HOST= +LETSENCRYPT_HOST= +LETSENCRYPT_EMAIL= \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..a6fba6aa1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ + +FROM alpine + +# Project Files and Settings + +RUN mkdir /Recipes +WORKDIR /Recipes + +ADD . /Recipes/ + +RUN apk update +RUN apk upgrade +RUN apk --no-cache add \ + python3 \ + python3-dev \ + postgresql-client \ + postgresql-dev \ + build-base \ + gettext +RUN pip3 install --upgrade pip + +RUN pip3 install -r requirements.txt + +RUN apk del -r python3-dev + +ENV PYTHONUNBUFFERED 1 + +# Server +EXPOSE 8080 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..437f6eadb --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,43 @@ +version: "3" +services: + db_recipes: + restart: always + image: "postgres:10.3-alpine" + volumes: + - /usr/src/recipes/postgresql:/var/lib/postgresql/data + env_file: + - ./.env.secret + networks: + - default + + web_recipes: + build: . + restart: always + env_file: + - ./.env.secret + command: "gunicorn --bind 0.0.0.0:8080 Recipes.wsgi" + volumes: + - .:/Recipes + depends_on: + - db_recipes + networks: + - default + + nginx_recipes: + image: "nginx" + restart: always + env_file: + - ./.env + volumes: + - ./nginx/conf.d:/etc/nginx/conf.d + - ./staticfiles:/static + - ./mediafiles:/media + networks: + - default + - nginx-proxy + +networks: + default: + nginx-proxy: + external: + name: nginx-proxy diff --git a/nginx/conf.d/Recipes.conf b/nginx/conf.d/Recipes.conf new file mode 100644 index 000000000..9e7b1283c --- /dev/null +++ b/nginx/conf.d/Recipes.conf @@ -0,0 +1,17 @@ +server { + listen 80; + server_name localhost; + # serve static files + location /static/ { + alias /static/; + } + # serve media files + location /media/ { + alias /media/; + } + # pass requests for dynamic content to gunicorn + location / { + proxy_set_header Host $host; + proxy_pass http://web_recipes:8080; + } +} \ No newline at end of file diff --git a/update.sh b/update.sh new file mode 100644 index 000000000..6aaca01df --- /dev/null +++ b/update.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +docker-compose run web_recipes python3 manage.py migrate +docker-compose run web_recipes python3 manage.py collectstatic