forked from Soju06/codex-lb
-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (118 loc) · 4.76 KB
/
Copy pathinternal-image.yml
File metadata and controls
133 lines (118 loc) · 4.76 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
name: Internal Image
on:
push:
branches:
- main
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.sha }}
cancel-in-progress: false
permissions:
contents: read
packages: write
jobs:
publish:
name: Build and publish CHEK image
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
persist-credentials: false
- name: Set up QEMU
uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c
- name: Log in to GHCR
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Refuse to overwrite immutable tag
env:
IMAGE_REF: ghcr.io/${{ github.repository }}:sha-${{ github.sha }}
run: |
if docker buildx imagetools inspect "${IMAGE_REF}" >/dev/null 2>inspect-error.log; then
echo "::error::Immutable image tag already exists: ${IMAGE_REF}"
exit 1
fi
if ! grep -Eiq 'manifest unknown|name unknown|not found' inspect-error.log; then
cat inspect-error.log >&2
echo "::error::Unable to prove immutable image tag is absent"
exit 1
fi
- name: Extract image metadata
id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=sha,prefix=sha-,format=long
- name: Build and push image
id: build
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a
with:
context: .
file: Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=codex-lb-internal
cache-to: type=gha,mode=max,scope=codex-lb-internal
- name: Verify immutable image receipt
id: receipt
env:
IMAGE_REF: ghcr.io/${{ github.repository }}:sha-${{ github.sha }}
EXPECTED_DIGEST: ${{ steps.build.outputs.digest }}
run: |
set -euo pipefail
[[ "${EXPECTED_DIGEST}" =~ ^sha256:[0-9a-f]{64}$ ]]
manifest=$(docker buildx imagetools inspect "${IMAGE_REF}")
actual_digest=$(awk '$1 == "Digest:" {print $2; exit}' <<<"${manifest}")
[[ "${actual_digest}" == "${EXPECTED_DIGEST}" ]]
grep -q 'Platform:[[:space:]]*linux/amd64' <<<"${manifest}"
grep -q 'Platform:[[:space:]]*linux/arm64' <<<"${manifest}"
receipt_path="${RUNNER_TEMP}/codex-lb-image-receipt.json"
python3 - "${receipt_path}" <<'PY'
import json
import os
import sys
with open(sys.argv[1], "w", encoding="utf-8") as handle:
json.dump(
{
"schema": "qk_codex_lb_internal_image_receipt_v1",
"repository": os.environ["GITHUB_REPOSITORY"],
"source_sha": os.environ["GITHUB_SHA"],
"image_ref": os.environ["IMAGE_REF"],
"digest": os.environ["EXPECTED_DIGEST"],
"platforms": ["linux/amd64", "linux/arm64"],
},
handle,
separators=(",", ":"),
sort_keys=True,
)
handle.write("\n")
PY
receipt_sha256=$(shasum -a 256 "${receipt_path}" | awk '{print $1}')
{
echo "source_digest=${actual_digest}"
echo "receipt_path=${receipt_path}"
echo "receipt_sha256=${receipt_sha256}"
} >> "${GITHUB_OUTPUT}"
- name: Upload immutable image receipt
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
with:
name: codex-lb-image-receipt-${{ github.sha }}
path: ${{ steps.receipt.outputs.receipt_path }}
if-no-files-found: error
retention-days: 30
- name: Dispatch exact image to ops-bootstrap
uses: peter-evans/repository-dispatch@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0
with:
token: ${{ secrets.GH_PAT }}
repository: chekdata/ops-bootstrap
event-type: codex-lb-image-published
client-payload: >-
{"source_sha":"${{ github.sha }}","source_digest":"${{ steps.build.outputs.digest }}","receipt_sha256":"${{ steps.receipt.outputs.receipt_sha256 }}"}