Skip to content
Snippets Groups Projects
Commit edb00c10 authored by jan.bednarik's avatar jan.bednarik
Browse files

CI and Docker deployment

parent 3f12431d
No related branches found
No related tags found
No related merge requests found
.git
.venv
.env
stages:
- build
image: docker:20.10.8
variables:
DOCKER_TLS_CERTDIR: "/certs"
IMAGE_TAG_APP: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
services:
- docker:20.10.8-dind
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
build_app:
stage: build
script:
- docker pull $CI_REGISTRY_IMAGE:test || true
- docker build --cache-from $CI_REGISTRY_IMAGE:test -t $IMAGE_TAG_APP .
- docker push $IMAGE_TAG_APP
FROM python:3.6
RUN mkdir /app
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
RUN bash -c 'adduser --disabled-login --quiet --gecos app app && \
chmod -R o+r /app/ && \
chmod o+x /app/run.sh'
USER app
EXPOSE 8000
CMD ["bash", "run.sh"]
......@@ -3,3 +3,29 @@
Fork used by the Czech Pirate Party. Includes PirateID integration and Czech translation.
Helios is an end-to-end verifiable voting system.
## Info
větve v gitu:
- `original` je kopie https://github.com/benadida/helios-server
- `master` je z `original` odvozená Pirátská verze nasazená v produkci
- `test` je testovací verze odvozená z `master` nasazená pro testování
Obvykle děláme změny v `test` a když je to ok, releasujeme do `master`.
### Jak na upgrade?
1. aktualizuj větev `original`
2. udělej rebase větve `master` z větve `original`
3. udělej novou větev `test` odvozenou z `master`
## Čas
S časem se v kódu pracuje velmi primitivně. Všechny časy jsou naivně a musí být UTC.
Což komplikuje všechno. Ale podařilo se to rozumně pořešit na vstupu a výstupu.
V kódu je to ohnuté takto:
* Vizuálně času v templatech prohnán přes filtr `|timezone:"Europe/Prague"`.
* Ve form field `SplitDateTimeField` očekáváme Europe/Prague a převádíme na UTC.
bind = "0.0.0.0:8000"
accesslog = "-"
workers = 1
max_requests = 1000
max_requests_jitter = 10
timeout = 60
graceful_timeout = 60
......@@ -6,7 +6,7 @@ gunicorn==20.0.4
dj_database_url==0.5.0
psycopg2==2.8.4
celery==4.2.1
celery[redis]==4.4.7
django-picklefield==1.1.0
django-anymail==8.4
......@@ -25,3 +25,5 @@ rollbar==0.14.7
requests-oauthlib==1.3.1
unidecode==1.3.6
sentry-sdk[django]==1.40.5
run.sh 0 → 100644
#!/bin/bash
# exit on error
set -e
# migrate database
python manage.py migrate
# start webserver
exec gunicorn -c gunicorn.conf.py wsgi
......@@ -5,6 +5,11 @@ import sys
import json
import os
import sentry_sdk
from sentry_sdk.integrations.celery import CeleryIntegration
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.logging import LoggingIntegration
TESTING = 'test' in sys.argv
# go through environment variables and override them
......@@ -49,7 +54,7 @@ DATABASES = {
# override if we have an env variable
if get_from_env('DATABASE_URL', None):
import dj_database_url
DATABASES['default'] = dj_database_url.config(conn_max_age=600, ssl_require=True)
DATABASES['default'] = dj_database_url.config(conn_max_age=600)
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
# Local time zone for this installation. Choices can be found here:
......@@ -308,3 +313,16 @@ OCTOPUS_API_TOKEN = get_from_env('OCTOPUS_API_TOKEN', '')
if DEBUG:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# Sentry setup
SENTRY_DSN = get_from_env('SENTRY_DSN', '')
if SENTRY_DSN:
sentry_sdk.init(
dsn=SENTRY_DSN,
integrations=[
DjangoIntegration(),
CeleryIntegration(),
LoggingIntegration(level=logging.INFO, event_level=logging.WARNING),
],
send_default_pii=True,
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment