-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (84 loc) · 3.01 KB
/
docker-push.yaml
File metadata and controls
94 lines (84 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
---
name: push docker image
on:
workflow_call:
inputs:
runner:
description: runner name
type: string
default: ubuntu-latest
required: false
registry:
description: registry url
type: string
default: ghcr.io
required: false
path:
description: image path in registry
type: string
required: false
tags:
description: image tag - default sha
type: string
default: ${{ github.sha }}
required: false
file:
description: path to Dockerfile
type: string
required: false
context:
description: build context - default .
type: string
default: .
required: false
jobs:
docker-push:
runs-on: ${{ inputs.runner }}
permissions:
contents: read
packages: write
id-token: write
env:
image-path: ${{ inputs.registry }}/${{ github.repository }}${{ inputs.path && format('/{0}', inputs.path) || '' }}
steps:
# https://github.com/marketplace/actions/harden-runner
- name: harden runner
uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
with:
egress-policy: audit
# https://github.com/marketplace/actions/checkout
- name: checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
# https://github.com/marketplace/actions/docker-setup-buildx
- name: setup docker buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
# https://github.com/marketplace/actions/cosign-installer
- name: setup cosign
uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0
# https://github.com/marketplace/actions/docker-login
- name: log into registry
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ${{ inputs.registry }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# https://github.com/marketplace/actions/docker-metadata-action
- name: extract metadata for docker
id: meta
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
with:
images: ${{ env.image-path }}
tags: ${{ inputs.tags }}
# https://github.com/marketplace/actions/build-and-push-docker-images
- name: build and push docker image
id: build-and-push
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
with:
push: true
file: ${{ inputs.file }}
context: ${{ inputs.context }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# https://github.com/sigstore/cosign
- name: sign the published docker image
run: cosign sign --yes ${{ env.image-path }}@${{ steps.build-and-push.outputs.digest }}