Repository navigation
235 lines (225 loc) · 8.94 KB
/
Copy pathimage.yml
File metadata and controls
235 lines (225 loc) · 8.94 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
name: Container image
on:
push:
pull_request:
workflow_dispatch:
permissions:
contents: read
# Serialize main releases without cancelling an active deployment. GitHub does not
# guarantee commit order; explicit current-main checks reject stale reruns.
concurrency:
group: image-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
env:
IMAGE: ghcr.io/pocketcontext/taskcontext
jobs:
# Every branch and pull request: build for the runner's architecture and run the image.
check:
strategy:
fail-fast: false
matrix:
include:
- arch: amd
runner: ubuntu-24.04
- arch: arm
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Runtime safety checks
run: python3 tests/entrypoint.py
- name: Install packaged CLI for container checks
run: |
python3 -m venv "$RUNNER_TEMP/context-client"
"$RUNNER_TEMP/context-client/bin/pip" install .
echo "$RUNNER_TEMP/context-client/bin" >> "$GITHUB_PATH"
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: Build the image
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
load: true
tags: taskcontext:ci
build-args: REVISION=${{ github.sha }}
provenance: false
# Reuse this architecture's validated build cache during publication.
cache-from: type=gha,scope=${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=${{ matrix.arch }}
- name: Show the image
run: |
docker image inspect taskcontext:ci --format 'ID={{.Id}} digests={{json .RepoDigests}}'
docker run --rm --entrypoint sh taskcontext:ci -c 'set -eu; litestream version; pocketcontext --version; cat /app/POCKETCONTEXT_VERSION; find /app /usr/local/bin -type f | sort; test ! -e /app/pb_hooks/.gitkeep'
- name: Startup errors for missing configuration
run: python3 docker/smoke.py config --image taskcontext:ci
- name: Smoke test
run: python3 docker/smoke.py smoke --image taskcontext:ci
- name: Restore drill
run: python3 docker/smoke.py restore --image taskcontext:ci
- name: Primary object storage and frozen recovery
run: python3 docker/object_storage_smoke.py --image taskcontext:ci
# Application validation runs once on every event, including pull requests.
tests:
uses: ./.github/workflows/test.yml
permissions:
contents: read
# Each architecture is built on its own runner and pushed by digest, under no tag, so that two runs
# close together cannot mix their halves in one manifest.
build:
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
needs:
- check
- tests
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
include:
- arch: arm
platform: linux/arm64
runner: ubuntu-24.04-arm
- arch: amd
platform: linux/amd64
runner: ubuntu-24.04
runs-on: ${{ matrix.runner }}
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: Build and push by digest
id: build
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
platforms: ${{ matrix.platform }}
build-args: REVISION=${{ github.sha }}
outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true
provenance: false
cache-from: type=gha,scope=${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=${{ matrix.arch }}
- name: Export digest
env:
DIGEST: ${{ steps.build.outputs.digest }}
run: |
test -n "$DIGEST"
mkdir -p /tmp/digests
touch "/tmp/digests/${DIGEST#sha256:}"
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: digests-${{ matrix.arch }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
# One imagetools call creates both tags from the digests of this run.
manifest:
needs:
- build
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
contents: read
packages: write
steps:
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: Require current main revision
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
head=$(gh api "repos/$GITHUB_REPOSITORY/git/ref/heads/main" --jq '.object.sha')
if [[ ! "$head" =~ ^[0-9a-f]{40}$ || "$head" != "$GITHUB_SHA" ]]; then
echo 'Refusing stale release: workflow revision is not current main.' >&2
exit 1
fi
- name: Create and push the manifest list
working-directory: /tmp/digests
run: |
set -- *
echo "digests of this run: $*"
test "$#" -eq 2
sources=""
for digest in "$@"; do
sources="$sources $IMAGE@sha256:$digest"
done
# shellcheck disable=SC2086 # one argument per digest
docker buildx imagetools create \
--tag "$IMAGE:latest" \
--tag "$IMAGE:sha-${GITHUB_SHA::7}" \
--tag "$IMAGE:sha-$GITHUB_SHA" \
$sources
- name: Show what was published
run: docker buildx imagetools inspect "$IMAGE:latest"
deploy:
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && vars.CONTEXT_DEPLOY_PAUSED != 'true' && vars.COLORS_PROFILE != ''
needs:
- manifest
runs-on: ubuntu-24.04
timeout-minutes: 30
permissions:
contents: read
environment:
name: ${{ vars.COLORS_PROFILE }}
# Serialize rather than cancel: interrupting a deploy midway is worse than making the next one wait.
concurrency:
group: deploy-${{ vars.COLORS_PROFILE }}
cancel-in-progress: false
steps:
- name: Require current main revision
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
head=$(gh api "repos/$GITHUB_REPOSITORY/git/ref/heads/main" --jq '.object.sha')
if [[ ! "$head" =~ ^[0-9a-f]{40}$ || "$head" != "$GITHUB_SHA" ]]; then
echo 'Refusing stale release: workflow revision is not current main.' >&2
exit 1
fi
- name: Deploy via SSH
env:
# Only the key is a secret. The address and user are variables, so the logs stay readable.
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SERVER_IP: ${{ vars.SERVER_IP }}
SERVER_USER: ${{ vars.SERVER_USER }}
SSH_KNOWN_HOSTS: ${{ vars.SSH_KNOWN_HOSTS }}
run: |
mkdir -p ~/.ssh
# shellcheck disable=SC2046
eval $(ssh-agent -s)
echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
# Pinned by ONCE at provisioning time, not scanned here. Fail closed.
if [ -z "$SSH_KNOWN_HOSTS" ]; then
echo "SSH_KNOWN_HOSTS is unset - configure the deployment environment before releasing" >&2
exit 1
fi
printf '%s\n' "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
# A ping, not a command: the PocketDeploy key deploys every host it owns.
# It resolves latest to a digest; the workflow does not attest the live source revision.
ssh -T -o BatchMode=yes -o StrictHostKeyChecking=yes "$SERVER_USER@$SERVER_IP" < /dev/null
- name: Verify public health
run: |
# /up executes a database query, so HTTP 200 also checks database availability.
curl --fail --silent --show-error \
--connect-timeout 10 --max-time 20 \
--retry 12 --retry-delay 5 --retry-max-time 180 --retry-all-errors \
https://tasks.pocketcontext.com/up