diff --git a/Dockerfile b/Dockerfile index aa894ca..273604b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,9 +6,8 @@ ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 EXPOSE 8000 -# psycopg2 dependencies RUN apk update \ - && apk add postgresql-dev gcc python3-dev musl-dev + && apk add postgresql-dev gcc python3-dev musl-dev gettext postgresql-client # install dependencies ADD ./requirements.txt . @@ -20,4 +19,8 @@ RUN addgroup -S portier && adduser -S portier -G portier # add code ADD --chown=portier:portier . /app +RUN ./manage.py collectstatic --noinput --link +RUN ./manage.py compilemessages +USER portier + CMD ["/app/start.sh", "migrate_start"] diff --git a/docker-compose.dev.yaml b/docker-compose.dev.yaml new file mode 100644 index 0000000..324fb32 --- /dev/null +++ b/docker-compose.dev.yaml @@ -0,0 +1,29 @@ +version: '2.4' + +services: + web: + build: . + ports: + - 8000:8000 + depends_on: + - postgres + - redis + environment: + DEBUG: 1 + SECRET_KEY: "D4mn1t_Ch4nG3_M3!1!!" + SQL_ENGINE: django.db.backends.postgresql + SQL_USER: portier + SQL_PASSWORD: portier + SQL_DATABASE: portier + SQL_HOST: postgres + SQL_PORT: 5432 + REDIS_HOST: redis + REDIS_PORT: 6379 + redis: + image: redis:5-alpine + postgres: + image: postgres:11.7-alpine + environment: + POSTGRES_PASSWORD: "portier" + POSTGRES_USER: "portier" + POSTGRES_DB: "portier" diff --git a/locale/de/LC_MESSAGES/django.po b/locale/de/LC_MESSAGES/django.po new file mode 100644 index 0000000..29c8134 --- /dev/null +++ b/locale/de/LC_MESSAGES/django.po @@ -0,0 +1,23 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-04-20 20:58+0000\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: srs/models.py:9 +msgid "srs_application_name" +msgstr "" diff --git a/locale/en/LC_MESSAGES/django.po b/locale/en/LC_MESSAGES/django.po new file mode 100644 index 0000000..29c8134 --- /dev/null +++ b/locale/en/LC_MESSAGES/django.po @@ -0,0 +1,23 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-04-20 20:58+0000\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: srs/models.py:9 +msgid "srs_application_name" +msgstr "" diff --git a/portier/settings.py b/portier/settings.py index d64ef12..90a2416 100644 --- a/portier/settings.py +++ b/portier/settings.py @@ -20,12 +20,11 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '-xcxbgd8w&w&nv0-e!5=kd%u5esjt07$h5*+$goica9nc$l!(9' +SECRET_KEY = os.environ.get("SECRET_KEY", default="CHANGE_ME!") # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = ['*'] +DEBUG = int(os.environ.get("DEBUG", default=0)) +ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", default="*").split(" ") # Application definition @@ -76,9 +75,13 @@ WSGI_APPLICATION = 'portier.wsgi.application' # https://docs.djangoproject.com/en/3.0/ref/settings/#databases DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + "default": { + "ENGINE": os.environ.get("SQL_ENGINE", "django.db.backends.sqlite3"), + "NAME": os.environ.get("SQL_DATABASE", os.path.join(BASE_DIR, "db.sqlite3")), + "USER": os.environ.get("SQL_USER", "portier"), + "PASSWORD": os.environ.get("SQL_PASSWORD", "portier"), + "HOST": os.environ.get("SQL_HOST", "postgres"), + "PORT": os.environ.get("SQL_PORT", "5432"), } } @@ -120,10 +123,12 @@ USE_TZ = True # https://docs.djangoproject.com/en/3.0/howto/static-files/ STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') -CELERY_BROKER_URL = 'redis://localhost:6379' -CELERY_RESULT_BACKEND = 'redis://localhost:6379' +# Celery +CELERY_BROKER_URL = "redis://{}:{}".format(os.environ.get('REDIS_HOST', default='redis'), os.environ.get('REDIS_PORT', default=6379)) +CELERY_RESULT_BACKEND = "redis://{}:{}".format(os.environ.get('REDIS_HOST', default='redis'), os.environ.get('REDIS_PORT', default=6379)) CELERY_ACCEPT_CONTENT = ['application/json'] CELERY_RESULT_SERIALIZER = 'json' CELERY_TASK_SERIALIZER = 'json' diff --git a/requirements.txt b/requirements.txt index f6d3d64..ed1a215 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ django>=3.0 celery>=4.4 gunicorn>=20 +psycopg2-binary diff --git a/srs/models.py b/srs/models.py index 3f54d3a..218ce13 100644 --- a/srs/models.py +++ b/srs/models.py @@ -1,11 +1,12 @@ from django.db import models +from django.utils.translation import gettext as _ import uuid from . import signals class Application(models.Model): - name = models.CharField(max_length=100, unique=True) + name = models.CharField(max_length=100, unique=True, help_text=_("srs_application_name")) def __str__(self): return self.name diff --git a/start.sh b/start.sh index 27c37b8..333b161 100755 --- a/start.sh +++ b/start.sh @@ -5,15 +5,39 @@ migrate() { python manage.py migrate } +wait_for_redis() { + echo "Trying to connect to redis at ${REDIS_HOST:-redis}:${REDIS_PORT:-6379} ..." + while ! nc -z ${REDIS_HOST:-redis} ${REDIS_PORT:-6379}; + do + sleep 1; + done; + echo "Successfully connected to redis. Continuing."; +} + +wait_for_database() { + echo "Trying to connect to database at ${SQL_HOST:-postgres}:${SQL_PORT:-5432} ..." + while ! nc -z ${SQL_HOST:-postgres} ${SQL_PORT:-5432}; + do + sleep 1; + done; + echo "Successfully connected to database. Continuing."; +} + case $1 in "create_superuser" ) + wait_for_redis + wait_for_database python manage.py createsuperuser --no-input --username "${ADMIN_USER:-admin}" --email "${ADMIN_EMAIL:-post@chaoswest.tv}" ;; "migrate_start" ) + wait_for_redis + wait_for_database migrate gunicorn -w 4 --bind 0.0.0.0:${EXPOSE_PORT:-8000} portier.wsgi ;; "only_start" ) + wait_for_redis + wait_for_database gunicorn -w 4 --bind 0.0.0.0:${EXPOSE_PORT:-8000} portier.wsgi ;; esac