From dbeb3a19da48abaadf8ca3795410673941fc2220 Mon Sep 17 00:00:00 2001 From: Maciej Michalski Date: Mon, 16 Nov 2026 20:53:44 +0100 Subject: [PATCH 1/2] Add reusable container image workflow --- .gitattributes | 1 + .github/CODEOWNERS | 3 + .github/ISSUE_TEMPLATE/bug_report.yml | 34 ++++ .github/ISSUE_TEMPLATE/config.yml | 1 + .github/ISSUE_TEMPLATE/feature_request.yml | 26 +++ .github/PULL_REQUEST_TEMPLATE.md | 24 +++ .github/dependabot.yml | 10 + .github/workflows/container-image.yml | 208 +++++++++++++++++++++ .github/workflows/lint.yml | 22 +++ CODE_OF_CONDUCT.md | 41 ++++ CONTRIBUTING.md | 33 ++++ LICENSE | 2 +- README.md | 98 ++++++++++ 13 files changed, 502 insertions(+), 1 deletion(-) create mode 100644 .gitattributes create mode 100644 .github/CODEOWNERS create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/container-image.yml create mode 100644 .github/workflows/lint.yml create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 README.md diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6313b56 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..cb26f3c --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,3 @@ +# CODEOWNERS +# Repository owners: update if needed +* @Think-Cube/think-cube diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..5e8ccc6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,34 @@ +name: Bug Report +description: Report a problem with a reusable workflow +title: "bug: " +labels: ["bug", "triage"] +body: + - type: input + id: workflow + attributes: + label: Workflow and version + placeholder: e.g. container-image.yml@v1.0.0 + validations: + required: true + + - type: input + id: run + attributes: + label: Link to the failing run + validations: + required: true + + - type: textarea + id: description + attributes: + label: Describe the bug + description: A clear description of what the bug is. + validations: + required: true + + - type: textarea + id: expected + attributes: + label: Expected behavior + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..3ba13e0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1 @@ +blank_issues_enabled: false diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..e801623 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,26 @@ +name: Feature Request +description: Suggest an improvement or a new reusable workflow +title: "feat: " +labels: ["enhancement", "triage"] +body: + - type: textarea + id: problem + attributes: + label: Problem / motivation + description: What problem does this solve? What use case does it enable? + validations: + required: true + + - type: textarea + id: solution + attributes: + label: Proposed solution + validations: + required: true + + - type: textarea + id: alternatives + attributes: + label: Alternatives considered + validations: + required: false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..3abbaf6 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,24 @@ +## Type of Change + +- [ ] Bug fix +- [ ] New feature / improvement +- [ ] Action / dependency update +- [ ] Documentation update +- [ ] Other (describe below) + +## Description + + + +## Testing + +- [ ] `actionlint` passes +- [ ] Ran the changed workflow from a calling repository +- [ ] No secrets or credentials committed + +## Checklist + +- [ ] Actions are pinned to commit SHAs +- [ ] Breaking changes to inputs, secrets or permissions are called out +- [ ] README updated if behavior changed +- [ ] I have read [CONTRIBUTING.md](../CONTRIBUTING.md) diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..05c25f6 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly + groups: + actions: + patterns: + - "*" diff --git a/.github/workflows/container-image.yml b/.github/workflows/container-image.yml new file mode 100644 index 0000000..ff8fe61 --- /dev/null +++ b/.github/workflows/container-image.yml @@ -0,0 +1,208 @@ +name: Container image + +on: + workflow_call: + inputs: + image-name: + description: Image name without registry or namespace + required: true + type: string + context: + description: Build context + required: false + type: string + default: . + dockerfile: + description: Path to the Dockerfile + required: false + type: string + default: Dockerfile + platforms: + description: JSON array of platforms to build + required: false + type: string + default: '["linux/amd64", "linux/arm64"]' + smoke-test: + description: Script run with the image reference as its only argument + required: false + type: string + default: tests/smoke.sh + trivy-severity: + description: Severities that fail the build + required: false + type: string + default: CRITICAL + dockerhub-namespace: + description: Docker Hub namespace of the mirror + required: false + type: string + default: thinkcubedev + secrets: + DOCKERHUB_USERNAME: + required: false + DOCKERHUB_TOKEN: + required: false + +permissions: {} + +jobs: + lint: + runs-on: ubuntu-24.04 + permissions: + contents: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: hadolint/hadolint-action@06be81baf89a55ffd0e24b8f04a4185738dd3387 # v3.5.0 + with: + dockerfile: ${{ inputs.dockerfile }} + + verify: + needs: lint + runs-on: ${{ matrix.platform == 'linux/arm64' && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }} + permissions: + contents: read + strategy: + fail-fast: false + matrix: + platform: ${{ fromJSON(inputs.platforms) }} + env: + IMAGE: local/${{ inputs.image-name }}:test + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 + - uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 + with: + context: ${{ inputs.context }} + file: ${{ inputs.dockerfile }} + platforms: ${{ matrix.platform }} + load: true + tags: ${{ env.IMAGE }} + provenance: false + no-cache: ${{ github.event_name == 'schedule' }} + cache-from: type=gha,scope=${{ matrix.platform }} + cache-to: type=gha,mode=max,scope=${{ matrix.platform }},ignore-error=true + - name: Run smoke test + env: + SMOKE_TEST: ${{ inputs.smoke-test }} + run: bash "$SMOKE_TEST" "$IMAGE" + - uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 + with: + image-ref: ${{ env.IMAGE }} + scanners: vuln + severity: ${{ inputs.trivy-severity }} + ignore-unfixed: true + exit-code: "1" + timeout: 15m + + publish: + needs: verify + if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-24.04 + permissions: + contents: read + id-token: write + packages: write + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Resolve image references + id: image + env: + IMAGE_NAME: ${{ inputs.image-name }} + PLATFORMS: ${{ inputs.platforms }} + run: | + echo "ghcr=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/${IMAGE_NAME}" >> "$GITHUB_OUTPUT" + echo "platforms=$(jq -r 'join(",")' <<< "$PLATFORMS")" >> "$GITHUB_OUTPUT" + { + echo 'cache-from<> "$GITHUB_OUTPUT" + - uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0 + - uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 + - uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + - uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0 + if: env.DOCKERHUB_USERNAME != '' + with: + registry: docker.io + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0 + id: meta + env: + DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index + with: + images: ${{ steps.image.outputs.ghcr }} + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=edge,branch=main + type=sha,format=short,prefix=sha-,enable=${{ github.event_name == 'push' && github.ref_type == 'branch' }} + type=schedule,pattern={{date 'YYYYMMDD'}},prefix=edge- + - name: Refuse to overwrite a released version + if: github.ref_type == 'tag' + env: + IMAGE: ${{ steps.image.outputs.ghcr }} + VERSION: ${{ steps.meta.outputs.version }} + run: | + if docker buildx imagetools inspect "$IMAGE:$VERSION" > /dev/null 2>&1; then + echo "::error::$IMAGE:$VERSION already exists; release a new version instead" + exit 1 + fi + - uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 + id: build + with: + context: ${{ inputs.context }} + file: ${{ inputs.dockerfile }} + platforms: ${{ steps.image.outputs.platforms }} + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + annotations: ${{ steps.meta.outputs.annotations }} + sbom: true + provenance: mode=max + no-cache: ${{ github.event_name == 'schedule' }} + cache-from: ${{ steps.image.outputs.cache-from }} + - uses: sigstore/cosign-installer@756fe2d284c7292c4e9b62c8a28f1e5629c59532 # v4.1.3 + - name: Sign the image + env: + IMAGE: ${{ steps.image.outputs.ghcr }} + DIGEST: ${{ steps.build.outputs.digest }} + run: cosign sign --yes "$IMAGE@$DIGEST" + - name: Mirror to Docker Hub + if: env.DOCKERHUB_USERNAME != '' + env: + GHCR_IMAGE: ${{ steps.image.outputs.ghcr }} + HUB_IMAGE: docker.io/${{ inputs.dockerhub-namespace }}/${{ inputs.image-name }} + DIGEST: ${{ steps.build.outputs.digest }} + TAGS: ${{ steps.meta.outputs.tags }} + run: | + args=() + while read -r tag; do + args+=(--tag "${tag/#$GHCR_IMAGE/$HUB_IMAGE}") + done <<< "$TAGS" + docker buildx imagetools create "${args[@]}" "$GHCR_IMAGE@$DIGEST" + cosign sign --yes "$HUB_IMAGE@$DIGEST" + - name: Write summary + env: + IMAGE: ${{ steps.image.outputs.ghcr }} + DIGEST: ${{ steps.build.outputs.digest }} + TAGS: ${{ steps.meta.outputs.tags }} + run: | + { + echo "Published \`$IMAGE@$DIGEST\`" + echo + sed 's/.*/- `&`/' <<< "$TAGS" + } >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..6461297 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,22 @@ +name: Lint + +on: + push: + branches: [main] + pull_request: + branches: [main] + +permissions: {} + +jobs: + actionlint: + runs-on: ubuntu-24.04 + permissions: + contents: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: docker://rhysd/actionlint:1.7.12@sha256:b1934ee5f1c509618f2508e6eb47ee0d3520686341fec936f3b79331f9315667 + with: + args: -color diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..516c6d5 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,41 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment: + +- Demonstrating empathy and kindness toward other people +- Being respectful of differing opinions, viewpoints, and experiences +- Giving and gracefully accepting constructive feedback +- Accepting responsibility and apologizing to those affected by our mistakes +- Focusing on what is best not just for us as individuals, but for the overall community + +Examples of unacceptable behavior: + +- The use of sexualized language or imagery, and sexual attention or advances of any kind +- Trolling, insulting or derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information without explicit permission +- Other conduct which could reasonably be considered inappropriate in a professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at the repository's Issues page. All complaints will be reviewed and investigated promptly and fairly. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 2.1. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..10bee62 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,33 @@ +# Contributing to workflows + +Thank you for your interest in contributing! + +## How to Contribute + +1. **Fork** this repository. +2. **Create a branch**: `git checkout -b fix/description` or `feat/description` +3. **Make your changes** — see guidelines below. +4. **Open a Pull Request** using the PR template. + +## Workflow Guidelines + +- Pin every action to a full commit SHA with the version in a comment. +- Declare `permissions: {}` at the top and grant each job only what it needs. +- Pass `${{ }}` values to `run` steps through `env`, never inline them into the script. +- Do not use `secrets: inherit`; declare each secret the workflow needs. +- Document new inputs and secrets in the README. +- Changes to inputs, secrets or required permissions that break callers need a new major version. + +## Testing + +Every pull request runs `actionlint`. Before releasing, point a calling repository at your branch and check a full run. + +## Reporting Issues + +Use the issue templates: +- **Bug report** — something is broken or behaves unexpectedly. +- **Feature request** — suggest an improvement. + +## Code of Conduct + +By contributing, you agree to abide by our [Code of Conduct](CODE_OF_CONDUCT.md). diff --git a/LICENSE b/LICENSE index 9d76bbf..b946e70 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2026 ThinkCube +Copyright (c) 2026 Think-Cube Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md new file mode 100644 index 0000000..4d2b28f --- /dev/null +++ b/README.md @@ -0,0 +1,98 @@ +# workflows + +Reusable GitHub Actions workflows for Think-Cube repositories. + +## Workflows + +| Workflow | Purpose | +|---|---| +| [`container-image.yml`](.github/workflows/container-image.yml) | Lint, test, scan, sign and publish a multi-arch container image | + +## container-image + +Every run lints the Dockerfile with Hadolint, then builds the image for each platform on a native runner, runs the repository's smoke test and fails on fixable vulnerabilities found by Trivy. + +On `main` and on `v*` tags it also builds a multi-arch image with an SBOM and build provenance, pushes it to GitHub Container Registry, signs it with keyless Cosign and mirrors the same digest to Docker Hub. + +### Usage + +```yaml +name: Build + +on: + push: + branches: [main] + tags: ["v*.*.*"] + pull_request: + branches: [main] + schedule: + - cron: "17 4 * * 1" + workflow_dispatch: + +permissions: {} + +jobs: + image: + permissions: + contents: read + id-token: write + packages: write + uses: Think-Cube/workflows/.github/workflows/container-image.yml@v1.0.0 + with: + image-name: ansible + secrets: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} +``` + +The calling job must grant all three permissions. A reusable workflow cannot use more than its caller allows. + +### Inputs + +| Input | Default | Description | +|---|---|---| +| `image-name` | (required) | Image name without registry or namespace | +| `context` | `.` | Build context | +| `dockerfile` | `Dockerfile` | Path to the Dockerfile | +| `platforms` | `["linux/amd64", "linux/arm64"]` | JSON array of platforms to build | +| `smoke-test` | `tests/smoke.sh` | Script run with the image reference as its only argument | +| `trivy-severity` | `CRITICAL` | Severities that fail the build | +| `dockerhub-namespace` | `thinkcubedev` | Docker Hub namespace of the mirror | + +### Secrets + +| Secret | Description | +|---|---| +| `DOCKERHUB_USERNAME` | Docker Hub user. The mirror is skipped when it is empty. | +| `DOCKERHUB_TOKEN` | Docker Hub access token with read and write scope | + +GitHub Container Registry uses the job's `GITHUB_TOKEN`, so it needs no secret. + +### Tags + +| Event | Tags | +|---|---| +| Tag `v2.1.0` | `2.1.0`, `2.1`, `2`, `latest` | +| Push to `main` | `edge`, `sha-` | +| Schedule | `edge`, `edge-YYYYMMDD` | +| Pull request | Nothing is published | + +A release fails instead of overwriting a version that already exists in GitHub Container Registry. Scheduled runs build without cache so the image picks up current OS patches. + +### Verify a published image + +```bash +cosign verify ghcr.io/think-cube/: \ + --certificate-oidc-issuer https://token.actions.githubusercontent.com \ + --certificate-identity-regexp '^https://github\.com/Think-Cube/workflows/\.github/workflows/container-image\.yml@refs/tags/v.+$' +``` + +## Versioning + +Releases are tagged `vMAJOR.MINOR.PATCH`. Callers pin an exact tag, and Dependabot in the calling repository proposes upgrades. A new major version means callers must change their inputs, secrets or permissions. + +Actions inside the workflows are pinned to commit SHAs and updated by Dependabot. + +## License + +This project is licensed under the [MIT License](LICENSE). From 503838245308e9497de6a5a8e87670b5c3e3b4d6 Mon Sep 17 00:00:00 2001 From: Maciej Michalski Date: Mon, 16 Nov 2026 20:56:36 +0100 Subject: [PATCH 2/2] Fix shellcheck findings in container image workflow --- .github/workflows/container-image.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/container-image.yml b/.github/workflows/container-image.yml index ff8fe61..7942954 100644 --- a/.github/workflows/container-image.yml +++ b/.github/workflows/container-image.yml @@ -118,9 +118,9 @@ jobs: IMAGE_NAME: ${{ inputs.image-name }} PLATFORMS: ${{ inputs.platforms }} run: | - echo "ghcr=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/${IMAGE_NAME}" >> "$GITHUB_OUTPUT" - echo "platforms=$(jq -r 'join(",")' <<< "$PLATFORMS")" >> "$GITHUB_OUTPUT" { + echo "ghcr=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/${IMAGE_NAME}" + echo "platforms=$(jq -r 'join(",")' <<< "$PLATFORMS")" echo 'cache-from<> "$GITHUB_STEP_SUMMARY"