diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 119ba6e..f01c908 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -56,7 +56,7 @@ publish: script: - docker info - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - - docker build . -t "$IMAGE_NAME" + - docker build . -f Dockerfile.prod -t "$IMAGE_NAME" - docker push "$IMAGE_NAME" deploy_dev: diff --git a/Dockerfile.prod b/Dockerfile.prod new file mode 100644 index 0000000..d683eb4 --- /dev/null +++ b/Dockerfile.prod @@ -0,0 +1,18 @@ +FROM python:alpine +ENV PYTHONUNBUFFERED 1 +ENV IS_DOCKER 0 +WORKDIR /app +COPY requirements.txt ./ +COPY requirements-production.txt ./ + +RUN apk add --no-cache --virtual .build-deps build-base linux-headers \ + && apk add --no-cache jpeg-dev zlib-dev postgresql-dev \ + && pip install -r requirements.txt \ + && pip install -r requirements.production.txt \ + && apk del .build-deps + +COPY . ./ +COPY sikweb/settings-sample-prod.py settings.py + +ENTRYPOINT ["sh", "-c", "echo 'Django running on http://localhost:8000 in production mode' \ + && gunicorn -w 4 -b 0.0.0.0:8000 web20-backend.wsgi"] diff --git a/docker-compose.yml b/docker-compose.yml index a42ae3d..9dc0e6d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,6 +3,8 @@ version: '3' services: db: image: postgres + volumes: + - db-data:/var/lib/postgresql/data web: build: . image: registry.gitlab.com/sahkoinsinoorikilta/vtmk/web2.0-backend @@ -11,3 +13,5 @@ services: - "8000:8000" depends_on: - db +volumes: + db-data: {} diff --git a/sikweb/settings-sample-prod.py b/sikweb/settings-sample-prod.py new file mode 100644 index 0000000..3a4b659 --- /dev/null +++ b/sikweb/settings-sample-prod.py @@ -0,0 +1,50 @@ + +""" +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 = False + +ALLOWED_HOSTS = ["sika.sik.party"] + +# 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" + +# Email settings (more settings in base.py) +EMAIL_HOST_USER = os.getenv('EMAIL_HOST', '@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') + +# Database settings +# Only uncomment if default settings in base.py are not ok + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': os.getenv('DB_NAME', ''), + 'USER': os.getenv('DB_USER', ''), + 'PASSWORD': os.getenv('DB_PASSWORD', ''), + 'HOST': os.getenv('DB_HOST', '127.0.0.1'), + 'PORT': os.getenv('DB_PORT', 5432), + } +} diff --git a/stack-compose.yml b/stack-compose.yml index f74e67d..7781f95 100644 --- a/stack-compose.yml +++ b/stack-compose.yml @@ -1,6 +1,6 @@ version: '3.2' services: - web20_backend: + backend: image: registry.gitlab.com/sahkoinsinoorikilta/vtmk/web2.0-backend:latest ports: - 8000:8000