mirror of
https://github.com/cyclotruc/gitingest.git
synced 2026-04-28 11:41:35 +00:00
99 lines
3.3 KiB
YAML
99 lines
3.3 KiB
YAML
name: Build & Push Container
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- 'main'
|
|
tags:
|
|
- '*'
|
|
merge_group:
|
|
pull_request_target:
|
|
types: [labeled, synchronize, reopened, ready_for_review, opened]
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
PUSH_FROM_PR: >-
|
|
${{ github.event_name == 'pull_request_target' &&
|
|
(
|
|
contains(github.event.pull_request.labels.*.name, 'push-container') ||
|
|
contains(github.event.pull_request.labels.*.name, 'deploy-pr-temp-env')
|
|
)
|
|
}}
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
docker-build:
|
|
name: "GHCR"
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
attestations: write
|
|
id-token: write
|
|
steps:
|
|
- name: Harden the runner (Audit all outbound calls)
|
|
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
|
|
|
- name: Set current timestamp
|
|
id: vars
|
|
run: |
|
|
echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
|
|
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Log in to the Container registry
|
|
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Docker Meta
|
|
id: meta
|
|
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
|
|
with:
|
|
images: |
|
|
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
flavor: |
|
|
latest=false
|
|
tags: |
|
|
type=ref,event=branch,branch=main
|
|
type=ref,event=branch,branch=main,suffix=-${{ steps.vars.outputs.sha_short }}-${{ steps.vars.outputs.timestamp }}
|
|
type=pep440,pattern={{raw}}
|
|
type=ref,event=pr,suffix=-${{ steps.vars.outputs.sha_short }}-${{ steps.vars.outputs.timestamp }}
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
|
|
id: push
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64, linux/arm64
|
|
push: ${{ github.event_name != 'pull_request_target' || env.PUSH_FROM_PR == 'true' }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Generate artifact attestation
|
|
if: github.event_name != 'pull_request_target' || env.PUSH_FROM_PR == 'true'
|
|
uses: actions/attest-build-provenance@e8998f949152b193b063cb0ec769d69d929409be # v2.4.0
|
|
with:
|
|
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
|
|
subject-digest: ${{ steps.push.outputs.digest }}
|
|
push-to-registry: true
|