From 9cb987826aca3846674f13f8955aa64abc7ffa9c Mon Sep 17 00:00:00 2001 From: cytopia Date: Sun, 27 Mar 2022 23:15:48 +0200 Subject: [PATCH] Add Alpine Docker flavour --- .github/workflows/action_branch.yml | 2 +- .github/workflows/action_pull_request.yml | 2 +- .github/workflows/action_schedule.yml | 2 +- .github/workflows/params.yml | 7 + Dockerfiles/Dockerfile.alpine | 218 ++++++++++++++++++ Dockerfile => Dockerfiles/Dockerfile.debian | 0 Dockerfiles/Dockerfile.latest | 1 + {data => Dockerfiles/data}/create-vhost.sh | 0 .../data}/docker-entrypoint.d/00-base-libs.sh | 0 .../data}/docker-entrypoint.d/01-uid-gid.sh | 0 .../data}/docker-entrypoint.d/02-timezone.sh | 0 .../docker-entrypoint.d/03-docker-logs.sh | 0 .../data}/docker-entrypoint.d/04-php-fpm.sh | 0 .../docker-entrypoint.d/05-main-vhost.sh | 0 .../docker-entrypoint.d/06-mass-vhost.sh | 0 .../data}/docker-entrypoint.d/07-vhost-gen.sh | 0 .../data}/docker-entrypoint.d/08-cert-gen.sh | 0 .../docker-entrypoint.d/09-fix-permissions.sh | 0 .../docker-entrypoint.d/10-supervisord.sh | 0 .../data}/docker-entrypoint.sh | 0 {data => Dockerfiles/data}/vhost-gen/main.yml | 0 {data => Dockerfiles/data}/vhost-gen/mass.yml | 0 Makefile | 15 +- README.md | 3 +- tests/00.sh | 11 +- 25 files changed, 251 insertions(+), 10 deletions(-) create mode 100644 Dockerfiles/Dockerfile.alpine rename Dockerfile => Dockerfiles/Dockerfile.debian (100%) create mode 120000 Dockerfiles/Dockerfile.latest rename {data => Dockerfiles/data}/create-vhost.sh (100%) rename {data => Dockerfiles/data}/docker-entrypoint.d/00-base-libs.sh (100%) rename {data => Dockerfiles/data}/docker-entrypoint.d/01-uid-gid.sh (100%) rename {data => Dockerfiles/data}/docker-entrypoint.d/02-timezone.sh (100%) rename {data => Dockerfiles/data}/docker-entrypoint.d/03-docker-logs.sh (100%) rename {data => Dockerfiles/data}/docker-entrypoint.d/04-php-fpm.sh (100%) rename {data => Dockerfiles/data}/docker-entrypoint.d/05-main-vhost.sh (100%) rename {data => Dockerfiles/data}/docker-entrypoint.d/06-mass-vhost.sh (100%) rename {data => Dockerfiles/data}/docker-entrypoint.d/07-vhost-gen.sh (100%) rename {data => Dockerfiles/data}/docker-entrypoint.d/08-cert-gen.sh (100%) rename {data => Dockerfiles/data}/docker-entrypoint.d/09-fix-permissions.sh (100%) rename {data => Dockerfiles/data}/docker-entrypoint.d/10-supervisord.sh (100%) rename {data => Dockerfiles/data}/docker-entrypoint.sh (100%) rename {data => Dockerfiles/data}/vhost-gen/main.yml (100%) rename {data => Dockerfiles/data}/vhost-gen/mass.yml (100%) diff --git a/.github/workflows/action_branch.yml b/.github/workflows/action_branch.yml index 55d6950..3197415 100644 --- a/.github/workflows/action_branch.yml +++ b/.github/workflows/action_branch.yml @@ -22,7 +22,7 @@ jobs: # (2/2) Build docker: needs: [params] - uses: devilbox/github-actions/.github/workflows/docker-name-version-arch.yml@master + uses: devilbox/github-actions/.github/workflows/docker-name-version-flavour-arch.yml@master with: enabled: true can_deploy: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/heads/release-') }} diff --git a/.github/workflows/action_pull_request.yml b/.github/workflows/action_pull_request.yml index c80bf78..21b075b 100644 --- a/.github/workflows/action_pull_request.yml +++ b/.github/workflows/action_pull_request.yml @@ -24,7 +24,7 @@ jobs: # (2/2) Build docker: needs: [params] - uses: devilbox/github-actions/.github/workflows/docker-name-version-arch.yml@master + uses: devilbox/github-actions/.github/workflows/docker-name-version-flavour-arch.yml@master with: enabled: true can_deploy: false diff --git a/.github/workflows/action_schedule.yml b/.github/workflows/action_schedule.yml index 36d979a..c25dfa2 100644 --- a/.github/workflows/action_schedule.yml +++ b/.github/workflows/action_schedule.yml @@ -24,7 +24,7 @@ jobs: # (2/2) Build docker: needs: [params] - uses: devilbox/github-actions/.github/workflows/docker-name-version-arch.yml@master + uses: devilbox/github-actions/.github/workflows/docker-name-version-flavour-arch.yml@master with: enabled: true can_deploy: true diff --git a/.github/workflows/params.yml b/.github/workflows/params.yml index 62d7923..102172f 100644 --- a/.github/workflows/params.yml +++ b/.github/workflows/params.yml @@ -15,7 +15,14 @@ env: { "NAME": "Apache", "VERSION": ["2.2"], + "FLAVOUR": ["latest", "debian"], "ARCH": ["linux/amd64", "linux/386", "linux/arm64", "linux/arm/v7", "linux/arm/v6"] + }, + { + "NAME": "Apache", + "VERSION": ["2.2"], + "FLAVOUR": ["alpine"], + "ARCH": ["linux/amd64"] } ] diff --git a/Dockerfiles/Dockerfile.alpine b/Dockerfiles/Dockerfile.alpine new file mode 100644 index 0000000..1165493 --- /dev/null +++ b/Dockerfiles/Dockerfile.alpine @@ -0,0 +1,218 @@ +FROM alpine:3.5 as builder + +RUN set -eux \ + && apk add -U shadow + + +FROM httpd:2.2-alpine +MAINTAINER "cytopia" + +LABEL \ + name="cytopia's apache 2.2 image" \ + image="devilbox/apache-2.2" \ + vendor="devilbox" \ + license="MIT" + + +### +### Build arguments +### +ARG VHOST_GEN_GIT_REF=1.0.3 +ARG WATCHERD_GIT_REF=v1.0.2 +ARG CERT_GEN_GIT_REF=0.7 +ARG ARCH + +ENV BUILD_DEPS \ + autoconf \ + gcc \ + musl-dev \ + make \ + wget + +ENV RUN_DEPS \ + ca-certificates \ + bash \ + openssl \ + py-yaml \ + supervisor + + +### +### Runtime arguments +### +ENV MY_USER=daemon +ENV MY_GROUP=daemon +ENV HTTPD_START="httpd-foreground" +ENV HTTPD_RELOAD="/usr/local/apache2/bin/httpd -k stop" + +### +### Install required packages +### +RUN set -eux \ + && apk add -U \ + ${BUILD_DEPS} \ + ${RUN_DEPS} \ + \ + # Required symlinks to build mod-proxy-fcgi on i386 + && if [ "${ARCH}" = "linux/386" ]; then \ + ln -s $(which ar) /usr/bin/i586-linux-gnu-ar; \ + ln -s $(which ranlib) /usr/bin/i586-linux-gnu-ranlib ; \ + fi \ + \ + # mod-proxy-fcgi + && wget --no-check-certificate -O mod-proxy-fcgi.tar.gz https://github.com/devilbox/mod-proxy-fcgi/archive/master.tar.gz \ + && tar xvfz mod-proxy-fcgi.tar.gz \ + && cd mod-proxy-fcgi-master \ + && autoconf \ + && ./configure \ + && make \ + && make install \ + && cd .. \ + && rm -rf mod-proxy-fcgi* \ + \ + # Install vhost-gen + && wget --no-check-certificate -O vhost-gen.tar.gz "https://github.com/devilbox/vhost-gen/archive/refs/tags/${VHOST_GEN_GIT_REF}.tar.gz" \ + && tar xvfz vhost-gen.tar.gz \ + && cd "vhost-gen-${VHOST_GEN_GIT_REF}" \ + && make install \ + && cd .. \ + && rm -rf vhost*gen* \ + \ + # Install cert-gen + && wget --no-check-certificate -O /usr/bin/ca-gen https://raw.githubusercontent.com/devilbox/cert-gen/${CERT_GEN_GIT_REF}/bin/ca-gen \ + && wget --no-check-certificate -O /usr/bin/cert-gen https://raw.githubusercontent.com/devilbox/cert-gen/${CERT_GEN_GIT_REF}/bin/cert-gen \ + && chmod +x /usr/bin/ca-gen \ + && chmod +x /usr/bin/cert-gen \ + \ + # Install watcherd + && wget --no-check-certificate -O /usr/bin/watcherd https://raw.githubusercontent.com/devilbox/watcherd/${WATCHERD_GIT_REF}/watcherd \ + && chmod +x /usr/bin/watcherd \ + \ + # Clean-up + && apk del \ + ${BUILD_DEPS} + + +### +### Configure Apache +### +RUN set -eux \ + && ( \ + echo "ServerName localhost"; \ + echo "LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so"; \ + echo "NameVirtualHost *:80"; \ + echo "Include conf/extra/httpd-default.conf"; \ + echo "Include /etc/httpd-custom.d/*.conf"; \ + echo "Include /etc/httpd/conf.d/*.conf"; \ + echo "Include /etc/httpd/vhost.d/*.conf"; \ + \ + #echo "LoadModule ssl_module modules/mod_ssl.so"; \ + echo "Listen 443"; \ + echo "NameVirtualHost *:443"; \ + echo "SSLCipherSuite HIGH:MEDIUM:!MD5:!RC4:!3DES"; \ + echo "SSLProxyCipherSuite HIGH:MEDIUM:!MD5:!RC4:!3DES"; \ + echo "SSLHonorCipherOrder on"; \ + echo "SSLProtocol all -SSLv2 -SSLv3"; \ + echo "SSLProxyProtocol all -SSLv2 -SSLv3"; \ + echo "SSLPassPhraseDialog builtin"; \ + echo "SSLSessionCache \"shmcb:/usr/local/apache2/logs/ssl_scache(512000)\""; \ + echo "SSLSessionCacheTimeout 300"; \ + echo "SSLMutex \"file:/usr/local/apache2/logs/ssl_mutex\""; \ + \ + echo "HTTPProtocolOptions unsafe"; \ + ) >> /usr/local/apache2/conf/httpd.conf + + +### +### Create directories +### +RUN set -eux \ + && mkdir -p /etc/httpd-custom.d \ + && mkdir -p /etc/httpd/conf.d \ + && mkdir -p /etc/httpd/vhost.d \ + && mkdir -p /var/www/default/htdocs \ + && mkdir -p /shared/httpd \ + && chmod 0775 /shared/httpd \ + && chown ${MY_USER}:${MY_GROUP} /shared/httpd + + +### +### Copy files +### +COPY ./data/vhost-gen/main.yml /etc/vhost-gen/main.yml +COPY ./data/vhost-gen/mass.yml /etc/vhost-gen/mass.yml +COPY ./data/create-vhost.sh /usr/local/bin/create-vhost.sh +COPY ./data/docker-entrypoint.d /docker-entrypoint.d +COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh + + +### +### Backporting from Alpine 3.5 +### +# Required for usermod and groupmod +COPY --from=builder /etc/pam.d /etc/pam.d +COPY --from=builder /etc/security /etc/security +COPY --from=builder /etc/login.defs /etc/login.defs + +COPY --from=builder /lib/security /lib/security +COPY --from=builder /lib/libpam.so.0 /lib/libpam.so.0 +COPY --from=builder /lib/libpam.so.0.84.1 /lib/libpam.so.0.84.1 +COPY --from=builder /lib/libpam_misc.so.0 /lib/libpam_misc.so.0 +COPY --from=builder /lib/libpam_misc.so.0.82.1 /lib/libpam_misc.so.0.82.1 +COPY --from=builder /lib/libpamc.so.0 /lib/libpamc.so.0 +COPY --from=builder /lib/libpamc.so.0.82.1 /lib/libpamc.so.0.82.1 + +#COPY --from=builder /usr/bin/faillog /usr/bin/faillog +#COPY --from=builder /usr/bin/gpasswd /usr/bin/gpasswd +#COPY --from=builder /usr/bin/sg /usr/bin/sg +#COPY --from=builder /usr/bin/chfn /usr/bin/chfn +#COPY --from=builder /usr/bin/newgrp /usr/bin/newgrp +#COPY --from=builder /usr/bin/chsh /usr/bin/chsh +#COPY --from=builder /usr/bin/lastlog /usr/bin/lastlog +#COPY --from=builder /usr/bin/chage /usr/bin/chage +#COPY --from=builder /usr/bin/expiry /usr/bin/expiry +#COPY --from=builder /usr/sbin/newusers /usr/sbin/newusers +#COPY --from=builder /usr/sbin/pwconv /usr/sbin/pwconv +#COPY --from=builder /usr/sbin/groupmems /usr/sbin/groupmems +#COPY --from=builder /usr/sbin/vipw /usr/sbin/vipw +COPY --from=builder /usr/sbin/usermod /usr/sbin/usermod +#COPY --from=builder /usr/sbin/grpconv /usr/sbin/grpconv +#COPY --from=builder /usr/sbin/useradd /usr/sbin/useradd +COPY --from=builder /usr/sbin/groupmod /usr/sbin/groupmod +#COPY --from=builder /usr/sbin/grpck /usr/sbin/grpck +#COPY --from=builder /usr/sbin/userdel /usr/sbin/userdel +#COPY --from=builder /usr/sbin/groupdel /usr/sbin/groupdel +#COPY --from=builder /usr/sbin/pwck /usr/sbin/pwck +#COPY --from=builder /usr/sbin/pwunconv /usr/sbin/pwunconv +#COPY --from=builder /usr/sbin/chgpasswd /usr/sbin/chgpasswd +#COPY --from=builder /usr/sbin/logoutd /usr/sbin/logoutd +#COPY --from=builder /usr/sbin/grpunconv /usr/sbin/grpunconv +#COPY --from=builder /usr/sbin/vigr /usr/sbin/vigr +#COPY --from=builder /usr/sbin/groupadd /usr/sbin/groupadd +#COPY --from=builder /bin/groups /bin/groups + + +### +### Ports +### +EXPOSE 80 +EXPOSE 443 + + +### +### Volumes +### +VOLUME /shared/httpd +VOLUME /ca + + +### +### Signals +### +STOPSIGNAL SIGTERM + + +### +### Entrypoint +### +ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/Dockerfile b/Dockerfiles/Dockerfile.debian similarity index 100% rename from Dockerfile rename to Dockerfiles/Dockerfile.debian diff --git a/Dockerfiles/Dockerfile.latest b/Dockerfiles/Dockerfile.latest new file mode 120000 index 0000000..d537b9a --- /dev/null +++ b/Dockerfiles/Dockerfile.latest @@ -0,0 +1 @@ +Dockerfile.debian \ No newline at end of file diff --git a/data/create-vhost.sh b/Dockerfiles/data/create-vhost.sh similarity index 100% rename from data/create-vhost.sh rename to Dockerfiles/data/create-vhost.sh diff --git a/data/docker-entrypoint.d/00-base-libs.sh b/Dockerfiles/data/docker-entrypoint.d/00-base-libs.sh similarity index 100% rename from data/docker-entrypoint.d/00-base-libs.sh rename to Dockerfiles/data/docker-entrypoint.d/00-base-libs.sh diff --git a/data/docker-entrypoint.d/01-uid-gid.sh b/Dockerfiles/data/docker-entrypoint.d/01-uid-gid.sh similarity index 100% rename from data/docker-entrypoint.d/01-uid-gid.sh rename to Dockerfiles/data/docker-entrypoint.d/01-uid-gid.sh diff --git a/data/docker-entrypoint.d/02-timezone.sh b/Dockerfiles/data/docker-entrypoint.d/02-timezone.sh similarity index 100% rename from data/docker-entrypoint.d/02-timezone.sh rename to Dockerfiles/data/docker-entrypoint.d/02-timezone.sh diff --git a/data/docker-entrypoint.d/03-docker-logs.sh b/Dockerfiles/data/docker-entrypoint.d/03-docker-logs.sh similarity index 100% rename from data/docker-entrypoint.d/03-docker-logs.sh rename to Dockerfiles/data/docker-entrypoint.d/03-docker-logs.sh diff --git a/data/docker-entrypoint.d/04-php-fpm.sh b/Dockerfiles/data/docker-entrypoint.d/04-php-fpm.sh similarity index 100% rename from data/docker-entrypoint.d/04-php-fpm.sh rename to Dockerfiles/data/docker-entrypoint.d/04-php-fpm.sh diff --git a/data/docker-entrypoint.d/05-main-vhost.sh b/Dockerfiles/data/docker-entrypoint.d/05-main-vhost.sh similarity index 100% rename from data/docker-entrypoint.d/05-main-vhost.sh rename to Dockerfiles/data/docker-entrypoint.d/05-main-vhost.sh diff --git a/data/docker-entrypoint.d/06-mass-vhost.sh b/Dockerfiles/data/docker-entrypoint.d/06-mass-vhost.sh similarity index 100% rename from data/docker-entrypoint.d/06-mass-vhost.sh rename to Dockerfiles/data/docker-entrypoint.d/06-mass-vhost.sh diff --git a/data/docker-entrypoint.d/07-vhost-gen.sh b/Dockerfiles/data/docker-entrypoint.d/07-vhost-gen.sh similarity index 100% rename from data/docker-entrypoint.d/07-vhost-gen.sh rename to Dockerfiles/data/docker-entrypoint.d/07-vhost-gen.sh diff --git a/data/docker-entrypoint.d/08-cert-gen.sh b/Dockerfiles/data/docker-entrypoint.d/08-cert-gen.sh similarity index 100% rename from data/docker-entrypoint.d/08-cert-gen.sh rename to Dockerfiles/data/docker-entrypoint.d/08-cert-gen.sh diff --git a/data/docker-entrypoint.d/09-fix-permissions.sh b/Dockerfiles/data/docker-entrypoint.d/09-fix-permissions.sh similarity index 100% rename from data/docker-entrypoint.d/09-fix-permissions.sh rename to Dockerfiles/data/docker-entrypoint.d/09-fix-permissions.sh diff --git a/data/docker-entrypoint.d/10-supervisord.sh b/Dockerfiles/data/docker-entrypoint.d/10-supervisord.sh similarity index 100% rename from data/docker-entrypoint.d/10-supervisord.sh rename to Dockerfiles/data/docker-entrypoint.d/10-supervisord.sh diff --git a/data/docker-entrypoint.sh b/Dockerfiles/data/docker-entrypoint.sh similarity index 100% rename from data/docker-entrypoint.sh rename to Dockerfiles/data/docker-entrypoint.sh diff --git a/data/vhost-gen/main.yml b/Dockerfiles/data/vhost-gen/main.yml similarity index 100% rename from data/vhost-gen/main.yml rename to Dockerfiles/data/vhost-gen/main.yml diff --git a/data/vhost-gen/mass.yml b/Dockerfiles/data/vhost-gen/mass.yml similarity index 100% rename from data/vhost-gen/mass.yml rename to Dockerfiles/data/vhost-gen/mass.yml diff --git a/Makefile b/Makefile index fa32498..41374f6 100644 --- a/Makefile +++ b/Makefile @@ -27,9 +27,18 @@ TAG = latest NAME = Apache VERSION = 2.2 IMAGE = devilbox/apache-$(VERSION) -DIR = . -FILE = Dockerfile -DOCKER_TAG = $(TAG) +FLAVOUR = latest +DIR = Dockerfiles +FILE = Dockerfile.$(FLAVOUR) +ifeq ($(strip $(FLAVOUR)),latest) + DOCKER_TAG = $(TAG) +else + ifeq ($(strip $(TAG)),latest) + DOCKER_TAG = $(FLAVOUR) + else + DOCKER_TAG = $(FLAVOUR)-$(TAG) + endif +endif ARCH = linux/amd64 diff --git a/README.md b/README.md index 5d25c49..9b8e7b1 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,8 @@ **[devilbox/docker-apache-2.2](https://github.com/devilbox/docker-apache-2.2)** -**Available Architectures:** `amd64`, `arm64`, `386`, `arm/v7`, `arm/v6` +* **Available Architectures:** `amd64`, `arm64`, `386`, `arm/v7`, `arm/v6` +* **Available Docker tags:** `latest`, `alpine`, `debian` This image is based on the official **[Apache 2.2](https://hub.docker.com/_/httpd)** Docker image and extends it with the ability to have **virtual hosts created automatically**, as well as **adding SSL certificates** when creating new directories. For that to work, it integrates two tools that will take care about the whole process: **[watcherd](https://github.com/devilbox/watcherd)** and **[vhost-gen](https://github.com/devilbox/vhost-gen)**. diff --git a/tests/00.sh b/tests/00.sh index 8b16b08..84f1d3b 100755 --- a/tests/00.sh +++ b/tests/00.sh @@ -32,14 +32,14 @@ run "echo \"hello world\" > ${RAND_DIR}/index.html" ### ### Startup container ### -run "docker run -d --rm --platform ${ARCH} \ +run "docker run --platform ${ARCH} \ -v ${RAND_DIR}:/var/www/default/htdocs \ -p 127.0.0.1:80:80 \ -e DEBUG_ENTRYPOINT=2 \ -e DEBUG_RUNTIME=1 \ -e NEW_UID=$( id -u ) \ -e NEW_GID=$( id -g ) \ - --name ${RAND_NAME} ${IMAGE}:${TAG}" + --name ${RAND_NAME} ${IMAGE}:${TAG} &" ### @@ -47,12 +47,17 @@ run "docker run -d --rm --platform ${ARCH} \ ### run "sleep 20" # Startup-time is longer on cross-platform run "docker ps" -run "docker logs ${RAND_NAME}" +if ! run "docker logs ${RAND_NAME}"; then + run "docker stop ${RAND_NAME}" || true + exit 21 +fi if ! run "curl -sS localhost/index.html"; then + run "docker logs ${RAND_NAME}" || true run "docker stop ${RAND_NAME}" exit 1 fi if ! run "curl -sS localhost/index.html | grep 'hello world'"; then + run "docker logs ${RAND_NAME}" || true run "docker stop ${RAND_NAME}" exit 1 fi