From 4a4eb346ab9ff77c880bd5f0dd91ed46b0bcdb1e Mon Sep 17 00:00:00 2001 From: cytopia Date: Sat, 19 Mar 2022 08:43:32 +0100 Subject: [PATCH 1/6] Multi base image --- .github/workflows/action_branch.yml | 4 +- .github/workflows/action_pull_request.yml | 4 +- .github/workflows/action_schedule.yml | 4 +- ...l => docker-name-version-flavour-arch.yml} | 26 +++++------ .github/workflows/params.yml | 1 + Dockerfiles/Dockerfile.alpine | 43 +++++++++++++++++++ Dockerfile => Dockerfiles/Dockerfile.latest | 5 ++- Dockerfiles/Dockerfile.stable | 38 ++++++++++++++++ .../data}/docker-entrypoint.sh | 27 +++++++++--- Makefile | 15 +++++-- README.md | 15 +++++++ 11 files changed, 153 insertions(+), 29 deletions(-) rename .github/workflows/{docker-name-version-arch.yml => docker-name-version-flavour-arch.yml} (86%) create mode 100644 Dockerfiles/Dockerfile.alpine rename Dockerfile => Dockerfiles/Dockerfile.latest (95%) create mode 100644 Dockerfiles/Dockerfile.stable rename {data => Dockerfiles/data}/docker-entrypoint.sh (97%) diff --git a/.github/workflows/action_branch.yml b/.github/workflows/action_branch.yml index 9139bd9..9f205aa 100644 --- a/.github/workflows/action_branch.yml +++ b/.github/workflows/action_branch.yml @@ -22,8 +22,8 @@ jobs: # (2/2) Build docker: needs: [params] - #uses: devilbox/github-actions/.github/workflows/docker-name-version-arch.yml@master - uses: ./.github/workflows/docker-name-version-arch.yml + #uses: devilbox/github-actions/.github/workflows/docker-name-version-flavour-arch.yml@master + uses: ./.github/workflows/docker-name-version-flavour-arch.yml 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 8d86e44..cfad24f 100644 --- a/.github/workflows/action_pull_request.yml +++ b/.github/workflows/action_pull_request.yml @@ -24,8 +24,8 @@ jobs: # (2/2) Build docker: needs: [params] - #uses: devilbox/github-actions/.github/workflows/docker-name-version-arch.yml@master - uses: ./.github/workflows/docker-name-version-arch.yml + #uses: devilbox/github-actions/.github/workflows/docker-name-version-flavour-arch.yml@master + uses: ./.github/workflows/docker-name-version-flavour-arch.yml with: enabled: true can_deploy: false diff --git a/.github/workflows/action_schedule.yml b/.github/workflows/action_schedule.yml index d2b8c1e..c61e6b1 100644 --- a/.github/workflows/action_schedule.yml +++ b/.github/workflows/action_schedule.yml @@ -24,8 +24,8 @@ jobs: # (2/2) Build docker: needs: [params] - #uses: devilbox/github-actions/.github/workflows/docker-name-version-arch.yml@master - uses: ./.github/workflows/docker-name-version-arch.yml + #uses: devilbox/github-actions/.github/workflows/docker-name-version-flavour-arch.yml@master + uses: ./.github/workflows/docker-name-version-flavour-arch.yml with: enabled: true can_deploy: true diff --git a/.github/workflows/docker-name-version-arch.yml b/.github/workflows/docker-name-version-flavour-arch.yml similarity index 86% rename from .github/workflows/docker-name-version-arch.yml rename to .github/workflows/docker-name-version-flavour-arch.yml index 3eafa82..e117425 100644 --- a/.github/workflows/docker-name-version-arch.yml +++ b/.github/workflows/docker-name-version-flavour-arch.yml @@ -69,12 +69,12 @@ jobs: MATRIX_BUILD="$( \ jq -M -c \ --argjson refs '${{ inputs.refs }}' \ - 'map({name:.NAME, version:.VERSION[], arch:.ARCH[], refs:$refs[]})' <<<'${{ inputs.matrix }}' \ + 'map({name:.NAME, version:.VERSION[], flavour:.FLAVOUR[], arch:.ARCH[], refs:$refs[]})' <<<'${{ inputs.matrix }}' \ )" MATRIX_DEPLOY="$( \ jq -M -c \ --argjson refs '${{ inputs.refs }}' \ - 'map({name:.NAME, version:.VERSION[], refs:$refs[]})' <<<'${{ inputs.matrix }}' \ + 'map({name:.NAME, version:.VERSION[], flavour:.FLAVOUR[], refs:$refs[]})' <<<'${{ inputs.matrix }}' \ )" echo "::set-output name=matrix_build::${MATRIX_BUILD}" echo "::set-output name=matrix_deploy::${MATRIX_DEPLOY}" @@ -82,11 +82,11 @@ jobs: else MATRIX_BUILD="$( \ jq -M -c \ - 'map({name:.NAME, version:.VERSION[], arch:.ARCH[]})' <<<'${{ inputs.matrix }}' \ + 'map({name:.NAME, version:.VERSION[], flavour:.FLAVOUR[], arch:.ARCH[]})' <<<'${{ inputs.matrix }}' \ )" MATRIX_DEPLOY="$( \ jq -M -c \ - 'map({name:.NAME, version:.VERSION[]})' <<<'${{ inputs.matrix }}' \ + 'map({name:.NAME, version:.VERSION[], flavour:.FLAVOUR[]})' <<<'${{ inputs.matrix }}' \ )" echo "::set-output name=matrix_build::${MATRIX_BUILD}" echo "::set-output name=matrix_deploy::${MATRIX_DEPLOY}" @@ -114,7 +114,7 @@ jobs: # ----------------------------------------------------------------------------------------------- build: needs: [configure] - name: Build ${{ matrix.name }}-${{ matrix.version }} (${{ matrix.arch }}) ${{ matrix.refs }} + name: Build ${{ matrix.name }}-${{ matrix.version }} (${{ matrix.flavour }}) (${{ matrix.arch }}) ${{ matrix.refs }} runs-on: ubuntu-latest strategy: fail-fast: false @@ -155,7 +155,7 @@ jobs: uses: cytopia/shell-command-retry-action@v0.1.2 with: command: | - make build NAME=${{ matrix.name }} VERSION=${{ matrix.version }} ARCH=${{ matrix.arch }} TAG=${{ steps.tag.outputs.docker-tag }} + make build NAME=${{ matrix.name }} VERSION=${{ matrix.version }} FLAVOUR=${{ matrix.flavour }} ARCH=${{ matrix.arch }} TAG=${{ steps.tag.outputs.docker-tag }} # ------------------------------------------------------------ # Test @@ -164,7 +164,7 @@ jobs: uses: cytopia/shell-command-retry-action@v0.1.2 with: command: | - make test NAME=${{ matrix.name }} VERSION=${{ matrix.version }} ARCH=${{ matrix.arch }} TAG=${{ steps.tag.outputs.docker-tag }} + make test NAME=${{ matrix.name }} VERSION=${{ matrix.version }} FLAVOUR=${{ matrix.flavour }} ARCH=${{ matrix.arch }} TAG=${{ steps.tag.outputs.docker-tag }} # ------------------------------------------------------------ # Deploy @@ -180,7 +180,7 @@ jobs: uses: cytopia/shell-command-retry-action@v0.1.2 with: command: | - make push NAME=${{ matrix.name }} VERSION=${{ matrix.version }} ARCH=${{ matrix.arch }} TAG=${{ steps.tag.outputs.docker-tag }} + make push NAME=${{ matrix.name }} VERSION=${{ matrix.version }} FLAVOUR=${{ matrix.flavour }} ARCH=${{ matrix.arch }} TAG=${{ steps.tag.outputs.docker-tag }} if: needs.configure.outputs.can_login == 1 && inputs.can_deploy # ----------------------------------------------------------------------------------------------- @@ -188,7 +188,7 @@ jobs: # ----------------------------------------------------------------------------------------------- deploy: needs: [configure, build] - name: Deploy ${{ matrix.name }}-${{ matrix.version }} ${{ matrix.refs }} + name: Deploy ${{ matrix.name }}-${{ matrix.version }} (${{ matrix.flavour }}) ${{ matrix.refs }} runs-on: ubuntu-latest strategy: fail-fast: false @@ -221,8 +221,8 @@ jobs: run: | ARCHES="$( echo '${{ inputs.matrix }}' \ | jq 'group_by(.NAME, .VERSION, .ARCH)' \ - | jq 'map({NAME: .[].NAME, VERSION: .[].VERSION[], ARCHES: .[].ARCH|join(",")})' \ - | jq '.[] | select(.NAME=="${{ matrix.name }}" and .VERSION=="${{ matrix.version }}") | .ARCHES' \ + | jq 'map({NAME: .[].NAME, VERSION: .[].VERSION[], FLAVOUR: .[].FLAVOUR[], ARCHES: .[].ARCH|join(",")})' \ + | jq '.[] | select(.NAME=="${{ matrix.name }}" and .VERSION=="${{ matrix.version }}" and .FLAVOUR=="${{ matrix.flavour }}") | .ARCHES' \ | jq -c -M \ )" echo "::set-output name=arches::${ARCHES}" @@ -242,10 +242,10 @@ jobs: uses: cytopia/shell-command-retry-action@v0.1.2 with: command: | - make manifest-create NAME=${{ matrix.name }} VERSION=${{ matrix.version }} ARCHES=${{ steps.manifest.outputs.arches }} TAG=${{ steps.tag.outputs.docker-tag }} + make manifest-create NAME=${{ matrix.name }} VERSION=${{ matrix.version }} FLAVOUR=${{ matrix.flavour }} ARCHES=${{ steps.manifest.outputs.arches }} TAG=${{ steps.tag.outputs.docker-tag }} - name: "[DEPLOY] Publish Docker manifest: ${{ steps.tag.outputs.docker-tag }}" uses: cytopia/shell-command-retry-action@v0.1.2 with: command: | - make manifest-push NAME=${{ matrix.name }} VERSION=${{ matrix.version }} TAG=${{ steps.tag.outputs.docker-tag }} + make manifest-push NAME=${{ matrix.name }} VERSION=${{ matrix.version }} FLAVOUR=${{ matrix.flavour }} TAG=${{ steps.tag.outputs.docker-tag }} diff --git a/.github/workflows/params.yml b/.github/workflows/params.yml index b2820bc..246486f 100644 --- a/.github/workflows/params.yml +++ b/.github/workflows/params.yml @@ -15,6 +15,7 @@ env: { "NAME": "Bind", "VERSION": ["latest"], + "FLAVOUR": ["stable", "alpine", "latest"], "ARCH": ["linux/amd64", "linux/386", "linux/arm64", "linux/arm/v7", "linux/arm/v6", "linux/ppc64le", "linux/s390x", "linux/mips64le"] } ] diff --git a/Dockerfiles/Dockerfile.alpine b/Dockerfiles/Dockerfile.alpine new file mode 100644 index 0000000..88f8b9b --- /dev/null +++ b/Dockerfiles/Dockerfile.alpine @@ -0,0 +1,43 @@ +FROM alpine +LABEL org.opencontainers.image.authors="cytopia@everythingcli.org" + +ENV \ + USER=named \ + GROUP=named + +### +### Install +### +RUN set -x \ + && apk add --no-cache \ + bash \ + bind \ + bind-tools \ + # Log directory + && mkdir /var/log/named \ + && chown ${USER}:${GROUP} /var/log/named \ + && chmod 0755 /var/log/named \ + # Cache directory + && mkdir /var/cache/bind \ + && chown root:${GROUP} /var/cache/bind \ + && chmod 0775 /var/cache/bind + + + +### +### Bootstrap Scipts +### +COPY ./data/docker-entrypoint.sh / + + +### +### Ports +### +EXPOSE 53 +EXPOSE 53/udp + + +#### +#### Entrypoint +#### +ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/Dockerfile b/Dockerfiles/Dockerfile.latest similarity index 95% rename from Dockerfile rename to Dockerfiles/Dockerfile.latest index 387c900..e2e38b6 100644 --- a/Dockerfile +++ b/Dockerfiles/Dockerfile.latest @@ -1,6 +1,9 @@ FROM debian:stable-slim LABEL org.opencontainers.image.authors="cytopia@everythingcli.org" +ENV \ + USER=bind \ + GROUP=bind ### ### Install @@ -9,8 +12,6 @@ RUN set -eux \ && apt update \ && apt install --no-install-recommends --no-install-suggests -y \ bind9 \ - #nsutils \ - #putils-ping \ && apt purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ && rm -r /var/lib/apt/lists/* \ && mkdir /var/log/named \ diff --git a/Dockerfiles/Dockerfile.stable b/Dockerfiles/Dockerfile.stable new file mode 100644 index 0000000..e2e38b6 --- /dev/null +++ b/Dockerfiles/Dockerfile.stable @@ -0,0 +1,38 @@ +FROM debian:stable-slim +LABEL org.opencontainers.image.authors="cytopia@everythingcli.org" + +ENV \ + USER=bind \ + GROUP=bind + +### +### Install +### +RUN set -eux \ + && apt update \ + && apt install --no-install-recommends --no-install-suggests -y \ + bind9 \ + && apt purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ + && rm -r /var/lib/apt/lists/* \ + && mkdir /var/log/named \ + && chown bind:bind /var/log/named \ + && chmod 0755 /var/log/named + + +### +### Bootstrap Scipts +### +COPY ./data/docker-entrypoint.sh / + + +### +### Ports +### +EXPOSE 53 +EXPOSE 53/udp + + +#### +#### Entrypoint +#### +ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/data/docker-entrypoint.sh b/Dockerfiles/data/docker-entrypoint.sh similarity index 97% rename from data/docker-entrypoint.sh rename to Dockerfiles/data/docker-entrypoint.sh index 0020fc3..0252a7a 100755 --- a/data/docker-entrypoint.sh +++ b/Dockerfiles/data/docker-entrypoint.sh @@ -37,7 +37,13 @@ mkdir -p "${NAMED_CUST_ZONE}" ### When overwriting, use an FQDN by which this container is reachable. ### http://rscott.org/dns/soa.html ### -DEFAULT_MNAME="$( hostname -A | sed 's/\s$//g' | xargs -0 )" +if [ -f "/etc/alpine-release" ]; then + # Alpine + DEFAULT_MNAME="$( hostname -f | sed 's/\s$//g' | xargs -0 )" +else + # Debian + DEFAULT_MNAME="$( hostname -A | sed 's/\s$//g' | xargs -0 )" +fi ### @@ -532,10 +538,14 @@ log "info" "Debug level: ${DEBUG_ENTRYPOINT}" "${DEBUG_ENTRYPOINT}" { echo "include \"${NAMED_LOG_CONF}\";" echo "include \"${NAMED_OPT_CONF}\";" - echo "include \"/etc/bind/named.conf.local\";" - echo "include \"/etc/bind/named.conf.default-zones\";" + if [ -f "/etc/bind/named.conf.local" ]; then + echo "include \"/etc/bind/named.conf.local\";" + fi + if [ -f "/etc/bind/named.conf.default-zones" ]; then + echo "include \"/etc/bind/named.conf.default-zones\";" + fi } > "${NAMED_CONF}" - +log_file "${NAMED_CONF}" ### @@ -685,6 +695,13 @@ else fi +### +### Forward zones (resource policy zone) +### +# Empty out first +echo > "${NAMED_CUST_CONF}/rpz.conf" + + ### ### Build forward zones (A Record) ### @@ -917,4 +934,4 @@ done <<< "${FWD_ZONES}" ### log "info" "Starting $( named -V | grep -oiE '^BIND[[:space:]]+[0-9.]+' )" "${DEBUG_ENTRYPOINT}" named-checkconf "${NAMED_CONF}" -exec /usr/sbin/named -4 -c /etc/bind/named.conf -u bind -f +exec /usr/sbin/named -4 -c /etc/bind/named.conf -u "${USER}" -f diff --git a/Makefile b/Makefile index 2f88ec4..758045a 100644 --- a/Makefile +++ b/Makefile @@ -27,9 +27,18 @@ TAG = latest NAME = Bind VERSION = latest IMAGE = cytopia/bind -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 # Makefile.lint overwrites diff --git a/README.md b/README.md index b63932d..785637a 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,21 @@ Bind caching DNS server based on Debian slim with support for DNS forwarders, in |------------|------------------| | | | +## Available Docker tags + +| Docker Tag | Description | +|--------------------------------|--------------------------------------------------------------| +| `latest` | Latest Debian stable image (default) | +| `stable` | Latest Debian stable image | +| `alpine` | Latest Alpine image | +| | | +| `[0-9]\.[0-9]+` | Git tagged Debian stable image. E.g: `0.53` | +| `stable-[0-9]\.[0-9]+` | Git tagged Debian stable image. E.g: `stable-0.53` | +| `alpine-[0-9]\.[0-9]+` | Git tagged Alpine image. E.g: `alpine-0.53` | +| | | +| `release-[0-9]\.[0-9]+` | Git branch Debian stable image. E.g: `release-0.53` | +| `stable-release-[0-9]\.[0-9]+` | Git branch Debian stable image. E.g: `stable-release-0.53` | +| `alpine-release-[0-9]\.[0-9]+` | Git branch Alpine image. E.g: `alpine-release-0.53` | ---- From 31842c2ca85ff88a57e695a981cbc516b7ebce8e Mon Sep 17 00:00:00 2001 From: cytopia Date: Sat, 19 Mar 2022 08:46:55 +0100 Subject: [PATCH 2/6] Convert latest to symlink --- Dockerfiles/Dockerfile.latest | 39 +---------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) mode change 100644 => 120000 Dockerfiles/Dockerfile.latest diff --git a/Dockerfiles/Dockerfile.latest b/Dockerfiles/Dockerfile.latest deleted file mode 100644 index e2e38b6..0000000 --- a/Dockerfiles/Dockerfile.latest +++ /dev/null @@ -1,38 +0,0 @@ -FROM debian:stable-slim -LABEL org.opencontainers.image.authors="cytopia@everythingcli.org" - -ENV \ - USER=bind \ - GROUP=bind - -### -### Install -### -RUN set -eux \ - && apt update \ - && apt install --no-install-recommends --no-install-suggests -y \ - bind9 \ - && apt purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ - && rm -r /var/lib/apt/lists/* \ - && mkdir /var/log/named \ - && chown bind:bind /var/log/named \ - && chmod 0755 /var/log/named - - -### -### Bootstrap Scipts -### -COPY ./data/docker-entrypoint.sh / - - -### -### Ports -### -EXPOSE 53 -EXPOSE 53/udp - - -#### -#### Entrypoint -#### -ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/Dockerfiles/Dockerfile.latest b/Dockerfiles/Dockerfile.latest new file mode 120000 index 0000000..f924cbb --- /dev/null +++ b/Dockerfiles/Dockerfile.latest @@ -0,0 +1 @@ +Dockerfile.stable \ No newline at end of file From 03a508915608fa86222f0918110c8e2bbf3cfb2a Mon Sep 17 00:00:00 2001 From: cytopia Date: Sat, 19 Mar 2022 08:50:00 +0100 Subject: [PATCH 3/6] Show Bind version during GitHub Actions --- .github/workflows/params.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/params.yml b/.github/workflows/params.yml index 246486f..347cbbc 100644 --- a/.github/workflows/params.yml +++ b/.github/workflows/params.yml @@ -14,7 +14,7 @@ env: [ { "NAME": "Bind", - "VERSION": ["latest"], + "VERSION": ["9"], "FLAVOUR": ["stable", "alpine", "latest"], "ARCH": ["linux/amd64", "linux/386", "linux/arm64", "linux/arm/v7", "linux/arm/v6", "linux/ppc64le", "linux/s390x", "linux/mips64le"] } From 2cdb54e2cbe6e39a5d71c2d00ae0476b71759b79 Mon Sep 17 00:00:00 2001 From: cytopia Date: Sat, 19 Mar 2022 08:53:12 +0100 Subject: [PATCH 4/6] Trigger Build --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 785637a..3eec60a 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ Bind caching DNS server based on Debian slim with support for DNS forwarders, in | `stable-release-[0-9]\.[0-9]+` | Git branch Debian stable image. E.g: `stable-release-0.53` | | `alpine-release-[0-9]\.[0-9]+` | Git branch Alpine image. E.g: `alpine-release-0.53` | + ---- **Table of Contents** From e26fb67f08e6b2927e0bc1938f2b7633db8a8a88 Mon Sep 17 00:00:00 2001 From: cytopia Date: Sat, 19 Mar 2022 09:21:41 +0100 Subject: [PATCH 5/6] Ensure to re-create custom config directories prior startup --- Dockerfiles/data/docker-entrypoint.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Dockerfiles/data/docker-entrypoint.sh b/Dockerfiles/data/docker-entrypoint.sh index 0252a7a..64f1da1 100755 --- a/Dockerfiles/data/docker-entrypoint.sh +++ b/Dockerfiles/data/docker-entrypoint.sh @@ -27,6 +27,13 @@ NAMED_LOG_CONF="${NAMED_DIR}/named.conf.logging" NAMED_CUST_CONF="${NAMED_DIR}/custom/conf" NAMED_CUST_ZONE="${NAMED_DIR}/custom/zone" +# Recreate custom config directories +if [ -d "${NAMED_CUST_CONF}" ]; then + rm -rf "${NAMED_CUST_CONF}" +fi +if [ -d "${NAMED_CUST_ZONE}" ]; then + rm -rf "${NAMED_CUST_ZONE}" +fi mkdir -p "${NAMED_CUST_CONF}" mkdir -p "${NAMED_CUST_ZONE}" @@ -695,13 +702,6 @@ else fi -### -### Forward zones (resource policy zone) -### -# Empty out first -echo > "${NAMED_CUST_CONF}/rpz.conf" - - ### ### Build forward zones (A Record) ### From 65238b64055ebd4d03ad4fbb0e0ca10d736306b8 Mon Sep 17 00:00:00 2001 From: cytopia Date: Sat, 19 Mar 2022 09:38:40 +0100 Subject: [PATCH 6/6] Remove mips64le build from Alpine --- .github/workflows/params.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/params.yml b/.github/workflows/params.yml index 347cbbc..a292b09 100644 --- a/.github/workflows/params.yml +++ b/.github/workflows/params.yml @@ -15,8 +15,14 @@ env: { "NAME": "Bind", "VERSION": ["9"], - "FLAVOUR": ["stable", "alpine", "latest"], + "FLAVOUR": ["stable", "latest"], "ARCH": ["linux/amd64", "linux/386", "linux/arm64", "linux/arm/v7", "linux/arm/v6", "linux/ppc64le", "linux/s390x", "linux/mips64le"] + }, + { + "NAME": "Bind", + "VERSION": ["9"], + "FLAVOUR": ["alpine"], + "ARCH": ["linux/amd64", "linux/386", "linux/arm64", "linux/arm/v7", "linux/arm/v6", "linux/ppc64le", "linux/s390x"] } ]