| 1 |
name: Docker |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
on: |
| 9 |
push: |
| 10 |
branches: ["main"] |
| 11 |
|
| 12 |
tags: ["v*.*.*"] |
| 13 |
pull_request: |
| 14 |
branches: ["main"] |
| 15 |
|
| 16 |
env: |
| 17 |
|
| 18 |
REGISTRY: ghcr.io |
| 19 |
|
| 20 |
IMAGE_NAME: ${{ github.repository }} |
| 21 |
|
| 22 |
jobs: |
| 23 |
build: |
| 24 |
runs-on: ubuntu-latest |
| 25 |
permissions: |
| 26 |
contents: read |
| 27 |
packages: write |
| 28 |
|
| 29 |
|
| 30 |
id-token: write |
| 31 |
|
| 32 |
steps: |
| 33 |
- name: Checkout repository |
| 34 |
uses: actions/checkout@v3 |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
- name: Install cosign |
| 39 |
if: github.event_name != 'pull_request' |
| 40 |
uses: sigstore/[email protected] |
| 41 |
with: |
| 42 |
cosign-release: "v2.4.3" |
| 43 |
|
| 44 |
|
| 45 |
- name: Setup Docker buildx |
| 46 |
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
- name: Log into registry ${{ env.REGISTRY }} |
| 51 |
if: github.event_name != 'pull_request' |
| 52 |
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c |
| 53 |
with: |
| 54 |
registry: ${{ env.REGISTRY }} |
| 55 |
username: ${{ github.actor }} |
| 56 |
password: ${{ secrets.GITHUB_TOKEN }} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
- name: Extract Docker metadata |
| 61 |
id: meta |
| 62 |
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 |
| 63 |
with: |
| 64 |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
- name: Build and push Docker image |
| 69 |
id: build-and-push |
| 70 |
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a |
| 71 |
with: |
| 72 |
context: . |
| 73 |
push: ${{ github.event_name != 'pull_request' }} |
| 74 |
tags: ${{ steps.meta.outputs.tags }} |
| 75 |
labels: ${{ steps.meta.outputs.labels }} |
| 76 |
cache-from: type=gha |
| 77 |
cache-to: type=gha,mode=max |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
- name: Sign the published Docker image |
| 85 |
if: ${{ github.event_name != 'pull_request' }} |
| 86 |
env: |
| 87 |
COSIGN_EXPERIMENTAL: "true" |
| 88 |
|
| 89 |
|
| 90 |
run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign --yes {}@${{ steps.build-and-push.outputs.digest }} |