Repository navigation
178 lines (155 loc) · 7.08 KB
/
Copy pathpush.yml
File metadata and controls
178 lines (155 loc) · 7.08 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
171
172
173
174
175
176
177
178
name: Push
on:
workflow_call:
inputs:
activitypub-private-tags:
description: ActivityPub Docker image tags for private registry
required: true
type: string
activitypub-public-tags:
description: ActivityPub Docker image tags for public registry
required: false
type: string
activitypub-public-labels:
description: ActivityPub Docker image labels for public registry
required: false
type: string
activitypub-migrations-private-tags:
description: ActivityPub Migrations Docker image tags for private registry
required: true
type: string
activitypub-migrations-public-tags:
description: ActivityPub Migrations Docker image tags for public registry
required: false
type: string
activitypub-migrations-public-labels:
description: ActivityPub Migrations Docker image tags for public registry
required: false
type: string
permissions:
id-token: write
packages: write
jobs:
push-main-images:
name: Push Docker Images
runs-on: ubuntu-latest
steps:
- name: Download ActivityPub image
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
with:
name: activitypub-amd64
path: /tmp
- name: Download Migrations image
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
with:
name: activitypub-migrations-amd64
path: /tmp
- name: Download arm64 GHCR digests
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
with:
name: arm64-ghcr-digests
path: /tmp/digests
- name: Authenticate with GCP
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3
id: gcp-auth
with:
token_format: access_token
workload_identity_provider: projects/687476608778/locations/global/workloadIdentityPools/github-oidc-activitypub/providers/github-provider-activitypub
service_account: cicd-activitypub-terraform@ghost-activitypub.iam.gserviceaccount.com
- name: Login to GCP Artifact Registry
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4
with:
registry: europe-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.gcp-auth.outputs.access_token }}
- name: Login to GitHub Container Registry
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4
- name: Push ActivityPub Docker image to private registry
run: |
docker load < /tmp/activitypub-amd64.tar
echo "${{ inputs.activitypub-private-tags }}" | while read -r tag; do
docker push $tag
done
- name: Push ActivityPub multi-arch image and manifest to public registry
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
env:
PRIVATE_TAGS: ${{ inputs.activitypub-private-tags }}
PUBLIC_TAGS: ${{ inputs.activitypub-public-tags }}
PUBLIC_LABELS: ${{ inputs.activitypub-public-labels }}
run: |
source_private=$(printf '%s\n' "$PRIVATE_TAGS" | awk 'NF { print; exit }')
[ -n "$source_private" ] || { echo "no source tag"; exit 1; }
amd64_digest=""
while IFS= read -r tag; do
[ -n "$tag" ] || continue
docker tag "$source_private" "$tag"
push_output=$(docker push "$tag")
echo "$push_output"
d=$(echo "$push_output" | grep -oE 'digest: sha256:[a-f0-9]+' | awk '{print $2}' | tail -1)
[ -n "$d" ] && amd64_digest="$d"
done <<< "$PUBLIC_TAGS"
[ -n "$amd64_digest" ] || { echo "failed to capture amd64 digest"; exit 1; }
arm64_digest=$(cat /tmp/digests/activitypub-arm64.digest)
[ -n "$arm64_digest" ] || { echo "missing arm64 digest"; exit 1; }
tag_args=()
while IFS= read -r tag; do
[ -n "$tag" ] || continue
tag_args+=(-t "$tag")
done <<< "$PUBLIC_TAGS"
annotation_args=()
while IFS= read -r label; do
[ -n "$label" ] || continue
annotation_args+=(--annotation "index:$label")
done <<< "$PUBLIC_LABELS"
docker buildx imagetools create "${tag_args[@]}" "${annotation_args[@]}" \
"ghcr.io/tryghost/activitypub@${amd64_digest}" \
"ghcr.io/tryghost/activitypub@${arm64_digest}"
- name: Push Migrations Docker image to private registry
run: |
docker load < /tmp/activitypub-migrations-amd64.tar
echo "${{ inputs.activitypub-migrations-private-tags }}" | while read -r tag; do
docker push $tag
done
- name: Push Migrations multi-arch image and manifest to public registry
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
env:
PRIVATE_TAGS: ${{ inputs.activitypub-migrations-private-tags }}
PUBLIC_TAGS: ${{ inputs.activitypub-migrations-public-tags }}
PUBLIC_LABELS: ${{ inputs.activitypub-migrations-public-labels }}
run: |
source_private=$(printf '%s\n' "$PRIVATE_TAGS" | awk 'NF { print; exit }')
[ -n "$source_private" ] || { echo "no source tag"; exit 1; }
amd64_digest=""
while IFS= read -r tag; do
[ -n "$tag" ] || continue
docker tag "$source_private" "$tag"
push_output=$(docker push "$tag")
echo "$push_output"
d=$(echo "$push_output" | grep -oE 'digest: sha256:[a-f0-9]+' | awk '{print $2}' | tail -1)
[ -n "$d" ] && amd64_digest="$d"
done <<< "$PUBLIC_TAGS"
[ -n "$amd64_digest" ] || { echo "failed to capture amd64 digest"; exit 1; }
arm64_digest=$(cat /tmp/digests/activitypub-migrations-arm64.digest)
[ -n "$arm64_digest" ] || { echo "missing arm64 digest"; exit 1; }
tag_args=()
while IFS= read -r tag; do
[ -n "$tag" ] || continue
tag_args+=(-t "$tag")
done <<< "$PUBLIC_TAGS"
annotation_args=()
while IFS= read -r label; do
[ -n "$label" ] || continue
annotation_args+=(--annotation "index:$label")
done <<< "$PUBLIC_LABELS"
docker buildx imagetools create "${tag_args[@]}" "${annotation_args[@]}" \
"ghcr.io/tryghost/activitypub-migrations@${amd64_digest}" \
"ghcr.io/tryghost/activitypub-migrations@${arm64_digest}"