diff --git a/.github/workflows/prek_checks.yml b/.github/workflows/prek_checks.yml index 888299b..a43b12e 100644 --- a/.github/workflows/prek_checks.yml +++ b/.github/workflows/prek_checks.yml @@ -1,6 +1,5 @@ name: prek checks -# push is not included because build workflows call this on push -on: [pull_request, workflow_call, workflow_dispatch] +on: [workflow_call, workflow_dispatch] jobs: prek: @@ -21,6 +20,9 @@ jobs: env: # The first three variables (HADOLINT_DOWNLOAD, HADOLINT_BINARY, # HADOLINT_VERSION) are all parts of the release binary URL. + # + # The first two variables are generic and shouldn't need to be + # updated HADOLINT_DOWNLOAD: >- https://github.com/hadolint/hadolint/releases/download HADOLINT_BINARY: hadolint-linux-x86_64 @@ -47,6 +49,7 @@ jobs: with: install-only: true + # The no-commit-to-branch builtin hook is skipped to avoid false # positives (ex. when PRs are merged) - name: 'Run prek' diff --git a/.github/workflows/trixie-dev.yml b/.github/workflows/trixie-dev.yml new file mode 100644 index 0000000..0951119 --- /dev/null +++ b/.github/workflows/trixie-dev.yml @@ -0,0 +1,109 @@ +# https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax +# https://docs.github.com/en/actions/reference/workflows-and-actions/variables +name: 'trixie-dev' +# GHCR: GitHub Container Registry + +on: + pull_request: + branches-ignore: [main] + paths: + - '.github/workflows/trixie-dev.yml' + - '.github/workflows/prek_checks.yml' + - 'trixie/' + - '!trixie/README.md' + workflow_dispatch: + +env: + DESCRIPTION: 'Creative Commons (CC) Debian 13 (trixie) development' + OCI: 'org.opencontainers.image' + TITLE: 'CC Debian trixie (development)' + URL: 'https://github.com/creativecommons/containers/trixie' + VENDOR: 'Creative Commons' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name }} + cancel-in-progress: true + +jobs: + + prek_checks: + uses: $/.github/workflows/prek_checks.yml + + build_and_push: + needs: prek_checks + permissions: + contents: read + packages: write + runs-on: ubuntu-latest + + steps: + + - parallel: + + # https://github.com/docker/login-action + - name: Docker login to GitHub Container Registry (GHCR) + # docker/login-action v4.8.0 + uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # https://github.com/docker/metadata-action + - name: Docker extract metadata + id: docker_meta + env: + DOCKER_METADATA_ANNOTATIONS_LEVELS: index + # docker/metadata-action v6.2.0 + uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 + with: + annotations: | + ${{ env.OCI }}.created={{ date 'YYYY-MM-DDTHH:mm:ss.SSS[Z]' }} + ${{ env.OCI }}.description=${{ env.DESCRIPTION }} + ${{ env.OCI }}.source=${{ env.URL }} + ${{ env.OCI }}.title=${{ env.TITLE }} + ${{ env.OCI }}.url=${{ env.URL }} + ${{ env.OCI }}.vendor=${{ env.VENDOR }} + images: ghcr.io/creativecommons/trixie-dev + # https://specs.opencontainers.org/image-spec/annotations/ + labels: | + ${{ env.OCI }}.created={{ date 'YYYY-MM-DDTHH:mm:ss.SSS[Z]' }} + ${{ env.OCI }}.description=${{ env.DESCRIPTION }} + ${{ env.OCI }}.source=${{ env.URL }} + ${{ env.OCI }}.title=${{ env.TITLE }} + ${{ env.OCI }}.url=${{ env.URL }} + ${{ env.OCI }}.vendor=${{ env.VENDOR }} + tags: | + type=ref,event=pr,suffix=-{{ sha }} + + # https://github.com/docker/setup-buildx-action + - name: Docker setup Buildx + id: docker_buildx + # docker/setup-buildx-action v4.4.1 + uses: >- + docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 + with: + platforms: linux/amd64,linux/arm64 + + # https://github.com/actions/checkout + - name: GitHub checkout repository + # actions/checkout v7.0.1 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + + + # https://github.com/docker/build-push-action + - name: Build and push Docker trixie image to GHCR + # build-push-action v7.4.0 + uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc + with: + annotations: ${{ steps.docker_meta.outputs.annotations }} + builder: ${{ steps.docker_buildx.outputs.name }} + cache-from: type=gha + cache-to: type=gha,mode=max + context: trixie + labels: ${{ steps.docker_meta.outputs.labels }} + platforms: ${{ steps.docker_buildx.outputs.platforms }} + provenance: false + push: true + sbom: false + tags: ${{ steps.docker_meta.outputs.tags }} diff --git a/.github/workflows/build_trixie_to_ghcr.yml b/.github/workflows/trixie.yml similarity index 86% rename from .github/workflows/build_trixie_to_ghcr.yml rename to .github/workflows/trixie.yml index 722df57..06d35ca 100644 --- a/.github/workflows/build_trixie_to_ghcr.yml +++ b/.github/workflows/trixie.yml @@ -1,25 +1,23 @@ # https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax # https://docs.github.com/en/actions/reference/workflows-and-actions/variables -name: Build & push trixie to GHCR +name: 'trixie' # GHCR: GitHub Container Registry on: - create: push: + branches: [main] paths: - - '.github/workflows/build_trixie_to_ghcr.yml' + - '.github/workflows/trixie.yml' - '.github/workflows/prek_checks.yml' - 'trixie/' - '!trixie/README.md' workflow_dispatch: env: - DESCRIPTION: 'Creative Commons (CC) Debian 13 (trixe)' + DESCRIPTION: 'Creative Commons (CC) Debian 13 (trixie)' OCI: 'org.opencontainers.image' TITLE: 'CC Debian trixie' - TYPE_RAW__DEFAULT_ONLY__VALUE_DATE: >- - type=raw,enable={{is_default_branch}},value={{date 'YYYYMMDD-HHmmss'}} - URL: 'https://github.com/creativecommons/base-containers/trixie' + URL: 'https://github.com/creativecommons/containers/trixie' VENDOR: 'Creative Commons' jobs: @@ -72,9 +70,8 @@ jobs: ${{ env.OCI }}.url=${{ env.URL }} ${{ env.OCI }}.vendor=${{ env.VENDOR }} tags: | - ${{ env.TYPE_RAW__DEFAULT_ONLY__VALUE_DATE }} - type=raw,enable={{ is_default_branch }},priority=100,value=latest - type=sha,enable={{ is_not_default_branch }},prefix={{ branch }}- + type=raw,value={{date 'YYYYMMDD-HHmmss'}} + type=raw,priority=100,value=latest # https://github.com/docker/setup-buildx-action - name: Docker setup Buildx diff --git a/docker-compose.yml b/docker-compose.yml index c26b9f6..5892e6f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,15 +10,16 @@ services: build: context: trixie # disable the entrypoint as the image is only being built locally for use - # by trixie-dev + # by other services entrypoint: /bin/true image: trixie - # Development overlay - trixie-dev: + # Local development overlay + trixie-local: build: additional_contexts: trixie: "service:trixie" - context: trixie-dev + context: trixie-local command: sh -c 'echo "CMD ignored? (this should NOT show up in console)"' env_file: .env + image: trixie-local diff --git a/trixie-dev/Dockerfile b/trixie-local/Dockerfile similarity index 51% rename from trixie-dev/Dockerfile rename to trixie-local/Dockerfile index eb29ddc..63f2263 100644 --- a/trixie-dev/Dockerfile +++ b/trixie-local/Dockerfile @@ -4,15 +4,13 @@ FROM trixie # https://docs.docker.com/build/building/best-practices/#apt-get -# - Resynchronize the package index, update packages, install packages, -# and clean-up apt/dpkg +# - apt and dpkg are configured in parent CC Debian trixie image +# - Retrieve new lists of packages, distribution upgrade, install new +# packages, erase downloaded archive files, and erase package lists RUN set -o errexit -o nounset \ - && DEBIAN_FRONTEND=noninteractive apt-get update \ - --no-allow-insecure-repositories --quiet \ - && DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade \ - --no-install-recommends --no-install-suggests --quiet --yes \ - && DEBIAN_FRONTEND=noninteractive apt-get install \ - --no-install-recommends --no-install-suggests --quiet --yes \ + && apt-get update --quiet \ + && apt-get dist-upgrade --quiet --yes \ + && apt-get install --quiet --yes \ curl \ httpie \ less \ @@ -20,11 +18,11 @@ RUN set -o errexit -o nounset \ tree \ vim \ wget \ - && DEBIAN_FRONTEND=noninteractive apt-get clean --quiet + && apt-get clean --quiet \ + && rm --recursive --force /var/lib/apt/lists/* # Create a Sleep service COPY --chmod=0555 sleep-run /etc/sv/sleep/run - RUN set -o errexit -o nounset \ && mkdir --parents /etc/sv/sleep/log \ && ln -s /etc/sv/socklog-unix/log/run /etc/sv/sleep/log/run \ diff --git a/trixie-dev/sleep-run b/trixie-local/sleep-run similarity index 79% rename from trixie-dev/sleep-run rename to trixie-local/sleep-run index 34b3865..a06e4fd 100644 --- a/trixie-dev/sleep-run +++ b/trixie-local/sleep-run @@ -4,5 +4,5 @@ sv start socklog-unix >/dev/null \ && sv check socklog-unix >/dev/null \ || exit 170 exec 2>&1 -echo 'Sleeping 💤' +printf '\e[34mSleeping\e[0m 💤\n' exec sleep 60 diff --git a/trixie/Dockerfile b/trixie/Dockerfile index ef7000a..1f7d735 100644 --- a/trixie/Dockerfile +++ b/trixie/Dockerfile @@ -9,29 +9,33 @@ FROM debian:trixie-slim COPY dpkg-cfg-socklog-slim /etc/dpkg/dpkg.cfg.d/socklog-slim # https://docs.docker.com/build/building/best-practices/#apt-get -# - Resynchronize the package index, update packages, install packages, -# clean-up apt/dpkg, and update CA certificates +# 1. Configure apt to avoid optional packages +# 2. Configure debconf to use noninteractive frontend +# 3. Retrieve new lists of packages, distribution upgrade, install new +# packages, erase downloaded archive files, erase package lists, and update +# certificate authority certificates +COPY docker-slim /etc/apt/apt.conf.d/docker-slim RUN set -o errexit -o nounset \ - && DEBIAN_FRONTEND=noninteractive apt-get update \ - --no-allow-insecure-repositories --quiet \ - && DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade \ - --no-install-recommends --no-install-suggests --quiet --yes \ - && DEBIAN_FRONTEND=noninteractive apt-get install \ - --no-install-recommends --no-install-suggests --quiet --yes \ + sed --regexp-extended --in-place \ + -e's/^(Templates:.+)$/\1\n# Debconf will select the default answer/' \ + -e's/(default answer)$/\1\nFrontend: noninteractive/' \ + /etc/debconf.conf \ + && apt-get update --quiet \ + && apt-get dist-upgrade --quiet --yes \ + && apt-get install --quiet --yes \ dumb-init \ ca-certificates \ msmtp-mta \ runit \ socklog-run \ - && DEBIAN_FRONTEND=noninteractive apt-get clean --quiet \ + && apt-get clean --quiet \ && rm --recursive --force /var/lib/apt/lists/* \ && update-ca-certificates # Runit configuration -# -# The default-syslog service is handled specially by runit (packages has -# related triggers). It can't be excluded and must be added before it can be -# removed. +# - The default-syslog service is handled specially by runit (packages has +# related triggers). It can't be excluded and must be added before it can be +# removed. COPY --chmod=0555 log-run /etc/sv/socklog-unix/log/run RUN set -o errexit -o nounset \ && update-service --add socklog-unix \ @@ -39,5 +43,10 @@ RUN set -o errexit -o nounset \ && update-service --remove default-syslog COPY --parents conf.d/* color_vars.sh /etc/container/ COPY --chmod=0555 setup.sh /etc/container/ -ENTRYPOINT ["/usr/bin/dumb-init", "/etc/container/setup.sh"] + +# Initialization +# 1. dumb-init is a signal repeater that defaults to process group mode +# 2. setup script sources any available configuration scripts +# 3. setup execs runit's runsvdir service management +ENTRYPOINT ["/usr/bin/dumb-init", "--", "/etc/container/setup.sh"] # ⚠️ NOTE: CMD is ignored. Services must be installed and enabled per runit. diff --git a/trixie/README.md b/trixie/README.md index 0a37309..9c5a7ee 100644 --- a/trixie/README.md +++ b/trixie/README.md @@ -51,10 +51,12 @@ When the image starts up, the `/etc/container/setup.sh` ## Deployment The image is deployed via GitHub Actions to the GitHub Container Registry -(GHCR). See the workflow for details: -[`../.github/workflows/build_trixie_to_ghcr.yml`][build]. +(GHCR). See the workflows for details: +- `main` branch: [`../.github/workflows/trixie.yml`][build] +- all other branches: [`../.github/workflows/trixie-dev.yml`][build-dev] -[build]: ../.github/workflows/build_trixie_to_ghcr.yml +[build]: ../.github/workflows/trixi.yml +[build]: ../.github/workflows/trixie-dev.yml ## Extending diff --git a/trixie/docker-slim b/trixie/docker-slim new file mode 100644 index 0000000..fe34abc --- /dev/null +++ b/trixie/docker-slim @@ -0,0 +1,8 @@ +# https://www.debian.org/doc/manuals/aptitude/ch02s05s05.en.html#configAptInstall-Recommends +# https://manpages.debian.org/trixie/apt/apt-get.8.en.html#OPTIONS +APT::Install-Recommends "false"; + +# https://manpages.debian.org/trixie/apt/apt-get.8.en.html#OPTIONS +APT::Install-Suggests "false"; + +# vim: filetype=aptconf diff --git a/trixie/setup.sh b/trixie/setup.sh index e06fca0..7dc4be0 100644 --- a/trixie/setup.sh +++ b/trixie/setup.sh @@ -83,7 +83,7 @@ do . "${_config_script}" done -# Prep and execute runit +# Prep and execute runit service management # Based on /etc/runit/2 mkdir --parents /run/runit/supervise /lib/runit/trigger_sv setup