mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-07-14 03:39:12 +09:00
3fada3d997
* Add GitHub Actions audit job (actionlint + zizmor) to CI Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Configure dependabot for GitHub Actions, bundler, and Docker Batches all action updates into a single weekly PR. Adds cooldown periods to all ecosystems. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Add local GitHub Actions linting (actionlint + zizmor) to bin/setup and bin/ci Install actionlint, shellcheck, and zizmor in bin/setup. Run both linters as CI steps in config/ci.rb alongside existing style checks. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Pin all GitHub Actions to SHA hashes Run pinact to pin action versions to specific commit SHAs, preventing supply chain attacks from tag mutation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix high severity zizmor findings - Suppress unpinned-images for redis service containers (digest pinning is nontrivial for service containers) - Move workflow-level permissions to job-level in publish-image.yml (build gets full set, manifest gets only what it needs) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix medium severity zizmor findings - Add persist-credentials: false to all checkout steps - Add permissions: {} at workflow level in ci.yml - Add job-level permissions (contents: read) to all CI jobs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix informational template-injection findings in publish-image.yml Move steps.meta.outputs.tags from inline ${{ }} expressions to env vars in both the manifest creation and cosign signing steps. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Update brakeman to 8.0.4 bin/brakeman uses --ensure-latest which fails if not on the newest version. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
214 lines
7.3 KiB
YAML
214 lines
7.3 KiB
YAML
name: Build and publish container image to GHCR
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- 'v*'
|
|
pull_request:
|
|
workflow_dispatch:
|
|
|
|
concurrency:
|
|
group: publish-${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
permissions: {}
|
|
|
|
env:
|
|
IMAGE_DESCRIPTION: Campfire is a web-based chat application with multiple rooms, direct messages, file attachments with previews, search, web push notifications, @mentions, and bot integrations. Single-tenant; production-ready image with web app, background jobs, caching, file serving, and SSL.
|
|
SOURCE_URL: https://github.com/${{ github.repository }}
|
|
|
|
jobs:
|
|
build:
|
|
name: Build and push image (${{ matrix.arch }})
|
|
runs-on: ${{ matrix.runner }}
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
id-token: write
|
|
attestations: write
|
|
timeout-minutes: 45
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- runner: ubuntu-latest
|
|
platform: linux/amd64
|
|
arch: amd64
|
|
- runner: ubuntu-24.04-arm
|
|
platform: linux/arm64
|
|
arch: arm64
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Compute canonical image name (lowercase)
|
|
id: vars
|
|
shell: bash
|
|
run: |
|
|
set -eu
|
|
IMAGE_REF="${IMAGE_NAME:-$GITHUB_REPOSITORY}"
|
|
CANONICAL_IMAGE="${REGISTRY}/${IMAGE_REF,,}"
|
|
echo "canonical=${CANONICAL_IMAGE}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Extract Docker metadata (tags, labels) with arch suffix
|
|
id: meta
|
|
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
|
|
with:
|
|
images: ${{ steps.vars.outputs.canonical }}
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=ref,event=tag
|
|
type=sha,format=short,prefix=sha-
|
|
type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
|
|
type=semver,pattern={{major}}.{{minor}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
|
|
type=semver,pattern={{major}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
|
|
flavor: |
|
|
latest=false
|
|
suffix=-${{ matrix.arch }}
|
|
labels: |
|
|
org.opencontainers.image.source=${{ env.SOURCE_URL }}
|
|
|
|
- name: Build and push (${{ matrix.platform }})
|
|
id: build
|
|
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
|
|
with:
|
|
context: .
|
|
file: Dockerfile
|
|
build-args: |
|
|
OCI_SOURCE=${{ env.SOURCE_URL }}
|
|
OCI_DESCRIPTION=${{ env.IMAGE_DESCRIPTION }}
|
|
platforms: ${{ matrix.platform }}
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=gha,scope=${{ matrix.platform }}
|
|
cache-to: type=gha,scope=${{ matrix.platform }},mode=max
|
|
sbom: false
|
|
provenance: false
|
|
|
|
- name: Attest image provenance (per-arch)
|
|
if: github.event_name != 'pull_request'
|
|
uses: actions/attest-build-provenance@977bb373ede98d70efdf65b84cb5f73e068dcc2a # v3.0.0
|
|
with:
|
|
subject-name: ${{ steps.vars.outputs.canonical }}
|
|
subject-digest: ${{ steps.build.outputs.digest }}
|
|
push-to-registry: false
|
|
|
|
manifest:
|
|
name: Create multi-arch manifest and sign
|
|
needs: build
|
|
if: github.event_name != 'pull_request'
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
id-token: write
|
|
timeout-minutes: 20
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
steps:
|
|
- name: Set up Docker Buildx (for imagetools)
|
|
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Compute canonical image name (lowercase)
|
|
id: vars
|
|
shell: bash
|
|
run: |
|
|
set -eu
|
|
IMAGE_REF="${IMAGE_NAME:-$GITHUB_REPOSITORY}"
|
|
CANONICAL_IMAGE="${REGISTRY}/${IMAGE_REF,,}"
|
|
echo "canonical=${CANONICAL_IMAGE}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Compute base tags (no suffix)
|
|
id: meta
|
|
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
|
|
with:
|
|
images: ${{ steps.vars.outputs.canonical }}
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=ref,event=tag
|
|
type=sha,format=short,prefix=sha-
|
|
type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
|
|
type=semver,pattern={{major}}.{{minor}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
|
|
type=semver,pattern={{major}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
|
|
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
|
|
flavor: |
|
|
latest=false
|
|
labels: |
|
|
org.opencontainers.image.source=${{ env.SOURCE_URL }}
|
|
|
|
- name: Create multi-arch manifests
|
|
shell: bash
|
|
env:
|
|
TAGS: ${{ steps.meta.outputs.tags }}
|
|
run: |
|
|
set -eu
|
|
tags="$TAGS"
|
|
echo "Creating manifests for tags:"
|
|
printf '%s\n' "$tags"
|
|
while IFS= read -r tag; do
|
|
[ -z "$tag" ] && continue
|
|
echo "Creating manifest for $tag"
|
|
src_tag="$tag"
|
|
if [[ "$tag" == *:latest && "${GITHUB_REF}" == refs/tags/* ]]; then
|
|
ref="${GITHUB_REF#refs/tags/}"
|
|
src_tag="${tag%:latest}:$ref"
|
|
fi
|
|
if [ -n "${IMAGE_DESCRIPTION:-}" ]; then
|
|
docker buildx imagetools create \
|
|
--tag "$tag" \
|
|
--annotation "index:org.opencontainers.image.description=${IMAGE_DESCRIPTION}" \
|
|
"${src_tag}-amd64" \
|
|
"${src_tag}-arm64"
|
|
else
|
|
docker buildx imagetools create \
|
|
--tag "$tag" \
|
|
"${src_tag}-amd64" \
|
|
"${src_tag}-arm64"
|
|
fi
|
|
done <<< "$tags"
|
|
|
|
- name: Install Cosign
|
|
uses: sigstore/cosign-installer@d58896d6a1865668819e1d91763c7751a165e159 # v3.9.2
|
|
|
|
- name: Cosign sign all tags (keyless OIDC)
|
|
shell: bash
|
|
env:
|
|
TAGS: ${{ steps.meta.outputs.tags }}
|
|
run: |
|
|
set -eu
|
|
tags="$TAGS"
|
|
printf '%s\n' "$tags"
|
|
while IFS= read -r tag; do
|
|
[ -z "$tag" ] && continue
|
|
echo "Signing $tag"
|
|
cosign sign --yes "$tag"
|
|
done <<< "$tags"
|
|
|
|
|