From 562738f945e2cb18830303b57fbe1a3abb1d291a Mon Sep 17 00:00:00 2001 From: Aarni Halinen Date: Wed, 9 Oct 2019 23:49:57 +0300 Subject: [PATCH 1/9] Use env variables for settings.py variables --- .env.sample | 8 ++ .gitignore | 2 +- sikweb/.ci-settings.py | 14 ---- sikweb/settings-sample.py | 75 ------------------- .../{settings-sample-prod.py => settings.py} | 22 +++--- 5 files changed, 20 insertions(+), 101 deletions(-) create mode 100644 .env.sample delete mode 100644 sikweb/.ci-settings.py delete mode 100644 sikweb/settings-sample.py rename sikweb/{settings-sample-prod.py => settings.py} (63%) diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..5be805f --- /dev/null +++ b/.env.sample @@ -0,0 +1,8 @@ +HOST=localhost +SECRET_KEY=7p$85^4ibb^p4-=vs44b7!y0e-zemugze18@a#30&71=a8)dp( +TG_BOT_TOKEN= +EMAIL_HOST= +EMAIL_PASSWD= +DB_USER=postgres +DB_PASSWD=postgres +DB_PORT=5432 \ No newline at end of file diff --git a/.gitignore b/.gitignore index b264155..aa9f6d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ *.swp -sikweb/settings.py +.env *~ *.pyc *.sqlite3 diff --git a/sikweb/.ci-settings.py b/sikweb/.ci-settings.py deleted file mode 100644 index 043f3ce..0000000 --- a/sikweb/.ci-settings.py +++ /dev/null @@ -1,14 +0,0 @@ -"""File containing CI settings.""" - -from sikweb.default_settings import * - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'ci', - 'USER': 'postgres', - 'PASSWORD': 'postgres', - 'HOST': 'postgres', - 'PORT': '5432', - }, -} diff --git a/sikweb/settings-sample.py b/sikweb/settings-sample.py deleted file mode 100644 index b92133c..0000000 --- a/sikweb/settings-sample.py +++ /dev/null @@ -1,75 +0,0 @@ - -""" -Django settings for sikweb project. - -Generated by 'django-admin startproject' using Django 1.9. - -For more information on this file, see -https://docs.djangoproject.com/en/1.9/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.9/ref/settings/ -""" - -from sikweb.base import * - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -# ALLOWED_HOSTS = ["*"] -URL = "sika.sik.party" - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '7p$85^4ibb^p4-=vs44b7!y0e-zemugze18@a#30&71=a8)dp(' - -# MQTT settings -MQTT_SETTINGS = { - 'HOST': 'mqtt.sik.party', - 'PORT': 1883, - 'TOPICS': { - 'BREW_TIME': 'sik/kiltahuone/kahvivaaka/brewtime', - 'WEIGHT': 'sik/kiltahuone/kahvivaaka/weight', - 'BREWING': 'sik/kiltahuone/kahvivaaka/brewing', - 'CUPS': 'sik/kiltahuone/kahvivaaka/cups', - } -} - -# ReCaptcha -# http://www.yaconiello.com/blog/integrating-google-recaptcha-to-django/ -GOOGLE_RECAPTCHA_SITE_KEY = "YOUR-PUBLIC-KEY" -GOOGLE_RECAPTCHA_SECRET_KEY = "YOUR-PRIVATE-KEY" - -# Email settings (more settings in base.py) -EMAIL_HOST_USER = '@gmail.com' -EMAIL_HOST_PASSWORD = '' -DEFAULT_EMAIL_FROM = 'SIK Viestintä ' -ENABLE_AUTOMATIC_EMAILS = False - -# Token for Telegram bot -TELEGRAM_BOT_TOKEN = "" - -# Database settings -# Only uncomment if default settings in base.py are not ok - -# DATABASES = { -# 'default': { -# 'ENGINE': 'django.db.backends.postgresql_psycopg2', -# 'NAME': 'sik', -# 'USER': 'sik', -# 'PASSWORD': 'password123', -# 'HOST': 'localhost', -# 'PORT': '5432', -# 'TEST': { -# 'NAME': 'sik_test', -# }, -# }, -# } -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': 'mydatabase', - 'TEST': { - 'NAME': 'sik_test', - }, - } -} diff --git a/sikweb/settings-sample-prod.py b/sikweb/settings.py similarity index 63% rename from sikweb/settings-sample-prod.py rename to sikweb/settings.py index bb05654..7333fe2 100644 --- a/sikweb/settings-sample-prod.py +++ b/sikweb/settings.py @@ -14,27 +14,27 @@ https://docs.djangoproject.com/en/1.9/ref/settings/ from sikweb.base import * # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False +DEBUG = os.getenv('DEBUG', False) == 'True' -ALLOWED_HOSTS = ["sika.sik.party"] -URL = "sika.sik.party" +URL = os.getenv("HOST", "sika.sik.party") +ALLOWED_HOSTS = [URL] # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = os.getenv('SECRET_KEY', '') # ReCaptcha # http://www.yaconiello.com/blog/integrating-google-recaptcha-to-django/ -GOOGLE_RECAPTCHA_SITE_KEY = "YOUR-PUBLIC-KEY" -GOOGLE_RECAPTCHA_SECRET_KEY = "YOUR-PRIVATE-KEY" +GOOGLE_RECAPTCHA_SITE_KEY = os.getenv("GOOGLE_RECAPTCHA_SITE_KEY", "YOUR-PUBLIC-KEY") +GOOGLE_RECAPTCHA_SECRET_KEY = os.getenv("GOOGLE_RECAPTCHA_SECRET_KEY", "YOUR-PRIVATE-KEY") # Email settings (more settings in base.py) -EMAIL_HOST_USER = 'sikviestinta@gmail.com' +EMAIL_HOST_USER = os.getenv('EMAIL_HOST', 'sikviestinta@gmail.com') EMAIL_HOST_PASSWORD = os.getenv('EMAIL_PASSWD', '') DEFAULT_EMAIL_FROM = 'SIK Viestintä ' ENABLE_AUTOMATIC_EMAILS = True # Token for Telegram bot -TELEGRAM_BOT_TOKEN = os.getenv('TG_BOT_TOKEN') +TELEGRAM_BOT_TOKEN = os.getenv('TG_BOT_TOKEN', '') # Database settings # Only uncomment if default settings in base.py are not ok @@ -42,10 +42,10 @@ TELEGRAM_BOT_TOKEN = os.getenv('TG_BOT_TOKEN') DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': os.getenv('DB_USER', ''), - 'USER': os.getenv('DB_USER', ''), - 'PASSWORD': os.getenv('DB_PASSWD', ''), - 'HOST': os.getenv('DB_HOST', '127.0.0.1'), + 'NAME': os.getenv('DB_USER', 'postgres'), + 'USER': os.getenv('DB_USER', 'postgres'), + 'PASSWORD': os.getenv('DB_PASSWD', 'postgres'), + 'HOST': os.getenv('DB_HOST', 'localhost'), 'PORT': os.getenv('DB_PORT', 5432), } } From 4e216891e6d111933b2f1bba56dbefc069a52c49 Mon Sep 17 00:00:00 2001 From: Aarni Halinen Date: Wed, 9 Oct 2019 23:51:36 +0300 Subject: [PATCH 2/9] Remove copy from Dockerfile.prod --- Dockerfile.prod | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile.prod b/Dockerfile.prod index 060f380..d8299d5 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -5,7 +5,6 @@ WORKDIR /app COPY requirements.txt ./ COPY requirements.production.txt ./ COPY . ./ -COPY sikweb/settings-sample-prod.py sikweb/settings.py # uWSGI, gunicorn etc. RUN apk add --no-cache --virtual .build-deps python3-dev build-base linux-headers pcre-dev openssl \ From 192be6e28b7f4a7ac096385b119693268e291ade Mon Sep 17 00:00:00 2001 From: Aarni Halinen Date: Thu, 10 Oct 2019 00:33:39 +0300 Subject: [PATCH 3/9] Remove copy cmds from CI --- .gitlab-ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 58d85e1..2ff9c3f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,8 +17,6 @@ test: script: - python -V - pip install -r requirements.txt - - cp sikweb/settings-sample.py sikweb/default_settings.py - - cp sikweb/.ci-settings.py sikweb/settings.py - python manage.py migrate --noinput - python manage.py createdefaultadmin - python manage.py test From 7457b8a24d49374b13bc13f6cd3b36a2b36bead9 Mon Sep 17 00:00:00 2001 From: Aarni Halinen Date: Thu, 10 Oct 2019 00:56:44 +0300 Subject: [PATCH 4/9] Add env var for unit tests --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 03fa62d..c51bb41 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,6 +14,7 @@ test: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB" + DB_HOST: postgres script: - python -V - pip install -r requirements.txt From 96fc8a55693be11d060bb419d6d56256c1e88b04 Mon Sep 17 00:00:00 2001 From: Aarni Halinen Date: Sun, 3 Nov 2019 16:06:14 +0200 Subject: [PATCH 5/9] Update development docker setup --- .env.sample | 2 + Dockerfile | 25 +++++-- Dockerfile.prod | 20 ++--- docker-compose.yml | 11 ++- setup.sh | 3 +- sikweb/base.py | 37 ---------- wait-for-it.sh | 177 --------------------------------------------- 7 files changed, 39 insertions(+), 236 deletions(-) delete mode 100755 wait-for-it.sh diff --git a/.env.sample b/.env.sample index 5be805f..65ab9dd 100644 --- a/.env.sample +++ b/.env.sample @@ -1,8 +1,10 @@ HOST=localhost +DEBUG=True SECRET_KEY=7p$85^4ibb^p4-=vs44b7!y0e-zemugze18@a#30&71=a8)dp( TG_BOT_TOKEN= EMAIL_HOST= EMAIL_PASSWD= DB_USER=postgres DB_PASSWD=postgres +DB_HOST=db DB_PORT=5432 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 3123a63..1473924 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,19 @@ -FROM python:3.7 +FROM python:3.7-alpine ENV PYTHONUNBUFFERED 1 -ENV IS_DOCKER 1 -RUN mkdir /code -WORKDIR /code -ADD requirements.txt /code/ -RUN env -ADD . /code/ +ENV IS_DOCKER 0 +WORKDIR /app +COPY requirements.txt ./ +COPY requirements.production.txt ./ +COPY . ./ + +# uWSGI, gunicorn etc. +RUN apk add --no-cache python3-dev build-base linux-headers pcre-dev openssl bash \ + # PSQL + && apk add --no-cache postgresql-dev \ + # Pillow + && apk add --no-cache jpeg-dev zlib-dev \ + && pip install --upgrade pip \ + && pip install -r requirements.txt \ + && pip install -r requirements.production.txt + +RUN python manage.py collectstatic --noinput diff --git a/Dockerfile.prod b/Dockerfile.prod index d8299d5..299a4ce 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -7,19 +7,15 @@ COPY requirements.production.txt ./ COPY . ./ # uWSGI, gunicorn etc. -RUN apk add --no-cache --virtual .build-deps python3-dev build-base linux-headers pcre-dev openssl \ - # PSQL - && apk add --no-cache postgresql-dev \ - # Pillow - && apk add --no-cache jpeg-dev zlib-dev \ - && pip install --upgrade pip \ - && pip install -r requirements.txt \ - && pip install -r requirements.production.txt \ - && apk del .build-deps +RUN apk add --no-cache python3-dev build-base linux-headers pcre-dev openssl \ + # PSQL + && apk add --no-cache postgresql-dev \ + # Pillow + && apk add --no-cache jpeg-dev zlib-dev \ + && pip install --upgrade pip \ + && pip install -r requirements.txt \ + && pip install -r requirements.production.txt RUN python manage.py collectstatic --noinput -# run migrate -# python manage.py migrate --noinput - ENTRYPOINT ["sh", "-c", "./production_entrypoint.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index 6a7b964..198c3eb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,12 +2,19 @@ version: '3' services: db: - image: postgres + image: postgres:12 + volumes: + - dbdata:/var/lib/postgresql/data web: build: . image: registry.gitlab.com/sahkoinsinoorikilta/vtmk/web2.0-backend:dev - command: ["bash", "-c", "cd /code && ./wait-for-it.sh db:5432 -- bash setup.sh --no-input --no-npm && python manage.py runserver 0.0.0.0:8000"] + command: ["bash", "-c", "cd /app & bash setup.sh --no-input --no-npm && gunicorn -w 4 -b 0.0.0.0:8000 sikweb.wsgi"] + env_file: + - .env.sample ports: - "8000:8000" depends_on: - db + +volumes: + dbdata: diff --git a/setup.sh b/setup.sh index 53c1a71..d2f82b6 100755 --- a/setup.sh +++ b/setup.sh @@ -3,7 +3,7 @@ echo "SIK WEB 2.0" echo "This script will set up the environment for this project." echo "=========================================================" -echo "Dependencies: python>3.5" +echo "Dependencies: python3.7" INTERACTIVE="true" USE_NPM="true" @@ -65,6 +65,7 @@ fi set -e set -x pip install -r requirements.txt +pip install -r requirements.production.txt $USE_NPM && npm install python manage.py migrate python manage.py createdefaultadmin diff --git a/sikweb/base.py b/sikweb/base.py index 7c026d7..5caee47 100644 --- a/sikweb/base.py +++ b/sikweb/base.py @@ -7,19 +7,12 @@ from django.utils.translation import ugettext_lazy as _ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -IS_DOCKER = bool(os.getenv('IS_DOCKER', None)) - # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer' -if not IS_DOCKER: - ALLOWED_HOSTS = [] -else: - ALLOWED_HOSTS = ["*"] - # Logger level LOGGERLEVEL = logging.DEBUG @@ -166,36 +159,6 @@ TEMPLATES = [ WSGI_APPLICATION = 'sikweb.wsgi.application' - -# Database -# https://docs.djangoproject.com/en/1.9/ref/settings/#databases - -if not IS_DOCKER: - DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'sik', - 'USER': 'sik', - 'PASSWORD': 'password123', - 'HOST': 'localhost', - 'PORT': '5432', - 'TEST': { - 'NAME': 'sik_test', - }, - }, - } -else: - logging.info('Using docker database configuration') - DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'postgres', - 'USER': 'postgres', - 'PASSWORD': 'postgres', - 'HOST': 'db', - 'PORT': '5432', - }, - } # Password validation # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators diff --git a/wait-for-it.sh b/wait-for-it.sh deleted file mode 100755 index bbe4043..0000000 --- a/wait-for-it.sh +++ /dev/null @@ -1,177 +0,0 @@ -#!/usr/bin/env bash -# Use this script to test if a given TCP host/port are available - -cmdname=$(basename $0) - -echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi } - -usage() -{ - cat << USAGE >&2 -Usage: - $cmdname host:port [-s] [-t timeout] [-- command args] - -h HOST | --host=HOST Host or IP under test - -p PORT | --port=PORT TCP port under test - Alternatively, you specify the host and port as host:port - -s | --strict Only execute subcommand if the test succeeds - -q | --quiet Don't output any status messages - -t TIMEOUT | --timeout=TIMEOUT - Timeout in seconds, zero for no timeout - -- COMMAND ARGS Execute command with args after the test finishes -USAGE - exit 1 -} - -wait_for() -{ - if [[ $TIMEOUT -gt 0 ]]; then - echoerr "$cmdname: waiting $TIMEOUT seconds for $HOST:$PORT" - else - echoerr "$cmdname: waiting for $HOST:$PORT without a timeout" - fi - start_ts=$(date +%s) - while : - do - if [[ $ISBUSY -eq 1 ]]; then - nc -z $HOST $PORT - result=$? - else - (echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1 - result=$? - fi - if [[ $result -eq 0 ]]; then - end_ts=$(date +%s) - echoerr "$cmdname: $HOST:$PORT is available after $((end_ts - start_ts)) seconds" - break - fi - sleep 1 - done - return $result -} - -wait_for_wrapper() -{ - # In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692 - if [[ $QUIET -eq 1 ]]; then - timeout $BUSYTIMEFLAG $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT & - else - timeout $BUSYTIMEFLAG $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT & - fi - PID=$! - trap "kill -INT -$PID" INT - wait $PID - RESULT=$? - if [[ $RESULT -ne 0 ]]; then - echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT" - fi - return $RESULT -} - -# process arguments -while [[ $# -gt 0 ]] -do - case "$1" in - *:* ) - hostport=(${1//:/ }) - HOST=${hostport[0]} - PORT=${hostport[1]} - shift 1 - ;; - --child) - CHILD=1 - shift 1 - ;; - -q | --quiet) - QUIET=1 - shift 1 - ;; - -s | --strict) - STRICT=1 - shift 1 - ;; - -h) - HOST="$2" - if [[ $HOST == "" ]]; then break; fi - shift 2 - ;; - --host=*) - HOST="${1#*=}" - shift 1 - ;; - -p) - PORT="$2" - if [[ $PORT == "" ]]; then break; fi - shift 2 - ;; - --port=*) - PORT="${1#*=}" - shift 1 - ;; - -t) - TIMEOUT="$2" - if [[ $TIMEOUT == "" ]]; then break; fi - shift 2 - ;; - --timeout=*) - TIMEOUT="${1#*=}" - shift 1 - ;; - --) - shift - CLI=("$@") - break - ;; - --help) - usage - ;; - *) - echoerr "Unknown argument: $1" - usage - ;; - esac -done - -if [[ "$HOST" == "" || "$PORT" == "" ]]; then - echoerr "Error: you need to provide a host and port to test." - usage -fi - -TIMEOUT=${TIMEOUT:-15} -STRICT=${STRICT:-0} -CHILD=${CHILD:-0} -QUIET=${QUIET:-0} - -# check to see if timeout is from busybox? -# check to see if timeout is from busybox? -TIMEOUT_PATH=$(realpath $(which timeout)) -if [[ $TIMEOUT_PATH =~ "busybox" ]]; then - ISBUSY=1 - BUSYTIMEFLAG="-t" -else - ISBUSY=0 - BUSYTIMEFLAG="" -fi - -if [[ $CHILD -gt 0 ]]; then - wait_for - RESULT=$? - exit $RESULT -else - if [[ $TIMEOUT -gt 0 ]]; then - wait_for_wrapper - RESULT=$? - else - wait_for - RESULT=$? - fi -fi - -if [[ $CLI != "" ]]; then - if [[ $RESULT -ne 0 && $STRICT -eq 1 ]]; then - echoerr "$cmdname: strict mode, refusing to execute subprocess" - exit $RESULT - fi - exec "${CLI[@]}" -else - exit $RESULT -fi From fdea5858ba7284fc59eb64c216944c773655125e Mon Sep 17 00:00:00 2001 From: Aarni Halinen Date: Sun, 3 Nov 2019 16:13:17 +0200 Subject: [PATCH 6/9] Remove obsolete copy from setup.sh --- setup.sh | 8 -------- 1 file changed, 8 deletions(-) diff --git a/setup.sh b/setup.sh index d2f82b6..ec3fc01 100755 --- a/setup.sh +++ b/setup.sh @@ -36,14 +36,6 @@ then exit 0 fi -$INTERACTIVE && read -p "Copy settings from template? (recommended) [y/n]" -n 1 -r || REPLY="y" -echo "" - -if [[ $REPLY =~ ^[Yy]$ ]] -then - cp "$PWD/sikweb/settings-sample.py" "$PWD/sikweb/settings.py" -fi - $INTERACTIVE && read -p "Copy pre-push hook to .git/hooks? (recommended) [y/n]" -n 1 -r || REPLY="y" echo "" From b23e439eb5a9d6cf21f4cfcc7748a5f9514ab5d6 Mon Sep 17 00:00:00 2001 From: Aarni Halinen Date: Sun, 3 Nov 2019 16:54:57 +0200 Subject: [PATCH 7/9] Remove IS_DOCKER ENV --- Dockerfile | 1 - Dockerfile.prod | 1 - 2 files changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1473924..931b522 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,5 @@ FROM python:3.7-alpine ENV PYTHONUNBUFFERED 1 -ENV IS_DOCKER 0 WORKDIR /app COPY requirements.txt ./ COPY requirements.production.txt ./ diff --git a/Dockerfile.prod b/Dockerfile.prod index 299a4ce..9452861 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -1,6 +1,5 @@ FROM python:3.7-alpine ENV PYTHONUNBUFFERED 1 -ENV IS_DOCKER 0 WORKDIR /app COPY requirements.txt ./ COPY requirements.production.txt ./ From dab6f98ec2e8147f52b891a7dc6733acf79f1e95 Mon Sep 17 00:00:00 2001 From: Aarni Halinen Date: Sun, 3 Nov 2019 17:01:38 +0200 Subject: [PATCH 8/9] Combine PROD and DEV images --- .gitlab-ci.yml | 16 +--------------- Dockerfile | 2 ++ Dockerfile.prod | 20 -------------------- docker-compose.yml | 2 +- 4 files changed, 4 insertions(+), 36 deletions(-) delete mode 100644 Dockerfile.prod diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c51bb41..ac47fdd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -45,20 +45,6 @@ remark: script: - npm run remark -# TODO: remove -publish_dev: - stage: publish - image: docker:stable - services: - - docker:stable-dind - only: - - develop - script: - - docker info - - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - - docker build . -t "$IMAGE_NAME_DEV" - - docker push "$IMAGE_NAME_DEV" - publish: stage: publish image: docker:stable @@ -69,7 +55,7 @@ publish: script: - docker info - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - - docker build . -f Dockerfile.prod -t "$IMAGE_NAME" + - docker build . -t "$IMAGE_NAME" - docker push "$IMAGE_NAME" deploy_dev: diff --git a/Dockerfile b/Dockerfile index 931b522..a82b6ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,3 +16,5 @@ RUN apk add --no-cache python3-dev build-base linux-headers pcre-dev openssl bas && pip install -r requirements.production.txt RUN python manage.py collectstatic --noinput + +CMD ["sh", "-c", "./production_entrypoint.sh"] diff --git a/Dockerfile.prod b/Dockerfile.prod deleted file mode 100644 index 9452861..0000000 --- a/Dockerfile.prod +++ /dev/null @@ -1,20 +0,0 @@ -FROM python:3.7-alpine -ENV PYTHONUNBUFFERED 1 -WORKDIR /app -COPY requirements.txt ./ -COPY requirements.production.txt ./ -COPY . ./ - -# uWSGI, gunicorn etc. -RUN apk add --no-cache python3-dev build-base linux-headers pcre-dev openssl \ - # PSQL - && apk add --no-cache postgresql-dev \ - # Pillow - && apk add --no-cache jpeg-dev zlib-dev \ - && pip install --upgrade pip \ - && pip install -r requirements.txt \ - && pip install -r requirements.production.txt - -RUN python manage.py collectstatic --noinput - -ENTRYPOINT ["sh", "-c", "./production_entrypoint.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index 198c3eb..33acf89 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: - dbdata:/var/lib/postgresql/data web: build: . - image: registry.gitlab.com/sahkoinsinoorikilta/vtmk/web2.0-backend:dev + image: registry.gitlab.com/sahkoinsinoorikilta/vtmk/web2.0-backend command: ["bash", "-c", "cd /app & bash setup.sh --no-input --no-npm && gunicorn -w 4 -b 0.0.0.0:8000 sikweb.wsgi"] env_file: - .env.sample From 2f4009d002674e89815b003912d89d55f45626bf Mon Sep 17 00:00:00 2001 From: Aarni Halinen Date: Sun, 3 Nov 2019 17:06:24 +0200 Subject: [PATCH 9/9] Update dev env --- .env.dev | 10 ++++++++++ docker-compose.yml | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .env.dev diff --git a/.env.dev b/.env.dev new file mode 100644 index 0000000..a7b70f0 --- /dev/null +++ b/.env.dev @@ -0,0 +1,10 @@ +HOST=web.sik.party +DEBUG=True +SECRET_KEY=7p$85^4ibb^p4-=vs44b7!y0e-zemugze18@a#30&71=a8)dp( +TG_BOT_TOKEN= +EMAIL_HOST= +EMAIL_PASSWD= +DB_USER=postgres +DB_PASSWD=postgres +DB_HOST=db +DB_PORT=5432 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 33acf89..828dc1e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: image: registry.gitlab.com/sahkoinsinoorikilta/vtmk/web2.0-backend command: ["bash", "-c", "cd /app & bash setup.sh --no-input --no-npm && gunicorn -w 4 -b 0.0.0.0:8000 sikweb.wsgi"] env_file: - - .env.sample + - .env.dev ports: - "8000:8000" depends_on: