Files
changedetection.io/.github/workflows/test-container-build.yml
T
Thibaud-Vdb 530a3d5fd6 ci: keep release metadata out of inline shell and lock down the container publish path (#4510)
* ci: pin third party actions to commit SHAs

A tag or branch ref is a movable pointer, whoever controls the action
repository can repoint it and the next run executes their code with
this repo's secrets, here the Docker Hub tokens and the container
publish path. The March 2025 tj-actions/changed-files incident
(CVE-2025-30066) worked exactly that way. Each pin keeps the resolved
tag in a comment and dependabot's weekly github-actions config bumps
SHA pins like tags, so they self-maintain. The pypi publish action
moves from the floating release/v1 branch to its current release.

* ci: declare least-privilege workflow permissions

Without a permissions block every job token inherits the repository
default scope. Each workflow now declares what it uses. The test and
build workflows get read-only tokens, CodeQL keeps its code scanning
upload, the container publish job keeps packages write for the ghcr
push, and the pypi publish job already carried its own id-token block
for trusted publishing, untouched.

* ci: pass release metadata to inline scripts through env

The two debug steps interpolated the release tag name and the
workflow_run branch directly into bash. Those strings are event
metadata that can carry shell syntax, and the workflow runs on
release events with the publish credentials in reach. Routed through
env they arrive as plain data, output unchanged.

* ci: stop persisting the checkout token in .git/config

actions/checkout writes the job token into .git/config so later steps can
push. None of these 21 jobs push with git: the containers are published
with registry credentials, PyPI uses trusted publishing, and the test
and CodeQL jobs only read the tree. A token left in .git/config is one
more credential for a compromised step or a packed artifact to pick up,
so each checkout now sets persist-credentials: false.
2026-10-09 20:12:35 +02:00

93 lines
2.9 KiB
YAML

name: ChangeDetection.io Container Build Test
# Triggers the workflow on push or pull request events
# This line doesnt work, even tho it is the documented one
#on: [push, pull_request]
on:
push:
paths:
- requirements.txt
- Dockerfile
- .github/workflows/*
- .github/test/Dockerfile*
pull_request:
paths:
- requirements.txt
- Dockerfile
- .github/workflows/*
- .github/test/Dockerfile*
# Changes to requirements.txt packages and Dockerfile may or may not always be compatible with arm etc, so worth testing
# @todo: some kind of path filter for requirements.txt and Dockerfile
permissions:
contents: read
jobs:
builder:
name: Build ${{ matrix.platform }} (${{ matrix.dockerfile == './Dockerfile' && 'main' || 'alpine' }})
runs-on: ubuntu-latest
strategy:
matrix:
include:
# Main Dockerfile platforms
- platform: linux/amd64
dockerfile: ./Dockerfile
- platform: linux/arm64
dockerfile: ./Dockerfile
- platform: linux/arm/v7
dockerfile: ./Dockerfile
- platform: linux/arm/v8
dockerfile: ./Dockerfile
# Alpine Dockerfile platforms (musl via alpine check)
- platform: linux/amd64
dockerfile: ./.github/test/Dockerfile-alpine
- platform: linux/arm64
dockerfile: ./.github/test/Dockerfile-alpine
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- name: Set up Python 3.11
uses: actions/setup-python@v7
with:
python-version: 3.11
- name: Cache pip packages
uses: actions/cache@v6
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
# Just test that the build works, some libraries won't compile on ARM/rPi etc
- name: Set up QEMU
uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0
with:
image: tonistiigi/binfmt:latest
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
with:
install: true
version: latest
driver-opts: image=moby/buildkit:master
- name: Test that the docker containers can build (${{ matrix.platform }} - ${{ matrix.dockerfile }})
id: docker_build
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
# https://github.com/docker/build-push-action#customizing
with:
context: ./
file: ${{ matrix.dockerfile }}
platforms: ${{ matrix.platform }}
cache-from: type=gha
cache-to: type=gha,mode=max