-
Notifications
You must be signed in to change notification settings - Fork 5
170 lines (154 loc) · 6.13 KB
/
Copy pathdocker-publish.yml
File metadata and controls
170 lines (154 loc) · 6.13 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: docker publish
on:
push:
branches: [main]
tags: [v*.*.*] # 手動で作成した時用
pull_request:
workflow_call:
inputs:
tag-name:
required: true
type: string
env:
IMAGE_NAME: om
# バージョン指定
# renovate: datasource=github-releases depName=docker/buildx
BUILDX_VERSION: v0.25.0
jobs:
env:
# release-please によるコミットの時は workflow_call でのみ実行する
if: ${{ !( github.workflow == 'docker publish' && startsWith(github.event.head_commit.message, 'release:') && github.event.head_commit.author.name == 'github-actions[bot]' ) }}
runs-on: ubuntu-latest
outputs:
REGISTRY_IMAGE: ${{ steps.lowercase.outputs.REGISTRY_IMAGE }}
PUSH: ${{ github.event_name != 'pull_request' }}
steps:
- id: lowercase
run: |
registory_image='ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}'
echo "REGISTRY_IMAGE=${registory_image@L}" >> $GITHUB_OUTPUT
meta:
needs: [env]
runs-on: ubuntu-latest
outputs:
version: ${{ steps.metadata.outputs.version}}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.labels.outputs.labels }}
json: ${{ steps.metadata.outputs.json }}
steps:
- name: Docker Metadata
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
id: metadata
with:
images: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}},value=${{ inputs.tag-name }}
type=semver,pattern={{major}}.{{minor}},value=${{ inputs.tag-name }}
type=semver,pattern={{major}},value=${{ inputs.tag-name }},enable=${{ !(startsWith(github.ref, 'refs/tags/v0.') || startsWith(inputs.tag-name, 'v0.')) }}
type=edge,branch=main
- name: Delete org.opencontainers.image.licenses label
id: labels
run: |
cat << EOS >> "$GITHUB_OUTPUT"
labels<<EOF
$(echo '${{ steps.metadata.outputs.labels }}' | sed '/^org.opencontainers.image.licenses=/d')
EOF
EOS
docker-publish:
permissions:
packages: write
needs: [env, meta]
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
on: ubuntu-latest
- platform: linux/arm64
on: ubuntu-24.04-arm
runs-on: ${{ matrix.on }}
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
with:
version: ${{ env.BUILDX_VERSION }}
- name: Log in to the Container registry
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: build-push
name: Build and push by digest
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
platforms: ${{ matrix.platform }}
labels: ${{ needs.meta.outputs.labels }}
outputs: type=image,name=${{ needs.env.outputs.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=${{ fromJson(needs.env.outputs.PUSH) }}
cache-from: type=gha,scope=buildkit-${{ matrix.platform }}
cache-to: type=gha,scope=buildkit-${{ matrix.platform }},mode=max
- if: ${{ github.event_name != 'pull_request' }}
name: Display image digest
env:
NAME: ${{ fromJson(steps.build-push.outputs.metadata)['image.name'] }}
DIGEST: ${{ fromJson(steps.build-push.outputs.metadata)['containerimage.digest'] }}
run: |
name=$(cut --delimiter=',' --fields=1 <<< "$NAME")
echo '```' >> $GITHUB_STEP_SUMMARY
echo "$name@$DIGEST" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- id: export-digest
if: ${{ fromJson(needs.env.outputs.PUSH) }}
name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build-push.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- id: prepare
if: ${{ steps.export-digest.conclusion == 'success' }}
name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_OUTPUT
- if: ${{ steps.export-digest.conclusion == 'success' }}
name: Upload digest
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: digests-${{ steps.prepare.outputs.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
permissions:
packages: write
needs: [env, meta, docker-publish]
if: ${{ fromJson(needs.env.outputs.PUSH) }}
runs-on: ubuntu-latest
steps:
- name: Download digests
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Log in to the Container registry
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create manifest list and push
working-directory: /tmp/digests
shell: bash -xe {0}
env:
DOCKER_METADATA_OUTPUT_JSON: ${{ needs.meta.outputs.json }}
run: |
docker buildx imagetools create $(jq -cr '.tags | map("--tag=" + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ needs.env.outputs.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ needs.env.outputs.REGISTRY_IMAGE }}:${{ needs.meta.outputs.version }}