Skip to content

Commit e78a192

Browse files
Merge pull request #241 from cri-o/oci-artifacts
Add support for publishing CRI-O as OCI artifacts
2 parents dd35ae0 + 0e8576f commit e78a192

File tree

5 files changed

+174
-17
lines changed

5 files changed

+174
-17
lines changed

.github/workflows/obs.yml

+56
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,69 @@ jobs:
179179
build/bundle/*.sig
180180
build/bundle/*.cert
181181
182+
oci-artifacts-publish:
183+
name: oci-artifacts / publish / ${{ inputs.revision || 'main' }}
184+
runs-on: ubuntu-latest
185+
needs:
186+
- vars
187+
- bundle-test
188+
permissions:
189+
contents: read
190+
id-token: write
191+
packages: write
192+
steps:
193+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
194+
- uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
195+
if: ${{ inputs.skip-bundles == false && github.event_name != 'pull_request' }}
196+
with:
197+
registry: ghcr.io/cri-o
198+
username: cri-o
199+
password: ${{ secrets.GITHUB_TOKEN }}
200+
- uses: sigstore/cosign-installer@3454372f43399081ed03b604cb2d021dabca52bb # v3.8.2
201+
if: ${{ inputs.skip-bundles == false && github.event_name != 'pull_request' }}
202+
- uses: oras-project/setup-oras@5c0b487ce3fe0ce3ab0d034e63669e426e294e4d # v1.2.2
203+
if: ${{ inputs.skip-bundles == false && github.event_name != 'pull_request' }}
204+
with:
205+
url: https://github.com/oras-project/oras/releases/download/v1.3.0-beta.2/oras_1.3.0-beta.2_linux_amd64.tar.gz
206+
checksum: 3f4258fc0e8a97a2ad07ba01f2d132b3702b48d9d0ab58c5b3321c904a8a1c03
207+
- uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
208+
if: ${{ inputs.skip-bundles == false && github.event_name != 'pull_request' }}
209+
with:
210+
name: bundles-amd64
211+
path: build/bundle
212+
- uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
213+
if: ${{ inputs.skip-bundles == false && github.event_name != 'pull_request' }}
214+
with:
215+
name: bundles-arm64
216+
path: build/bundle
217+
- uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
218+
if: ${{ inputs.skip-bundles == false && github.event_name != 'pull_request' }}
219+
with:
220+
name: bundles-ppc64le
221+
path: build/bundle
222+
- uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
223+
if: ${{ inputs.skip-bundles == false && github.event_name != 'pull_request' }}
224+
with:
225+
name: bundles-s390x
226+
path: build/bundle
227+
- run: scripts/oci-artifacts
228+
if: ${{ inputs.skip-bundles == false && github.event_name != 'pull_request' }}
229+
env:
230+
ARCHIVE_PATH: ${{ needs.vars.outputs.archive_path }}
231+
COMMIT: ${{ needs.vars.outputs.commit }}
232+
GIT_ROOT: ${{ needs.vars.outputs.git_root }}
233+
PROJECT_TYPE: ${{ needs.vars.outputs.project_type }}
234+
PROJECT_VERSION: ${{ needs.vars.outputs.project_version }}
235+
VERSION: ${{ needs.vars.outputs.version }}
236+
182237
stage:
183238
runs-on: ubuntu-latest
184239
name: stage / ${{ inputs.revision || 'main' }}
185240
timeout-minutes: 240
186241
needs:
187242
- vars
188243
- bundles-publish
244+
- oci-artifacts-publish
189245
steps:
190246
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
191247
- run: scripts/obs

dependencies.yaml

+7-1
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,17 @@ dependencies:
105105
- name: bom
106106
version: v0.6.0
107107
refPaths:
108-
- path: scripts/bundle/build
108+
- path: scripts/helpers
109109
match: BOM_VERSION
110110
- path: .github/workflows/test.yml
111111
match: BOM_VERSION
112112

113+
- name: oras
114+
version: v1.3.0-beta.2
115+
refPaths:
116+
- path: .github/workflows/obs.yml
117+
match: oras/releases
118+
113119
- name: debian base
114120
version: bookworm-v1.0.4
115121
refPaths:

scripts/bundle/build

+4-10
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,12 @@ for FILE in "$TMP_BIN"/*; do
148148
fi
149149
done
150150

151-
# Install BOM
152-
BOM_VERSION=v0.6.0
153-
BOM="$GIT_ROOT/build/bom"
154-
curl_to "$BOM" \
155-
"https://github.com/kubernetes-sigs/bom/releases/download/$BOM_VERSION/bom-amd64-linux"
156-
chmod +x "$BOM"
151+
install_bom
157152

158153
# Create the SBOM
159154
pushd "$ARCHIVE_PATH"
160155
SPDX_FILE="$ARCHIVE.spdx"
161-
$BOM version
162-
$BOM generate \
156+
bom generate \
163157
-l Apache-2.0 \
164158
--name CRI-O \
165159
--namespace "https://storage.googleapis.com/cri-o/artifacts/$SPDX_FILE" \
@@ -179,8 +173,8 @@ rm -rf "$TMPDIR"
179173
echo "Testing archive"
180174
tar xf "$ARCHIVE"
181175
SPDX_PATH="$ARCHIVE_PATH/$SPDX_FILE"
182-
$BOM document outline "$SPDX_PATH"
183-
$BOM validate -e "$SPDX_PATH" -d "$CRIODIR"
176+
bom document outline "$SPDX_PATH"
177+
bom validate -e "$SPDX_PATH" -d "$CRIODIR"
184178
pushd "$TMPDIR"
185179
export DESTDIR=test/
186180
./install

scripts/helpers

+14-6
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,18 @@ install_osc() {
2929

3030
install_krel() {
3131
KREL_VERSION=v0.18.0
32-
BINARY=krel
33-
curl_retry https://github.com/kubernetes/release/releases/download/$KREL_VERSION/$BINARY-amd64-linux -o $BINARY
34-
chmod +x $BINARY
35-
sudo cp $BINARY /usr/local/bin
36-
rm $BINARY
37-
$BINARY version
32+
install_binary https://github.com/kubernetes/release/releases/download/$KREL_VERSION/krel-amd64-linux krel
33+
}
34+
35+
install_bom() {
36+
BOM_VERSION=v0.6.0
37+
install_binary https://github.com/kubernetes-sigs/bom/releases/download/$BOM_VERSION/bom-amd64-linux bom
38+
}
39+
40+
install_binary() {
41+
curl_retry "$1" -o "$2"
42+
chmod +x "$2"
43+
sudo cp "$2" /usr/local/bin
44+
rm "$2"
45+
"$2" version
3846
}

scripts/oci-artifacts

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
source "$(dirname "${BASH_SOURCE[0]}")"/vars
5+
6+
REGISTRY=ghcr.io/cri-o
7+
ARTIFACT=$REGISTRY/bundle
8+
9+
ARCHES=(amd64 arm64 ppc64le s390x)
10+
BUNDLE_ARTIFACT_TYPE=application/vnd.cncf.cri-o.bundle.v1
11+
SBOM_ARTIFACT_TYPE=application/vnd.cncf.spdx.file.v1
12+
SBOM_FILE=sbom.spdx
13+
14+
install_bom
15+
16+
pushd "$ARCHIVE_PATH"
17+
18+
VERSION=v$VERSION
19+
ANNOTATION_VERSION="org.cncf.cri-o.version=$VERSION"
20+
ANNOTATION_COMMIT="org.cncf.cri-o.commit=$COMMIT"
21+
ANNOTATION_BRANCH="org.cncf.cri-o.branch=$PROJECT_VERSION"
22+
23+
ARCHIVE_ID=$COMMIT
24+
TAG=${COMMIT:0:7}
25+
if [[ $PROJECT_TYPE == stable ]]; then
26+
ARCHIVE_ID="$VERSION"
27+
TAG="$VERSION"
28+
fi
29+
30+
ARTIFACTS=()
31+
for ARCH in "${ARCHES[@]}"; do
32+
TARBALL_DIR=cri-o
33+
TARBALL="$TARBALL_DIR.$ARCH.$ARCHIVE_ID.tar.gz"
34+
35+
mkdir "$ARCH"
36+
mv "$TARBALL" "$ARCH"
37+
mv "$TARBALL.spdx" "$ARCH/$SBOM_FILE"
38+
pushd "$ARCH"
39+
40+
tar xf "$TARBALL"
41+
bom validate -e "$SBOM_FILE" -d "$TARBALL_DIR"
42+
43+
ARGS=()
44+
while IFS= read -r -d '' -u 9; do
45+
MIME=$(file -b --mime-type "$REPLY")
46+
ARGS+=("$REPLY:$MIME")
47+
done 9< <(find "$TARBALL_DIR" -type f -exec printf '%s\0' {} +)
48+
49+
TARGET_ARTIFACT="$ARTIFACT:$TAG-$ARCH"
50+
ARTIFACTS+=("$TARGET_ARTIFACT")
51+
52+
# shellcheck disable=SC2068
53+
ARTIFACT_REF=$(oras push \
54+
-a "$ANNOTATION_VERSION" \
55+
-a "$ANNOTATION_COMMIT" \
56+
-a "$ANNOTATION_BRANCH" \
57+
--artifact-type "$BUNDLE_ARTIFACT_TYPE" \
58+
--artifact-platform "linux/$ARCH" \
59+
--format json \
60+
"$TARGET_ARTIFACT,$COMMIT-$ARCH,$VERSION-$ARCH,$PROJECT_VERSION-$ARCH" \
61+
${ARGS[@]} | jq -r .reference)
62+
cosign sign -y "$ARTIFACT_REF"
63+
64+
popd
65+
done
66+
67+
# Multi-arch: https://github.com/oras-project/oras/blob/main/docs/proposals/multi-arch-image-mgmt.md
68+
# shellcheck disable=SC2068
69+
oras manifest index create \
70+
-a "$ANNOTATION_VERSION" \
71+
-a "$ANNOTATION_COMMIT" \
72+
-a "$ANNOTATION_BRANCH" \
73+
"$ARTIFACT:$TAG,$COMMIT,$VERSION,$PROJECT_VERSION" \
74+
${ARTIFACTS[@]} | tee -a out
75+
MANIFEST_REF=$(sed -n 's/Digest: //p' out)
76+
cosign sign -y "$ARTIFACT@$MANIFEST_REF"
77+
78+
for ARCH in "${ARCHES[@]}"; do
79+
pushd "$ARCH"
80+
SBOM_REF=$(
81+
oras attach \
82+
-a "$ANNOTATION_VERSION" \
83+
-a "$ANNOTATION_COMMIT" \
84+
-a "$ANNOTATION_BRANCH" \
85+
--platform "linux/$ARCH" \
86+
--artifact-type "$SBOM_ARTIFACT_TYPE" \
87+
"$ARTIFACT:$TAG" \
88+
"$SBOM_FILE:application/spdx" \
89+
--format json | jq -r .reference
90+
)
91+
popd
92+
cosign sign -y "$SBOM_REF"
93+
done

0 commit comments

Comments
 (0)