Last active
June 26, 2024 00:38
-
-
Save sajayantony/0c9d6436c03d531b1bbebe43249381cf to your computer and use it in GitHub Desktop.
Script to help create a simple mult-arch artifact
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo 'linux/amd64' > README-linux-amd64.md | |
echo 'linux/arm64' > README-linux-arm64.md | |
# Push the artifact for amd64 and get the digest | |
DIGEST_LINUX_AMD64=$(oras push --oci-layout layout-dir README-linux-amd64.md --format go-template='{{.digest}}') | |
# Push the artifact for arm64 and get the digest | |
DIGEST_LINUX_ARM64=$(oras push --oci-layout layout-dir README-linux-arm64.md --format go-template='{{.digest}}') | |
# Fetch the manifest for amd64 | |
AMD64_MANIFEST=$(oras manifest fetch --oci-layout layout-dir@$DIGEST_LINUX_AMD64 --pretty --descriptor | jq '{ | |
mediaType: .mediaType, | |
size: .size, | |
digest: .digest, | |
platform: { | |
architecture: "amd64", | |
os: "linux" | |
} | |
}') | |
# Fetch the manifest for arm64 | |
ARM64_MANIFEST=$(oras manifest fetch --oci-layout layout-dir@$DIGEST_LINUX_ARM64 --pretty --descriptor | jq '{ | |
mediaType: .mediaType, | |
size: .size, | |
digest: .digest, | |
platform: { | |
architecture: "arm64", | |
os: "linux" | |
} | |
}') | |
IMAGE_INDEX=$(jq -n --argjson amd64 "$AMD64_MANIFEST" --argjson arm64 "$ARM64_MANIFEST" '{ | |
schemaVersion: 2, | |
mediaType: "application/vnd.oci.image.index.v1+json", | |
manifests: [$amd64, $arm64] | |
}') | |
# Save the image index to a file | |
echo "$IMAGE_INDEX" > image-index.json | |
# Push the image index to the registry | |
oras manifest push --oci-layout ./layout-dir:image-index image-index.json | |
# View the local manifest | |
oras manifest get --pretty --oci-layout ./layout-dir:image-index | |
# push the index and artifacts to the registry | |
oras cp --from-oci-layout ./layout-dir:image-index localhost:5000/artifact:index --to-plain-http | |
oras manifest get --plain-http localhost:5000/artifact:index |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@theory's script https://gist.github.com/theory/7dc164e5772cae652d838a1c508972ae#file-push_trunk