diff options
-rw-r--r-- | .dockerignore | 1 | ||||
-rw-r--r-- | .gitlab-ci.yml | 10 | ||||
-rw-r--r-- | docker-compose.yml | 34 | ||||
-rwxr-xr-x | docker/app/migrate_and_serve.sh | 13 | ||||
-rw-r--r-- | docker/pysite.dockerapp | 23 |
5 files changed, 65 insertions, 16 deletions
diff --git a/.dockerignore b/.dockerignore index 33fc984e..d853d0d2 100644 --- a/.dockerignore +++ b/.dockerignore @@ -17,6 +17,7 @@ api/tests.py CHANGELOG.md CONTRIBUTING.md docker +!docker/app/migrate_and_boot.sh !docker/app/uwsgi.ini docker-compose.yml Dockerfile diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index be2ac1d0..22190d43 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -38,6 +38,8 @@ build-alpine-3.7: -f docker/app/alpine/3.7/Dockerfile . - docker push $BASE_IMAGE_URL:alpine-3.7-$CI_COMMIT_REF_SLUG + tags: + - docker build-alpine-3.6: stage: build @@ -52,6 +54,8 @@ build-alpine-3.6: -f docker/app/alpine/3.6/Dockerfile . - docker push $BASE_IMAGE_URL:alpine-3.6-$CI_COMMIT_REF_SLUG + tags: + - docker build-stretch-3.7: stage: build @@ -66,6 +70,8 @@ build-stretch-3.7: -f docker/app/stretch/3.7/Dockerfile . - docker push $BASE_IMAGE_URL:stretch-3.7-$CI_COMMIT_REF_SLUG + tags: + - docker build-stretch-3.6: stage: build @@ -80,6 +86,8 @@ build-stretch-3.6: -f docker/app/stretch/3.6/Dockerfile . - docker push $BASE_IMAGE_URL:stretch-3.6-$CI_COMMIT_REF_SLUG + tags: + - docker lint-python: stage: lint @@ -145,6 +153,8 @@ pages: paths: - public expire_in: 30 days + tags: + - docker push-django: image: docker:stable-git diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..ee302d4e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,34 @@ +### Docker compose setup file +# This file can be used to quickly set up a development server +# with code auto-reloading and automatic execution of migrations. +# +## Note +# This file is not intended to be used for production. +# The "migrate and server" script will automatically apply migrations +# and additionally use the Django development server which is +# unsuitable for production. + +version: "3.6" +services: + django: + build: + context: . + dockerfile: docker/app/alpine/3.7/Dockerfile + command: docker/app/migrate_and_serve.sh + ports: + - "127.0.0.1:8000:8000" + depends_on: + - postgres + volumes: + - .:/app:ro + environment: + DATABASE_URL: postgres://pysite:supersecretpassword@postgres/pysite + DEBUG: "true" + SECRET_KEY: suitable-for-development-only + + postgres: + image: postgres:11-alpine + environment: + POSTGRES_DB: pysite + POSTGRES_PASSWORD: supersecretpassword + POSTGRES_USER: pysite diff --git a/docker/app/migrate_and_serve.sh b/docker/app/migrate_and_serve.sh new file mode 100755 index 00000000..032504e2 --- /dev/null +++ b/docker/app/migrate_and_serve.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +### NOTE +# This file is intended to be used by local setups. +# You do not want to run the Django development server +# in production. The default Dockerfile command will +# run using uWSGI, this script is provided purely as +# a convenience to run migrations and start a development server. + +echo [i] Applying migrations. +python manage.py migrate --verbosity 0 +echo [i] Starting server. +python manage.py runserver 0.0.0.0:8000 diff --git a/docker/pysite.dockerapp b/docker/pysite.dockerapp index 4a811861..dc472b2e 100644 --- a/docker/pysite.dockerapp +++ b/docker/pysite.dockerapp @@ -1,8 +1,8 @@ -version: 0.1.0 +version: 0.3.0 name: pysite description: | Our community website, built on Django and PostgreSQL. -#namespace: python-discord +namespace: python-discord maintainers: - name: Johannes Christ email: [email protected] @@ -11,15 +11,16 @@ maintainers: version: "3.6" services: django: - image: registry.gitlab.com/python-discord/projects/site/django:latest + build: + context: . + command: docker/app/migrate_and_serve.sh ports: - "127.0.0.1:4000:4000" environment: DATABASE_URL: "postgres://${pg_user}:${pg_passwd}@${pg_host}/${pg_db}" - DEBUG: 0 + DEBUG: 'false' SECRET_KEY: "${secret_key}" depends_on: - - migrator - postgres postgres: @@ -29,20 +30,10 @@ services: POSTGRES_USER: "${pg_user}" POSTGRES_PASSWORD: "${pg_passwd}" - migrator: - image: registry.gitlab.com/python-discord/projects/site/django:latest - environment: - DATABASE_URL: "postgres://${pg_user}:${pg_passwd}@${pg_host}/${pg_db}" - DEBUG: 0 - SECRET_KEY: "${secret_key}" - command: "python manage.py migrate" - depends_on: - - postgres - --- pg_user: pysite pg_db: pysite -pg_passwd: '' +pg_passwd: supersecretpassword pg_host: postgres secret_key: 'suitable-for-development-only' |