-
Notifications
You must be signed in to change notification settings - Fork 1
244 lines (218 loc) · 9.03 KB
/
Copy pathdocker-build-release.yml
File metadata and controls
244 lines (218 loc) · 9.03 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
name: Build and Release Docker Container
# Only one can run at a time
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
on:
push:
tags:
- 'v*'
branches:
- main
workflow_dispatch:
inputs:
tag:
description: 'Docker image tag (e.g., v0.1.0)'
required: true
type: string
workflow_call:
inputs:
tag:
description: 'Docker image tag (e.g., v0.1.0)'
required: true
type: string
secrets:
INFRA_GH_TOKEN:
required: true
permissions:
contents: write
packages: write
id-token: write
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for middleware
id: meta_middleware
uses: docker/metadata-action@v5
with:
images: ghcr.io/chainsafe/canton-middleware
tags: |
type=ref,event=tag
type=sha,prefix=main-,enable={{is_default_branch}}
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=${{ inputs.tag }},enable=${{ inputs.tag != '' }}
- name: Extract metadata for ERC20 API
id: meta_api
uses: docker/metadata-action@v5
with:
images: ghcr.io/chainsafe/canton-erc20-api
tags: |
type=ref,event=tag
type=sha,prefix=main-,enable={{is_default_branch}}
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=${{ inputs.tag }},enable=${{ inputs.tag != '' }}
- name: Extract metadata for indexer
id: meta_indexer
uses: docker/metadata-action@v5
with:
images: ghcr.io/chainsafe/canton-indexer
tags: |
type=ref,event=tag
type=sha,prefix=main-,enable={{is_default_branch}}
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=${{ inputs.tag }},enable=${{ inputs.tag != '' }}
- name: Build and push Middlewware Docker Image
uses: docker/build-push-action@v5
with:
context: .
file: ./cmd/relayer/Dockerfile
push: true
tags: ${{ steps.meta_middleware.outputs.tags }}
labels: ${{ steps.meta_middleware.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
- name: Build and push ERC20 API Server Docker Image
uses: docker/build-push-action@v5
with:
context: .
file: ./cmd/api-server/Dockerfile
push: true
tags: ${{ steps.meta_api.outputs.tags }}
labels: ${{ steps.meta_api.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
- name: Build and push Indexer Docker Image
uses: docker/build-push-action@v5
with:
context: .
file: ./cmd/indexer/Dockerfile
push: true
tags: ${{ steps.meta_indexer.outputs.tags }}
labels: ${{ steps.meta_indexer.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
open-devnet-pr:
name: Open devnet deploy PR
needs: build-and-push
runs-on: ubuntu-latest
# Devnet continuously tracks main: deploy the main-<sha> image on every
# direct push to main. Release builds (workflow_call with a version tag)
# and manual dispatches build images only — mainnet promotion is manual.
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && inputs.tag == ''
steps:
- name: Compute image tag
id: version
run: |
# Must match the main-<sha> tag produced by docker/metadata-action above
VERSION="main-${GITHUB_SHA::7}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Checkout infra-kubernetes
uses: actions/checkout@v4
with:
repository: ChainSafe/infra-kubernetes
token: ${{ secrets.INFRA_GH_TOKEN }}
ref: main
# Each service maps to a Helm values file in infra-kubernetes whose
# top-level key matches the Helm release name. Add a service here to
# have it bumped and deployed to devnet automatically on every main push.
- name: Update image tags for all services
env:
VERSION: ${{ steps.version.outputs.version }}
DIR: definitions/canton/validator-dev1
run: |
while IFS='|' read -r key file; do
[ -z "$key" ] && continue
echo "Bumping ${key} -> ${VERSION} in ${file}"
yq e ".[\"${key}\"].image.tag = env(VERSION)" -i "${DIR}/${file}"
done <<'EOF'
canton-middleware-api|canton-middleware-api-values.yml
canton-indexer|canton-indexer-values.yml
canton-middleware|canton-middleware-values.yml
EOF
- name: Create signed commit and open PR
env:
VERSION: ${{ steps.version.outputs.version }}
GH_TOKEN: ${{ secrets.INFRA_GH_TOKEN }}
DIR: definitions/canton/validator-dev1
REPO: ChainSafe/infra-kubernetes
SOURCE_REPO: ${{ github.repository }}
SOURCE_SHA: ${{ github.sha }}
run: |
FILES=(
canton-middleware-api-values.yml
canton-indexer-values.yml
canton-middleware-values.yml
)
BRANCH="cd/devnet-canton-services-${VERSION}"
COMMIT_MSG="chore(devnet): deploy canton services ${VERSION}"
# Get current HEAD SHA of main
HEAD_SHA=$(gh api repos/${REPO}/git/ref/heads/main --jq '.object.sha')
# Create branch pointing at main HEAD (no-op if already exists)
gh api repos/${REPO}/git/refs \
--method POST \
--field ref="refs/heads/${BRANCH}" \
--field sha="${HEAD_SHA}" > /dev/null 2>&1 || true
# Get current branch HEAD SHA
BRANCH_SHA=$(gh api repos/${REPO}/git/ref/heads/${BRANCH} --jq '.object.sha')
# Skip if every file on the branch already has this version (idempotent re-run)
ALL_MATCH=true
for f in "${FILES[@]}"; do
KEY="${f%-values.yml}"
BRANCH_TAG=$(gh api "repos/${REPO}/contents/${DIR}/${f}?ref=${BRANCH}" \
-H "Accept: application/vnd.github.raw" 2>/dev/null \
| yq e ".[\"${KEY}\"].image.tag" - 2>/dev/null || echo "")
[ "$BRANCH_TAG" = "$VERSION" ] || ALL_MATCH=false
done
if [ "$ALL_MATCH" = "true" ]; then
echo "Branch already at tag ${VERSION} for all services, ensuring auto-merge"
gh pr merge --auto --squash --repo "${REPO}" "${BRANCH}" 2>/dev/null || true
exit 0
fi
# Build the GraphQL additions array: one entry per file, base64-encoded
# (no line wrapping, Linux base64). Commits via createCommitOnBranch are
# automatically signed by GitHub (Verified).
ADDITIONS="[]"
for f in "${FILES[@]}"; do
CONTENTS=$(base64 -w0 "${DIR}/${f}")
ADDITIONS=$(jq -nc --argjson acc "$ADDITIONS" \
--arg path "${DIR}/${f}" --arg contents "$CONTENTS" \
'$acc + [{path: $path, contents: $contents}]')
done
jq -nc \
--arg repo "$REPO" --arg branch "$BRANCH" --arg oid "$BRANCH_SHA" \
--arg msg "$COMMIT_MSG" --argjson additions "$ADDITIONS" \
'{
query: "mutation($repo: String!, $branch: String!, $oid: GitObjectID!, $msg: String!, $additions: [FileAddition!]!) { createCommitOnBranch(input: { branch: { repositoryNameWithOwner: $repo, branchName: $branch }, message: { headline: $msg }, fileChanges: { additions: $additions }, expectedHeadOid: $oid }) { commit { url } } }",
variables: { repo: $repo, branch: $branch, oid: $oid, msg: $msg, additions: $additions }
}' | gh api graphql --input -
# Open PR and enable auto-merge
PR_BODY=$(cat <<EOF
Automated continuous deployment to \`validator-dev1\`.
Bumps \`canton-middleware-api\`, \`canton-indexer\` and \`canton-middleware\` image tags to \`${VERSION}\`.
Source: [${SOURCE_REPO}@${SOURCE_SHA:0:7}](https://github.com/${SOURCE_REPO}/commit/${SOURCE_SHA})
EOF
)
gh pr create \
--repo "${REPO}" \
--title "${COMMIT_MSG}" \
--body "${PR_BODY}" \
--base main \
--head "${BRANCH}" \
|| { echo "PR already exists for this branch, skipping"; exit 0; }
gh pr merge --auto --squash --repo "${REPO}" "${BRANCH}"