From 0e718b3e6d5f736e14d7fb8670e81ad2edc35b38 Mon Sep 17 00:00:00 2001 From: Paul Eipper Date: Thu, 19 Dec 2019 23:31:52 -0300 Subject: [PATCH 1/6] build: add Dockerfile config Use `make test` to run a local dev build of the project, and `make prod` to create a production image ready to be pushed to a docker registry. --- .dockerignore | 7 ++ Makefile | 34 +++++++++ build/Dockerfile | 93 +++++++++++++++++++++++ build/confd/conf.d/local_settings.toml | 3 + build/confd/templates/local_settings.tmpl | 27 +++++++ build/django/create-superuser.py | 49 ++++++++++++ build/docker-entrypoint.sh | 13 ++++ build/setup.sh | 38 +++++++++ build/uwsgi.ini | 8 ++ 9 files changed, 272 insertions(+) create mode 100644 .dockerignore create mode 100644 Makefile create mode 100644 build/Dockerfile create mode 100644 build/confd/conf.d/local_settings.toml create mode 100644 build/confd/templates/local_settings.tmpl create mode 100644 build/django/create-superuser.py create mode 100644 build/docker-entrypoint.sh create mode 100755 build/setup.sh create mode 100644 build/uwsgi.ini diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..da6727ed --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.tx/ +docs/ +logo/ +scripts/ +.coveragerc +.travis.yml +Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..32abf7f3 --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +MAINTAINER=nkey +TAG=nsupdate.info +VER=$(shell git describe) +UWSGI_UID=700 +UWSGI_GID=700 + +all: prod + +prod: + docker build --build-arg BUILD=prod --build-arg uwsgi_uid=$(UWSGI_UID) --build-arg uwsgi_gid=$(UWSGI_GID) -t $(MAINTAINER)/$(TAG):$(VER) --rm -f ./build/Dockerfile . + docker tag $(MAINTAINER)/$(TAG):$(VER) $(MAINTAINER)/$(TAG):prod + +release: + docker push $(MAINTAINER)/$(TAG):$(VER) + docker push $(MAINTAINER)/$(TAG):prod + @echo "*** Don't forget to create a tag by creating an official GitHub release." + +release_latest: + docker tag $(MAINTAINER)/$(TAG):$(VER) $(MAINTAINER)/$(TAG):latest + docker push $(MAINTAINER)/$(TAG):latest + +release_stable: + docker tag $(MAINTAINER)/$(TAG):$(VER) $(MAINTAINER)/$(TAG):stable + docker push $(MAINTAINER)/$(TAG):stable + +dev: + docker build --build-arg BUILD=dev --build-arg uwsgi_uid=$(UWSGI_UID) --build-arg uwsgi_gid=$(UWSGI_GID) -t $(MAINTAINER)/$(TAG):$(VER)-dev --rm -f ./build/Dockerfile . + docker tag $(MAINTAINER)/$(TAG):$(VER)-dev $(MAINTAINER)/$(TAG):dev + +test: dev clean + docker run -P --name $(TAG)-test-dev -d $(MAINTAINER)/$(TAG):dev + +clean: + -docker rm -f -v $(TAG)-test-dev diff --git a/build/Dockerfile b/build/Dockerfile new file mode 100644 index 00000000..f04174c7 --- /dev/null +++ b/build/Dockerfile @@ -0,0 +1,93 @@ +FROM debian:stable-slim +LABEL maintainer="it@nkey.com.br" + +ARG BUILD=prod +ARG uwsgi_uid=700 +ARG uwsgi_gid=700 + +ENV BUILD=$BUILD +ENV DOCKER_CONTAINER=1 +ENV UWSGI_INI /nsupdate/uwsgi.ini +ENV DJANGO_SETTINGS_MODULE=local_settings +ENV DJANGO_SUPERUSER=django +ENV DJANGO_SUPERPASS=S3cr3t +ENV DJANGO_EMAIL=django@nsupdate.localdomain +ENV SERVICE_CONTACT=hostmaster@nsupdate.localdomain +ENV SECRET_KEY=S3cr3t +ENV BASEDOMAIN=nsupdate.localdomain +ENV REGISTRATION_OPEN=False + +RUN mkdir /static +RUN mkdir /upload +RUN mkdir /var/run/uwsgi + +# Install runtime tools +RUN DEBIAN_FRONTEND=noninteractive apt-get update \ + && apt-get install -y --no-install-recommends \ + python3 \ + python3-setuptools \ + python3-pip + +# Install confd +RUN apt-get install -y --no-install-recommends wget \ + && mkdir -p /usr/local/bin \ + && wget -O /usr/local/bin/confd https://github.com/kelseyhightower/confd/releases/download/v0.16.0/confd-0.16.0-linux-amd64 \ + && chmod +x /usr/local/bin/confd \ + && mkdir -p /etc/confd/{conf.d,templates} \ + && apt-get autoremove -y wget + +# Use local version of nsupdate from sources +COPY ./*.py /nsupdate/ +COPY ./*.rst /nsupdate/ +COPY ./*.in /nsupdate/ +COPY ./*.cfg /nsupdate/ +COPY ./*.txt /nsupdate/ +COPY ./requirements.d/ /nsupdate/requirements.d/ +COPY ./.git/ /nsupdate/.git/ +COPY ./src/ /nsupdate/src/ +WORKDIR /nsupdate + +# Build and install +RUN DEBIAN_FRONTEND=noninteractive apt-get update \ + && apt-get install -y --no-install-recommends \ + git \ + python3-dev \ + build-essential \ + libpcre3-dev \ + && pip3 install wheel \ + && python3 setup.py bdist_wheel \ + && pip3 install psycopg2-binary uwsgi \ + && pip3 install -r requirements.d/$BUILD.txt \ + && pip3 install -e . \ + && cp /usr/lib/x86_64-linux-gnu/libpython* /tmp \ + && apt-get autoremove -y \ + git \ + python3-dev \ + build-essential \ + libpcre3-dev \ + && cp /tmp/libpython* /usr/lib/x86_64-linux-gnu/ \ + && rm -rf build \ + && rm -rf .git && rm -rf /root/.cache \ + && rm -rf /tmp/* /var/tmp/* \ + && rm -rf /var/lib/apt/lists/* + +# Copy helper files +COPY build/django/create-superuser.py /nsupdate/src/nsupdate/management/commands/create-superuser.py +COPY build/uwsgi.ini /nsupdate/uwsgi.ini +COPY build/confd/ /etc/confd/ +COPY build/setup.sh / +COPY build/docker-entrypoint.sh /var/local/ + +# Set the permissions according to env options +RUN chmod a+x /var/local/docker-entrypoint.sh +RUN bash /setup.sh "${uwsgi_uid}" "${uwsgi_gid}" + +VOLUME /nsupdate +VOLUME /static +VOLUME /upload +VOLUME /var/run/uwsgi + +EXPOSE 3031 +EXPOSE 8080 + +ENTRYPOINT ["/var/local/docker-entrypoint.sh"] diff --git a/build/confd/conf.d/local_settings.toml b/build/confd/conf.d/local_settings.toml new file mode 100644 index 00000000..791cc6c6 --- /dev/null +++ b/build/confd/conf.d/local_settings.toml @@ -0,0 +1,3 @@ +[template] +src = "local_settings.tmpl" +dest = "/nsupdate/local_settings.py" diff --git a/build/confd/templates/local_settings.tmpl b/build/confd/templates/local_settings.tmpl new file mode 100644 index 00000000..ff9a751e --- /dev/null +++ b/build/confd/templates/local_settings.tmpl @@ -0,0 +1,27 @@ +from nsupdate.settings.{{getenv "BUILD"}} import * + +STATIC_ROOT='/static' +MEDIA_ROOT='/upload' + +SECRET_KEY = '{{ getenv "SECRET_KEY" }}' +BASEDOMAIN = '{{ getenv "BASEDOMAIN" }}' +WWW_HOST='{{ getenv "BASEDOMAIN" }}' + +REGISTRATION_OPEN = False + +SERVICE_CONTACT = '{{ getenv "SERVICE_CONTACT" }}' + +ALLOWED_HOSTS=['localhost', '127.0.0.1', '[::1]', '{{ getenv "BASEDOMAIN" }}'] + +{{ if getenv "DB_NAME"}} +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': '{{getenv "DB_NAME"}}', # database name + 'USER': '{{getenv "DB_USER"}}', + 'PASSWORD': '{{getenv "DB_PASS"}}', + 'HOST': '{{getenv "DB_HOST"}}', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. + 'PORT': '{{getenv "DB_PORT"}}' # Set to empty string for default. + } +} +{{end}} diff --git a/build/django/create-superuser.py b/build/django/create-superuser.py new file mode 100644 index 00000000..a211e923 --- /dev/null +++ b/build/django/create-superuser.py @@ -0,0 +1,49 @@ +# Title: create-superuser.py +# Link: https://gist.github.com/c00kiemon5ter/7806c1eac8c6a3e82f061ec32a55c702 +# License: None (Public Domain) + +from django.contrib.auth.management.commands import createsuperuser +from django.core.management import CommandError + +class Command(createsuperuser.Command): + help = 'Create a superuser with a password non-interactively' + + def add_arguments(self, parser): + super(Command, self).add_arguments(parser) + parser.add_argument( + '--preserve', dest='preserve', default=False, action='store_true', + help='Exit normally if the user already exists.', + ) + parser.add_argument( + '--password', dest='password', default=None, + help='Specifies the password for the superuser.', + ) + + def handle(self, *args, **options): + options.setdefault('interactive', False) + database = options.get('database') + password = options.get('password') + username = options.get('username') + email = options.get('email') + + if not password or not username or not email: + raise CommandError( + "--username, --password, and --email are required options") + + if username and options.get('preserve'): + exists = self.UserModel._default_manager.db_manager(database).filter(username=username).exists() + if exists: + self.stdout.write("User exists, exiting normally due to --preserve") + return + + user_data = { + 'username': username, + 'password': password, + 'email': email, + } + + self.UserModel._default_manager.db_manager( + database).create_superuser(**user_data) + + if options.get('verbosity', 0) >= 1: + self.stdout.write("Superuser created successfully.") diff --git a/build/docker-entrypoint.sh b/build/docker-entrypoint.sh new file mode 100644 index 00000000..7fca4303 --- /dev/null +++ b/build/docker-entrypoint.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +/usr/local/bin/confd -onetime -backend env + +python3 manage.py collectstatic +python3 manage.py migrate +python3 manage.py create-superuser --preserve --username $DJANGO_SUPERUSER --password $DJANGO_SUPERPASS --email $DJANGO_EMAIL + +# Fix Permissions prior to running uwsgi server +chown -R www-data:www-data /static +chown -R www-data:www-data /nsupdate + +uwsgi --uid=www-data --gid=www-data --ini uwsgi.ini diff --git a/build/setup.sh b/build/setup.sh new file mode 100755 index 00000000..f67510b6 --- /dev/null +++ b/build/setup.sh @@ -0,0 +1,38 @@ +#!/usr/bin/bash + +#Quit on error. +set -e +# Treat undefined variables as errors. +set -u + + +function main { + local uwsgi_uid="${1:-}" + local uwsgi_gid="${2:-}" + + # Change the uid + if [[ -n "${uwsgi_uid:-}" ]]; then + usermod -u "${uwsgi_uid}" www-data + fi + # Change the gid + if [[ -n "${uwsgi_gid:-}" ]]; then + groupmod -g "${uwsgi_gid}" www-data + fi + + # Setup permissions on the run directory where the sockets will be + # created, so we are sure the app will have the rights to create them. + + # Set owner. + chown www-data:www-data /var/run/uwsgi + # Set permissions. + chmod u=rwX,g=rwX,o=--- /var/run/uwsgi + + # Set app folder permissions + chown -R www-data:www-data /nsupdate + chown -R www-data:www-data /static + chown -R www-data:www-data /upload + +} + + +main "$@" diff --git a/build/uwsgi.ini b/build/uwsgi.ini new file mode 100644 index 00000000..e7485581 --- /dev/null +++ b/build/uwsgi.ini @@ -0,0 +1,8 @@ +[uwsgi] +socket = /var/run/uwsgi/uwsgi.sock +socket = :3031 +http-socket = :8080 +workers = 3 +master = true +wsgi-file=/nsupdate/src/nsupdate/wsgi.py +env = LANG=en_US.UTF-8 From c941a9e3954fa85a6c4caea1e07c0554e1d3773a Mon Sep 17 00:00:00 2001 From: Paul Eipper Date: Mon, 30 Dec 2019 19:18:03 -0300 Subject: [PATCH 2/6] build: move docker into contrib --- .dockerignore => misc/contrib/docker/.dockerignore | 0 Makefile => misc/contrib/docker/Makefile | 0 {build => misc/contrib/docker/build}/Dockerfile | 0 .../contrib/docker/build}/confd/conf.d/local_settings.toml | 0 .../contrib/docker/build}/confd/templates/local_settings.tmpl | 0 {build => misc/contrib/docker/build}/django/create-superuser.py | 0 {build => misc/contrib/docker/build}/docker-entrypoint.sh | 0 {build => misc/contrib/docker/build}/setup.sh | 0 {build => misc/contrib/docker/build}/uwsgi.ini | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename .dockerignore => misc/contrib/docker/.dockerignore (100%) rename Makefile => misc/contrib/docker/Makefile (100%) rename {build => misc/contrib/docker/build}/Dockerfile (100%) rename {build => misc/contrib/docker/build}/confd/conf.d/local_settings.toml (100%) rename {build => misc/contrib/docker/build}/confd/templates/local_settings.tmpl (100%) rename {build => misc/contrib/docker/build}/django/create-superuser.py (100%) rename {build => misc/contrib/docker/build}/docker-entrypoint.sh (100%) rename {build => misc/contrib/docker/build}/setup.sh (100%) rename {build => misc/contrib/docker/build}/uwsgi.ini (100%) diff --git a/.dockerignore b/misc/contrib/docker/.dockerignore similarity index 100% rename from .dockerignore rename to misc/contrib/docker/.dockerignore diff --git a/Makefile b/misc/contrib/docker/Makefile similarity index 100% rename from Makefile rename to misc/contrib/docker/Makefile diff --git a/build/Dockerfile b/misc/contrib/docker/build/Dockerfile similarity index 100% rename from build/Dockerfile rename to misc/contrib/docker/build/Dockerfile diff --git a/build/confd/conf.d/local_settings.toml b/misc/contrib/docker/build/confd/conf.d/local_settings.toml similarity index 100% rename from build/confd/conf.d/local_settings.toml rename to misc/contrib/docker/build/confd/conf.d/local_settings.toml diff --git a/build/confd/templates/local_settings.tmpl b/misc/contrib/docker/build/confd/templates/local_settings.tmpl similarity index 100% rename from build/confd/templates/local_settings.tmpl rename to misc/contrib/docker/build/confd/templates/local_settings.tmpl diff --git a/build/django/create-superuser.py b/misc/contrib/docker/build/django/create-superuser.py similarity index 100% rename from build/django/create-superuser.py rename to misc/contrib/docker/build/django/create-superuser.py diff --git a/build/docker-entrypoint.sh b/misc/contrib/docker/build/docker-entrypoint.sh similarity index 100% rename from build/docker-entrypoint.sh rename to misc/contrib/docker/build/docker-entrypoint.sh diff --git a/build/setup.sh b/misc/contrib/docker/build/setup.sh similarity index 100% rename from build/setup.sh rename to misc/contrib/docker/build/setup.sh diff --git a/build/uwsgi.ini b/misc/contrib/docker/build/uwsgi.ini similarity index 100% rename from build/uwsgi.ini rename to misc/contrib/docker/build/uwsgi.ini From 4d166c84caa6aa51c213687661e2deafa6860ac2 Mon Sep 17 00:00:00 2001 From: Paul Eipper Date: Mon, 30 Dec 2019 23:31:53 -0300 Subject: [PATCH 3/6] build(docker): parameterize Dockerfile path --- misc/contrib/docker/Makefile | 8 +++++--- misc/contrib/docker/build/Dockerfile | 11 ++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/misc/contrib/docker/Makefile b/misc/contrib/docker/Makefile index 32abf7f3..81dc6e72 100644 --- a/misc/contrib/docker/Makefile +++ b/misc/contrib/docker/Makefile @@ -1,13 +1,15 @@ -MAINTAINER=nkey +MAINTAINER=nkeyapps TAG=nsupdate.info VER=$(shell git describe) UWSGI_UID=700 UWSGI_GID=700 +BASE_DIR='../../..' +DOCKER_DIR='misc/contrib/docker' all: prod prod: - docker build --build-arg BUILD=prod --build-arg uwsgi_uid=$(UWSGI_UID) --build-arg uwsgi_gid=$(UWSGI_GID) -t $(MAINTAINER)/$(TAG):$(VER) --rm -f ./build/Dockerfile . + cd $(BASE_DIR); docker build --build-arg BUILD=prod --build-arg uwsgi_uid=$(UWSGI_UID) --build-arg uwsgi_gid=$(UWSGI_GID) --build-arg DOCKER_DIR=$(DOCKER_DIR) -t $(MAINTAINER)/$(TAG):$(VER) --rm -f $(DOCKER_DIR)/build/Dockerfile . docker tag $(MAINTAINER)/$(TAG):$(VER) $(MAINTAINER)/$(TAG):prod release: @@ -24,7 +26,7 @@ release_stable: docker push $(MAINTAINER)/$(TAG):stable dev: - docker build --build-arg BUILD=dev --build-arg uwsgi_uid=$(UWSGI_UID) --build-arg uwsgi_gid=$(UWSGI_GID) -t $(MAINTAINER)/$(TAG):$(VER)-dev --rm -f ./build/Dockerfile . + cd $(BASE_DIR); docker build --build-arg BUILD=dev --build-arg uwsgi_uid=$(UWSGI_UID) --build-arg uwsgi_gid=$(UWSGI_GID) --build-arg DOCKER_DIR=$(DOCKER_DIR) -t $(MAINTAINER)/$(TAG):$(VER)-dev --rm -f $(DOCKER_DIR)/build/Dockerfile . docker tag $(MAINTAINER)/$(TAG):$(VER)-dev $(MAINTAINER)/$(TAG):dev test: dev clean diff --git a/misc/contrib/docker/build/Dockerfile b/misc/contrib/docker/build/Dockerfile index f04174c7..7495877e 100644 --- a/misc/contrib/docker/build/Dockerfile +++ b/misc/contrib/docker/build/Dockerfile @@ -2,6 +2,7 @@ FROM debian:stable-slim LABEL maintainer="it@nkey.com.br" ARG BUILD=prod +ARG DOCKER_DIR=./misc/contrib/docker ARG uwsgi_uid=700 ARG uwsgi_gid=700 @@ -72,11 +73,11 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && rm -rf /var/lib/apt/lists/* # Copy helper files -COPY build/django/create-superuser.py /nsupdate/src/nsupdate/management/commands/create-superuser.py -COPY build/uwsgi.ini /nsupdate/uwsgi.ini -COPY build/confd/ /etc/confd/ -COPY build/setup.sh / -COPY build/docker-entrypoint.sh /var/local/ +COPY $DOCKER_DIR/build/django/create-superuser.py /nsupdate/src/nsupdate/management/commands/create-superuser.py +COPY $DOCKER_DIR/build/uwsgi.ini /nsupdate/uwsgi.ini +COPY $DOCKER_DIR/build/confd/ /etc/confd/ +COPY $DOCKER_DIR/build/setup.sh / +COPY $DOCKER_DIR/build/docker-entrypoint.sh /var/local/ # Set the permissions according to env options RUN chmod a+x /var/local/docker-entrypoint.sh From e5d3453299748d0ea334229b1937a2d2f0dec693 Mon Sep 17 00:00:00 2001 From: Paul Eipper Date: Mon, 30 Dec 2019 23:37:50 -0300 Subject: [PATCH 4/6] build(docker): simplify release action --- misc/contrib/docker/Makefile | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/misc/contrib/docker/Makefile b/misc/contrib/docker/Makefile index 81dc6e72..2f465e2e 100644 --- a/misc/contrib/docker/Makefile +++ b/misc/contrib/docker/Makefile @@ -12,19 +12,14 @@ prod: cd $(BASE_DIR); docker build --build-arg BUILD=prod --build-arg uwsgi_uid=$(UWSGI_UID) --build-arg uwsgi_gid=$(UWSGI_GID) --build-arg DOCKER_DIR=$(DOCKER_DIR) -t $(MAINTAINER)/$(TAG):$(VER) --rm -f $(DOCKER_DIR)/build/Dockerfile . docker tag $(MAINTAINER)/$(TAG):$(VER) $(MAINTAINER)/$(TAG):prod -release: +release: prod release_latest docker push $(MAINTAINER)/$(TAG):$(VER) - docker push $(MAINTAINER)/$(TAG):prod @echo "*** Don't forget to create a tag by creating an official GitHub release." release_latest: docker tag $(MAINTAINER)/$(TAG):$(VER) $(MAINTAINER)/$(TAG):latest docker push $(MAINTAINER)/$(TAG):latest -release_stable: - docker tag $(MAINTAINER)/$(TAG):$(VER) $(MAINTAINER)/$(TAG):stable - docker push $(MAINTAINER)/$(TAG):stable - dev: cd $(BASE_DIR); docker build --build-arg BUILD=dev --build-arg uwsgi_uid=$(UWSGI_UID) --build-arg uwsgi_gid=$(UWSGI_GID) --build-arg DOCKER_DIR=$(DOCKER_DIR) -t $(MAINTAINER)/$(TAG):$(VER)-dev --rm -f $(DOCKER_DIR)/build/Dockerfile . docker tag $(MAINTAINER)/$(TAG):$(VER)-dev $(MAINTAINER)/$(TAG):dev From a181c6d1497e9681ef4b6ade0c46d71c2d6f7853 Mon Sep 17 00:00:00 2001 From: Paul Eipper Date: Tue, 31 Dec 2019 00:03:42 -0300 Subject: [PATCH 5/6] build(docker): PEP8 fixes on build script --- .../docker/build/django/create-superuser.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/misc/contrib/docker/build/django/create-superuser.py b/misc/contrib/docker/build/django/create-superuser.py index a211e923..b4c69051 100644 --- a/misc/contrib/docker/build/django/create-superuser.py +++ b/misc/contrib/docker/build/django/create-superuser.py @@ -1,10 +1,11 @@ -# Title: create-superuser.py -# Link: https://gist.github.com/c00kiemon5ter/7806c1eac8c6a3e82f061ec32a55c702 +# Title: create-superuser.py +# Link: https://gist.github.com/c00kiemon5ter/7806c1eac8c6a3e82f061ec32a55c702 # License: None (Public Domain) from django.contrib.auth.management.commands import createsuperuser from django.core.management import CommandError + class Command(createsuperuser.Command): help = 'Create a superuser with a password non-interactively' @@ -28,12 +29,14 @@ def handle(self, *args, **options): if not password or not username or not email: raise CommandError( - "--username, --password, and --email are required options") + "--username, --password, and --email are required options") if username and options.get('preserve'): - exists = self.UserModel._default_manager.db_manager(database).filter(username=username).exists() + exists = self.UserModel._default_manager.db_manager( + database).filter(username=username).exists() if exists: - self.stdout.write("User exists, exiting normally due to --preserve") + self.stdout.write( + "User exists, exiting normally due to --preserve") return user_data = { @@ -43,7 +46,7 @@ def handle(self, *args, **options): } self.UserModel._default_manager.db_manager( - database).create_superuser(**user_data) + database).create_superuser(**user_data) if options.get('verbosity', 0) >= 1: self.stdout.write("Superuser created successfully.") From 685b5bd0b54c68343a70225ac4056a79b3abcf48 Mon Sep 17 00:00:00 2001 From: Paul Eipper Date: Fri, 3 Jan 2020 17:19:00 -0300 Subject: [PATCH 6/6] build(docker): require git tag for release Other small fixes for code review. --- misc/contrib/docker/.dockerignore | 7 ------- misc/contrib/docker/Makefile | 9 +++++++-- .../docker/build/confd/templates/local_settings.tmpl | 2 +- misc/contrib/docker/build/setup.sh | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) delete mode 100644 misc/contrib/docker/.dockerignore diff --git a/misc/contrib/docker/.dockerignore b/misc/contrib/docker/.dockerignore deleted file mode 100644 index da6727ed..00000000 --- a/misc/contrib/docker/.dockerignore +++ /dev/null @@ -1,7 +0,0 @@ -.tx/ -docs/ -logo/ -scripts/ -.coveragerc -.travis.yml -Makefile diff --git a/misc/contrib/docker/Makefile b/misc/contrib/docker/Makefile index 2f465e2e..a6547bc7 100644 --- a/misc/contrib/docker/Makefile +++ b/misc/contrib/docker/Makefile @@ -12,14 +12,19 @@ prod: cd $(BASE_DIR); docker build --build-arg BUILD=prod --build-arg uwsgi_uid=$(UWSGI_UID) --build-arg uwsgi_gid=$(UWSGI_GID) --build-arg DOCKER_DIR=$(DOCKER_DIR) -t $(MAINTAINER)/$(TAG):$(VER) --rm -f $(DOCKER_DIR)/build/Dockerfile . docker tag $(MAINTAINER)/$(TAG):$(VER) $(MAINTAINER)/$(TAG):prod -release: prod release_latest +release: require_tag prod release_latest docker push $(MAINTAINER)/$(TAG):$(VER) - @echo "*** Don't forget to create a tag by creating an official GitHub release." release_latest: docker tag $(MAINTAINER)/$(TAG):$(VER) $(MAINTAINER)/$(TAG):latest docker push $(MAINTAINER)/$(TAG):latest +require_tag: + @if ! git describe --exact-match; then\ + echo " *** Don't forget to create a tag by creating an official GitHub release.";\ + exit 1;\ + fi + dev: cd $(BASE_DIR); docker build --build-arg BUILD=dev --build-arg uwsgi_uid=$(UWSGI_UID) --build-arg uwsgi_gid=$(UWSGI_GID) --build-arg DOCKER_DIR=$(DOCKER_DIR) -t $(MAINTAINER)/$(TAG):$(VER)-dev --rm -f $(DOCKER_DIR)/build/Dockerfile . docker tag $(MAINTAINER)/$(TAG):$(VER)-dev $(MAINTAINER)/$(TAG):dev diff --git a/misc/contrib/docker/build/confd/templates/local_settings.tmpl b/misc/contrib/docker/build/confd/templates/local_settings.tmpl index ff9a751e..a64e0fd1 100644 --- a/misc/contrib/docker/build/confd/templates/local_settings.tmpl +++ b/misc/contrib/docker/build/confd/templates/local_settings.tmpl @@ -16,7 +16,7 @@ ALLOWED_HOSTS=['localhost', '127.0.0.1', '[::1]', '{{ getenv "BASEDOMAIN" }}'] {{ if getenv "DB_NAME"}} DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'ENGINE': 'django.db.backends.postgresql', 'NAME': '{{getenv "DB_NAME"}}', # database name 'USER': '{{getenv "DB_USER"}}', 'PASSWORD': '{{getenv "DB_PASS"}}', diff --git a/misc/contrib/docker/build/setup.sh b/misc/contrib/docker/build/setup.sh index f67510b6..7f2bbea1 100755 --- a/misc/contrib/docker/build/setup.sh +++ b/misc/contrib/docker/build/setup.sh @@ -1,6 +1,6 @@ #!/usr/bin/bash -#Quit on error. +# Quit on error. set -e # Treat undefined variables as errors. set -u