| 1 |
name: Docker |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
on: |
| 9 |
workflow_dispatch: |
| 10 |
push: |
| 11 |
branches: [ "master" ] |
| 12 |
|
| 13 |
tags: [ 'v*.*.*' ] |
| 14 |
pull_request: |
| 15 |
branches: [ "master" ] |
| 16 |
|
| 17 |
env: |
| 18 |
|
| 19 |
REGISTRY: ghcr.io |
| 20 |
|
| 21 |
jobs: |
| 22 |
build: |
| 23 |
|
| 24 |
runs-on: ubuntu-latest |
| 25 |
permissions: |
| 26 |
contents: read |
| 27 |
packages: write |
| 28 |
|
| 29 |
|
| 30 |
id-token: write |
| 31 |
|
| 32 |
steps: |
| 33 |
- name: Setup environment |
| 34 |
shell: bash |
| 35 |
run: | |
| 36 |
printf >> "${GITHUB_ENV}" -- '%s=%s\n' \ |
| 37 |
'IMAGE_NAME' "${GITHUB_REPOSITORY@L}" |
| 38 |
|
| 39 |
- name: Checkout repository |
| 40 |
uses: actions/checkout@v6 |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
- name: Install cosign |
| 45 |
if: github.event_name != 'pull_request' |
| 46 |
uses: sigstore/cosign-installer@v3 |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
- name: Set up QEMU |
| 51 |
uses: docker/setup-qemu-action@v3 |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
- name: Set up Docker Buildx |
| 57 |
uses: docker/setup-buildx-action@v3 |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
- name: Log into registry ${{ env.REGISTRY }} |
| 62 |
if: github.event_name != 'pull_request' |
| 63 |
uses: docker/login-action@v3 |
| 64 |
with: |
| 65 |
registry: ${{ env.REGISTRY }} |
| 66 |
username: ${{ github.actor }} |
| 67 |
password: ${{ secrets.GITHUB_TOKEN }} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
- name: Extract Docker metadata |
| 72 |
id: meta |
| 73 |
uses: docker/metadata-action@v5 |
| 74 |
with: |
| 75 |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
- name: Build and push Docker image |
| 80 |
id: build-and-push |
| 81 |
uses: docker/build-push-action@v6 |
| 82 |
with: |
| 83 |
context: . |
| 84 |
platforms: linux/arm64,linux/amd64 |
| 85 |
pull: true |
| 86 |
push: ${{ github.event_name != 'pull_request' }} |
| 87 |
tags: ${{ steps.meta.outputs.tags }} |
| 88 |
labels: ${{ steps.meta.outputs.labels }} |
| 89 |
cache-from: type=gha |
| 90 |
cache-to: type=gha,mode=max |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
- name: Sign the published Docker image |
| 98 |
if: ${{ github.event_name != 'pull_request' }} |
| 99 |
env: |
| 100 |
|
| 101 |
TAGS: ${{ steps.meta.outputs.tags }} |
| 102 |
DIGEST: ${{ steps.build-and-push.outputs.digest }} |
| 103 |
|
| 104 |
|
| 105 |
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} |