mirror of
https://github.com/bookorbit/bookorbit.git
synced 2026-11-03 00:11:37 -06:00
dc8f5822f6
Bumps the github-actions group with 2 updates in the / directory: [actions/checkout](https://github.com/actions/checkout) and [EnricoMi/publish-unit-test-result-action](https://github.com/enricomi/publish-unit-test-result-action). Updates `actions/checkout` from 6.0.3 to 7.0.0 - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/df4cb1c069e1874edd31b4311f1884172cec0e10...9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0) Updates `EnricoMi/publish-unit-test-result-action` from 2.23.0 to 2.24.0 - [Release notes](https://github.com/enricomi/publish-unit-test-result-action/releases) - [Commits](https://github.com/enricomi/publish-unit-test-result-action/compare/c950f6fb443cb5af20a377fd0dfaa78838901040...d0a4676d0e0b938bc201470d88276b7c74c712b3) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: 7.0.0 dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: EnricoMi/publish-unit-test-result-action dependency-version: 2.24.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
260 lines
9.7 KiB
YAML
260 lines
9.7 KiB
YAML
name: Container Image
|
|
run-name: >-
|
|
${{ github.event_name == 'workflow_run' && format('Image - {0} ({1})', github.event.workflow_run.head_commit.message, github.event.workflow_run.head_branch) || format('Image - {0}', github.ref_name) }}
|
|
|
|
on:
|
|
# Break-glass: bypasses CI/E2E gate. Use only when CI is broken and a hotfix image is urgently needed.
|
|
workflow_dispatch:
|
|
inputs:
|
|
force_rebuild:
|
|
description: Rebuild even if image for this SHA already exists in GHCR
|
|
type: boolean
|
|
default: false
|
|
workflow_run:
|
|
workflows: ["CI"]
|
|
types: [completed]
|
|
branches: [main]
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.sha }}
|
|
cancel-in-progress: true
|
|
|
|
permissions:
|
|
actions: read
|
|
contents: read
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
jobs:
|
|
# Main push path: resolve context once, then build multi-arch natively in parallel.
|
|
prepare:
|
|
name: Resolve Build Context
|
|
if: >
|
|
github.event_name == 'workflow_dispatch' ||
|
|
(github.event_name == 'workflow_run' &&
|
|
github.event.workflow_run.conclusion == 'success' &&
|
|
github.event.workflow_run.event == 'push')
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 5
|
|
permissions:
|
|
contents: read
|
|
packages: read
|
|
outputs:
|
|
source_sha: ${{ steps.ctx.outputs.source_sha }}
|
|
source_sha_short: ${{ steps.ctx.outputs.source_sha_short }}
|
|
update_main: ${{ steps.ctx.outputs.update_main }}
|
|
skip_build: ${{ steps.ctx.outputs.skip_build }}
|
|
steps:
|
|
- name: Resolve build context
|
|
id: ctx
|
|
shell: bash
|
|
env:
|
|
EVENT_NAME: ${{ github.event_name }}
|
|
GH_REF: ${{ github.ref }}
|
|
WORKFLOW_RUN_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
|
|
GH_SHA: ${{ github.sha }}
|
|
GH_TOKEN: ${{ github.token }}
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
FORCE_REBUILD: ${{ inputs.force_rebuild }}
|
|
run: |
|
|
if [[ "$EVENT_NAME" == "workflow_dispatch" && "$GH_REF" != "refs/heads/main" ]]; then
|
|
echo "::error::workflow_dispatch is only supported from main."
|
|
exit 1
|
|
fi
|
|
if [[ "$EVENT_NAME" == "workflow_run" ]]; then
|
|
SOURCE_SHA="$WORKFLOW_RUN_HEAD_SHA"
|
|
echo "update_main=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
SOURCE_SHA="$GH_SHA"
|
|
echo "update_main=false" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
SOURCE_SHA_SHORT="${SOURCE_SHA:0:12}"
|
|
echo "source_sha=${SOURCE_SHA}" >> "$GITHUB_OUTPUT"
|
|
echo "source_sha_short=${SOURCE_SHA_SHORT}" >> "$GITHUB_OUTPUT"
|
|
IMAGE_LOWER=$(echo "${IMAGE_NAME}" | tr '[:upper:]' '[:lower:]')
|
|
HTTP_STATUS_SHORT=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
-H "Authorization: Bearer ${GH_TOKEN}" \
|
|
-H "Accept: application/vnd.oci.image.index.v1+json" \
|
|
"https://ghcr.io/v2/${IMAGE_LOWER}/manifests/sha-${SOURCE_SHA_SHORT}")
|
|
HTTP_STATUS_FULL=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
-H "Authorization: Bearer ${GH_TOKEN}" \
|
|
-H "Accept: application/vnd.oci.image.index.v1+json" \
|
|
"https://ghcr.io/v2/${IMAGE_LOWER}/manifests/sha-${SOURCE_SHA}")
|
|
if [[ ("$HTTP_STATUS_SHORT" == "200" || "$HTTP_STATUS_FULL" == "200") && "${FORCE_REBUILD}" != "true" ]]; then
|
|
echo "Image sha-${SOURCE_SHA_SHORT} already exists in GHCR, skipping rebuild."
|
|
echo "skip_build=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "skip_build=false" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
build-amd64:
|
|
name: Build and Push amd64
|
|
needs: [prepare]
|
|
if: needs.prepare.outputs.skip_build != 'true'
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 45
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
outputs:
|
|
digest: ${{ steps.build.outputs.digest }}
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
|
with:
|
|
ref: ${{ needs.prepare.outputs.source_sha }}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ secrets.GHCR_TOKEN != '' && secrets.GHCR_TOKEN || github.token }}
|
|
|
|
- name: Build image
|
|
id: build
|
|
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile
|
|
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
|
|
platforms: linux/amd64
|
|
build-args: APP_VERSION=sha-${{ needs.prepare.outputs.source_sha_short }}
|
|
cache-from: type=gha,scope=container-image-yml-amd64
|
|
cache-to: type=gha,mode=max,scope=container-image-yml-amd64
|
|
|
|
- name: Scan image with Trivy
|
|
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
|
|
env:
|
|
TRIVY_PLATFORM: linux/amd64
|
|
with:
|
|
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build.outputs.digest }}
|
|
format: table
|
|
vuln-type: os,library
|
|
severity: CRITICAL,HIGH
|
|
ignore-unfixed: true
|
|
exit-code: "1"
|
|
|
|
build-arm64:
|
|
name: Build and Push arm64
|
|
needs: [prepare]
|
|
if: needs.prepare.outputs.skip_build != 'true'
|
|
runs-on: ubuntu-24.04-arm
|
|
timeout-minutes: 45
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
outputs:
|
|
digest: ${{ steps.build.outputs.digest }}
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
|
with:
|
|
ref: ${{ needs.prepare.outputs.source_sha }}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ secrets.GHCR_TOKEN != '' && secrets.GHCR_TOKEN || github.token }}
|
|
|
|
- name: Build image
|
|
id: build
|
|
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile
|
|
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
|
|
platforms: linux/arm64
|
|
build-args: APP_VERSION=sha-${{ needs.prepare.outputs.source_sha_short }}
|
|
cache-from: type=gha,scope=container-image-yml-arm64
|
|
cache-to: type=gha,mode=max,scope=container-image-yml-arm64
|
|
|
|
- name: Scan image with Trivy
|
|
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
|
|
env:
|
|
TRIVY_PLATFORM: linux/arm64
|
|
with:
|
|
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build.outputs.digest }}
|
|
format: table
|
|
vuln-type: os,library
|
|
severity: CRITICAL,HIGH
|
|
ignore-unfixed: true
|
|
exit-code: "1"
|
|
|
|
merge-manifest:
|
|
name: Merge and Push Multi-Arch Manifest
|
|
needs: [prepare, build-amd64, build-arm64]
|
|
if: needs.prepare.outputs.skip_build != 'true'
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 10
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
steps:
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ secrets.GHCR_TOKEN != '' && secrets.GHCR_TOKEN || github.token }}
|
|
|
|
- name: Create SHA manifest
|
|
shell: bash
|
|
env:
|
|
REGISTRY: ${{ env.REGISTRY }}
|
|
IMAGE: ${{ env.IMAGE_NAME }}
|
|
SHA_SHORT: ${{ needs.prepare.outputs.source_sha_short }}
|
|
AMD64_DIGEST: ${{ needs.build-amd64.outputs.digest }}
|
|
ARM64_DIGEST: ${{ needs.build-arm64.outputs.digest }}
|
|
run: |
|
|
FULL_IMAGE="${REGISTRY}/${IMAGE}"
|
|
docker buildx imagetools create \
|
|
--tag "${FULL_IMAGE}:sha-${SHA_SHORT}" \
|
|
"${FULL_IMAGE}@${AMD64_DIGEST}" \
|
|
"${FULL_IMAGE}@${ARM64_DIGEST}"
|
|
|
|
- name: Update main tag
|
|
if: needs.prepare.outputs.update_main == 'true'
|
|
shell: bash
|
|
env:
|
|
REGISTRY: ${{ env.REGISTRY }}
|
|
IMAGE: ${{ env.IMAGE_NAME }}
|
|
AMD64_DIGEST: ${{ needs.build-amd64.outputs.digest }}
|
|
ARM64_DIGEST: ${{ needs.build-arm64.outputs.digest }}
|
|
run: |
|
|
FULL_IMAGE="${REGISTRY}/${IMAGE}"
|
|
docker buildx imagetools create \
|
|
--tag "${FULL_IMAGE}:main" \
|
|
"${FULL_IMAGE}@${AMD64_DIGEST}" \
|
|
"${FULL_IMAGE}@${ARM64_DIGEST}"
|
|
|
|
- name: Inspect SHA manifest
|
|
shell: bash
|
|
env:
|
|
REGISTRY: ${{ env.REGISTRY }}
|
|
IMAGE: ${{ env.IMAGE_NAME }}
|
|
SHA_SHORT: ${{ needs.prepare.outputs.source_sha_short }}
|
|
run: docker buildx imagetools inspect "${REGISTRY}/${IMAGE}:sha-${SHA_SHORT}"
|