From 42621ace3a3e556ede7d547bca2c3dde55c3a328 Mon Sep 17 00:00:00 2001 From: heinzel Date: Sun, 14 Apr 2019 00:43:17 +0200 Subject: [PATCH] UPD: i like it now. --- Dockerfile | 25 ++++++++++---- Makefile | 16 +++++++-- README.rst | 21 +++++++----- .../etc/httpd/conf.d/django-test.conf | 18 ---------- container-files/docker-entrypoint.sh | 15 -------- container-filesystem/docker-entrypoint.sh | 10 ++++++ container-filesystem/etc/bashrc.local | 9 +++++ .../etc/httpd/conf.d/application.conf | 18 ++++++++++ .../etc/httpd/conf.d/defaults.conf | 0 .../etc/httpd/conf.d/welcome.conf | 0 .../etc/httpd/conf.d/wsgi.conf | 1 + .../etc/httpd/conf.d/zzz-lock-down.conf | 0 .../etc/httpd/conf.modules.d/00-base.conf | 0 .../etc/httpd/conf.modules.d/00-dav.conf | 0 .../etc/httpd/conf.modules.d/00-lua.conf | 0 .../etc/httpd/conf.modules.d/00-proxy.conf | 0 .../etc/httpd/conf.modules.d/10-h2.conf | 0 .../etc/httpd/conf.modules.d/10-proxy_h2.conf | 0 .../setup-application.sh | 21 ++++++++---- goss.yaml | 34 +++++++++++++++++++ 20 files changed, 131 insertions(+), 57 deletions(-) delete mode 100644 container-files/django-test-layer/etc/httpd/conf.d/django-test.conf delete mode 100755 container-files/docker-entrypoint.sh create mode 100755 container-filesystem/docker-entrypoint.sh create mode 100644 container-filesystem/etc/bashrc.local create mode 100644 container-filesystem/etc/httpd/conf.d/application.conf rename {container-files/httpd-layer => container-filesystem}/etc/httpd/conf.d/defaults.conf (100%) rename {container-files/httpd-layer => container-filesystem}/etc/httpd/conf.d/welcome.conf (100%) create mode 100644 container-filesystem/etc/httpd/conf.d/wsgi.conf rename {container-files/httpd-layer => container-filesystem}/etc/httpd/conf.d/zzz-lock-down.conf (100%) rename {container-files/httpd-layer => container-filesystem}/etc/httpd/conf.modules.d/00-base.conf (100%) rename {container-files/httpd-layer => container-filesystem}/etc/httpd/conf.modules.d/00-dav.conf (100%) rename {container-files/httpd-layer => container-filesystem}/etc/httpd/conf.modules.d/00-lua.conf (100%) rename {container-files/httpd-layer => container-filesystem}/etc/httpd/conf.modules.d/00-proxy.conf (100%) rename {container-files/httpd-layer => container-filesystem}/etc/httpd/conf.modules.d/10-h2.conf (100%) rename {container-files/httpd-layer => container-filesystem}/etc/httpd/conf.modules.d/10-proxy_h2.conf (100%) rename container-files/django-test-layer/srv/bin/setup-django-test.sh => container-filesystem/setup-application.sh (69%) create mode 100644 goss.yaml diff --git a/Dockerfile b/Dockerfile index f266c49..ef2216d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,33 @@ FROM fedora +LABEL maintainer="Jens Kleineheismann " + +ARG APPLICATION_NAME=django-test +ARG APPLICATION_SRC=src/${APPLICATION_NAME} + RUN dnf -y update && \ - dnf -y install procps-ng && \ + dnf -y install procps-ng iproute net-tools && \ dnf -y install httpd && \ dnf -y install python3-mod_wsgi && \ dnf clean all -COPY container-files/httpd-layer/ / +RUN chown apache: /etc/httpd/run && \ + setcap 'cap_net_bind_service=+ep' /usr/sbin/httpd && \ + sed -i -e 's:^\(\s.*\)\(CustomLog\s.*\)$:\1#\2:' \ + /etc/httpd/conf/httpd.conf -COPY src/django-test /srv/src/django-test -COPY container-files/django-test-layer/ / -RUN /srv/bin/setup-django-test.sh /srv/django-test /srv/src/django-test +COPY container-filesystem/ / +COPY $APPLICATION_SRC /srv/${APPLICATION_NAME}/src/${APPLICATION_NAME} -COPY container-files/docker-entrypoint.sh / +RUN ln -s ${APPLICATION_NAME} /srv/application && \ + /setup-application.sh /srv/${APPLICATION_NAME} \ + /srv/${APPLICATION_NAME}/src/${APPLICATION_NAME} && \ + rm /setup-application.sh EXPOSE 80/tcp +ENV LOG_LEVEL error + +USER apache ENTRYPOINT ["/docker-entrypoint.sh"] CMD ["--"] diff --git a/Makefile b/Makefile index cb66955..a6a9a5a 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,14 @@ REPO_URL := https://heinzelwelt.de/vcs/python/django-test REPO_DIR := src/$(APPLICATION_NAME) IMAGE_NAME := $(APPLICATION_NAME) +HOST_PORT := 80 +CONTAINER_PORT := 80 + DOCKER := docker +DGOSS := dgoss GIT := git -.PHONY: default help image test-run dist-clean +.PHONY: default help image test test-run dist-clean default: image @@ -17,12 +21,18 @@ $(REPO_DIR): $(GIT) clone $(REPO_URL) $@ $(IMAGE_NAME): $(REPO_DIR) - $(DOCKER) build -t $(IMAGE_NAME) . + $(DOCKER) build --build-arg APPLICATION_NAME=$(APPLICATION_NAME) -t $(IMAGE_NAME) . image: $(IMAGE_NAME) +test: + $(DGOSS) run $(IMAGE_NAME) + test-run: - $(DOCKER) run -ti --rm -p 80:80 $(IMAGE_NAME) + $(DOCKER) run -ti --rm -p $(HOST_PORT):$(CONTAINER_PORT) $(IMAGE_NAME) + +enter: + $(DOCKER) run -ti --rm -p $(HOST_PORT):$(CONTAINER_PORT) --entrypoint /bin/bash $(IMAGE_NAME) dist-clean: -rm -rf $(REPO_DIR) diff --git a/README.rst b/README.rst index e6e2eea..53ad9f3 100644 --- a/README.rst +++ b/README.rst @@ -3,10 +3,15 @@ ABOUT Docker container for django-test. +AUTHOR +====== +Jens Kleineheismann + + DESCRIPTION =========== -The django-heinzel docker image is derivated from -Fedora image (https://hub.docker.com/_/fedora). +This docker image is derivated from the official Fedora image +(https://hub.docker.com/_/fedora). It will contain and run @@ -18,16 +23,18 @@ It will contain and run BUILD ===== - ``make`` +- ``make test`` or alternatively the *long* way: - ``git clone https://heinzelwelt.de/vcs/python/django-test src/django-test`` -- ``docker build -t IMAGE_NAME .`` +- ``docker build -t django-test .`` +- ``dgoss run django-test`` USAGE ===== -- ``docker run -d -p 80:80 -e SERVER_ADMIN=heinzel@heinzelwelt.de IMAGE_NAME`` +- ``docker run -d -p 80:80 django-test`` The httpd process is listening on port 80/tcp. @@ -37,16 +44,14 @@ obtained with ``docker logs`` CONFIGURATION ============= -The following **environment variables** are supported: +The following **environment variables** are supported and +can be set with the -e option of the ``docker run`` command: - LOG_LEVEL (default: error) -- to set the httpd LogLevel directive -- SERVER_ADMIN (default: root@localhost) - -- to set the httpd ServerAdmin directive LICENCE ======= Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. - diff --git a/container-files/django-test-layer/etc/httpd/conf.d/django-test.conf b/container-files/django-test-layer/etc/httpd/conf.d/django-test.conf deleted file mode 100644 index 22961db..0000000 --- a/container-files/django-test-layer/etc/httpd/conf.d/django-test.conf +++ /dev/null @@ -1,18 +0,0 @@ -WSGIDaemonProcess django-test display-name=django-test python-home=/srv/django-test/python python-path=/srv/django-test/django - -Alias /static/ "/srv/django-test/django/var/www/static/" - - AllowOverride None - Require all granted - - -WSGIScriptAlias / "/srv/django-test/django/main/wsgi.py" - - WSGIProcessGroup django-test - WSGIPassAuthorization On - AllowOverride None - Options FollowSymLinks - - Require all granted - - diff --git a/container-files/docker-entrypoint.sh b/container-files/docker-entrypoint.sh deleted file mode 100755 index ee903d6..0000000 --- a/container-files/docker-entrypoint.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -DEFAULT_LOG_LEVEL="error" - -# Disable CustomLog, that is configured by default in upstream. -sed -i -e 's:^\(\s*\)\(CustomLog\s\s*"logs/access_log"\):\1# Disabled by /docker-entrypoint.sh # \2:' \ - /etc/httpd/conf/httpd.conf - -# Remove left-overs from an incomplete shutdown previously. -rm -rf /run/httpd/* /tmp/httpd* - -if test "X${SERVER_ADMIN}" != "X" ; then - set -- -c "ServerAdmin $SERVER_ADMIN" "$@" -fi -set -- -c "LogLevel ${LOG_LEVEL:-${DEFAULT_LOG_LEVEL}}" "$@" -exec /usr/sbin/httpd -DFOREGROUND "$@" diff --git a/container-filesystem/docker-entrypoint.sh b/container-filesystem/docker-entrypoint.sh new file mode 100755 index 0000000..7f7e719 --- /dev/null +++ b/container-filesystem/docker-entrypoint.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +# Remove left-overs from an incomplete shutdown previously. +rm -rf /run/httpd/* /tmp/httpd* + +exec /usr/sbin/httpd \ + -DFOREGROUND \ + -c "LogLevel ${LOG_LEVEL:-error}" \ + -c "ServerName ${HOSTNAME}" \ + "$@" diff --git a/container-filesystem/etc/bashrc.local b/container-filesystem/etc/bashrc.local new file mode 100644 index 0000000..e5993f9 --- /dev/null +++ b/container-filesystem/etc/bashrc.local @@ -0,0 +1,9 @@ +# /etc/bashrc.local + +PS1='\u@\w/ \$ ' +export PS1 + +alias ls="ls -F --color" +alias l="ls -ahl" + +#end diff --git a/container-filesystem/etc/httpd/conf.d/application.conf b/container-filesystem/etc/httpd/conf.d/application.conf new file mode 100644 index 0000000..4614c6f --- /dev/null +++ b/container-filesystem/etc/httpd/conf.d/application.conf @@ -0,0 +1,18 @@ +WSGIDaemonProcess wsgi-daemon display-name=wsgi-daemon python-home=/srv/application/python python-path=/srv/application/django + +Alias /static/ "/srv/application/django/var/www/static/" + + AllowOverride None + Require all granted + + +WSGIScriptAlias / "/srv/application/django/main/wsgi.py" + + WSGIProcessGroup wsgi-daemon + WSGIPassAuthorization On + AllowOverride None + Options FollowSymLinks + + Require all granted + + diff --git a/container-files/httpd-layer/etc/httpd/conf.d/defaults.conf b/container-filesystem/etc/httpd/conf.d/defaults.conf similarity index 100% rename from container-files/httpd-layer/etc/httpd/conf.d/defaults.conf rename to container-filesystem/etc/httpd/conf.d/defaults.conf diff --git a/container-files/httpd-layer/etc/httpd/conf.d/welcome.conf b/container-filesystem/etc/httpd/conf.d/welcome.conf similarity index 100% rename from container-files/httpd-layer/etc/httpd/conf.d/welcome.conf rename to container-filesystem/etc/httpd/conf.d/welcome.conf diff --git a/container-filesystem/etc/httpd/conf.d/wsgi.conf b/container-filesystem/etc/httpd/conf.d/wsgi.conf new file mode 100644 index 0000000..bc0e4cb --- /dev/null +++ b/container-filesystem/etc/httpd/conf.d/wsgi.conf @@ -0,0 +1 @@ +WSGISocketPrefix run/wsgi diff --git a/container-files/httpd-layer/etc/httpd/conf.d/zzz-lock-down.conf b/container-filesystem/etc/httpd/conf.d/zzz-lock-down.conf similarity index 100% rename from container-files/httpd-layer/etc/httpd/conf.d/zzz-lock-down.conf rename to container-filesystem/etc/httpd/conf.d/zzz-lock-down.conf diff --git a/container-files/httpd-layer/etc/httpd/conf.modules.d/00-base.conf b/container-filesystem/etc/httpd/conf.modules.d/00-base.conf similarity index 100% rename from container-files/httpd-layer/etc/httpd/conf.modules.d/00-base.conf rename to container-filesystem/etc/httpd/conf.modules.d/00-base.conf diff --git a/container-files/httpd-layer/etc/httpd/conf.modules.d/00-dav.conf b/container-filesystem/etc/httpd/conf.modules.d/00-dav.conf similarity index 100% rename from container-files/httpd-layer/etc/httpd/conf.modules.d/00-dav.conf rename to container-filesystem/etc/httpd/conf.modules.d/00-dav.conf diff --git a/container-files/httpd-layer/etc/httpd/conf.modules.d/00-lua.conf b/container-filesystem/etc/httpd/conf.modules.d/00-lua.conf similarity index 100% rename from container-files/httpd-layer/etc/httpd/conf.modules.d/00-lua.conf rename to container-filesystem/etc/httpd/conf.modules.d/00-lua.conf diff --git a/container-files/httpd-layer/etc/httpd/conf.modules.d/00-proxy.conf b/container-filesystem/etc/httpd/conf.modules.d/00-proxy.conf similarity index 100% rename from container-files/httpd-layer/etc/httpd/conf.modules.d/00-proxy.conf rename to container-filesystem/etc/httpd/conf.modules.d/00-proxy.conf diff --git a/container-files/httpd-layer/etc/httpd/conf.modules.d/10-h2.conf b/container-filesystem/etc/httpd/conf.modules.d/10-h2.conf similarity index 100% rename from container-files/httpd-layer/etc/httpd/conf.modules.d/10-h2.conf rename to container-filesystem/etc/httpd/conf.modules.d/10-h2.conf diff --git a/container-files/httpd-layer/etc/httpd/conf.modules.d/10-proxy_h2.conf b/container-filesystem/etc/httpd/conf.modules.d/10-proxy_h2.conf similarity index 100% rename from container-files/httpd-layer/etc/httpd/conf.modules.d/10-proxy_h2.conf rename to container-filesystem/etc/httpd/conf.modules.d/10-proxy_h2.conf diff --git a/container-files/django-test-layer/srv/bin/setup-django-test.sh b/container-filesystem/setup-application.sh similarity index 69% rename from container-files/django-test-layer/srv/bin/setup-django-test.sh rename to container-filesystem/setup-application.sh index 55a5910..3d15cc3 100755 --- a/container-files/django-test-layer/srv/bin/setup-django-test.sh +++ b/container-filesystem/setup-application.sh @@ -1,18 +1,14 @@ #!/bin/sh ### config ### -PROJECT_NAME="django-test" +PROJECT_REPO="git+https://heinzelwelt.de/vcs/python/django-test" SETUP_COMMAND="django-test-admin" -INSTALL_DIR="/srv/${PROJECT_NAME}" +INSTALL_DIR="${HOME}" VENV_DIR="python" -VENV_PATH="${INSTALL_DIR}/${VENV_DIR}" DJANGO_DIR="django" -DJANGO_PATH="${INSTALL_DIR}/${DJANGO_DIR}" DJANGO_MAIN_MODULE="main" -PROJECT_REPO="git+https://heinzelwelt.de/vcs/python/django-test" - ### argv ### if test "$1" != "" ; then if test "$1" != "-" ; then @@ -27,19 +23,30 @@ if test "$1" != "" ; then shift fi +VENV_PATH="${INSTALL_DIR}/${VENV_DIR}" +DJANGO_PATH="${INSTALL_DIR}/${DJANGO_DIR}" +DJANGO_SETTINGS_FILE="${DJANGO_PATH}/${DJANGO_MAIN_MODULE}/settings.py" + ### action ### +echo "Setup application in $INSTALL_DIR" mkdir -p "$INSTALL_DIR" +echo "Setup python environment" python3 -m venv "${VENV_PATH}" source "${VENV_PATH}/bin/activate" pip install --upgrade pip +echo "Install application from $PROJECT_REPO" pip install "$PROJECT_REPO" +echo "Setup django project" $SETUP_COMMAND setup "${DJANGO_PATH}" +echo "Collect static files" python3 "${DJANGO_PATH}/manage.py" collectstatic --noinput -cat <> "${DJANGO_PATH}/${DJANGO_MAIN_MODULE}/settings.py" +echo "Disable DEBUG mode" +cat <> "$DJANGO_SETTINGS_FILE" ALLOWED_HOSTS = ['*'] DEBUG = False E-O-H +echo "Done" ### end ### diff --git a/goss.yaml b/goss.yaml new file mode 100644 index 0000000..ee23036 --- /dev/null +++ b/goss.yaml @@ -0,0 +1,34 @@ +command: + /usr/sbin/httpd -t: + exit-status: 0 + ps axo cmd | grep -q [w]sgi-daemon: + exit-status: 0 +file: + /run/httpd: + exists: true + mode: "0710" + owner: apache + group: apache + filetype: directory + /srv/application/django/main/wsgi.py: + exists: true + mode: "0644" + owner: root + group: root + filetype: file +package: + httpd: + installed: true + python3-mod_wsgi: + installed: true +port: + tcp6:80: + listening: true + ip: + - '::' +process: + httpd: + running: true +http: + http://localhost: + status: 200