-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add initial Builder: oci-import
support
#20
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# https://github.com/docker-library/official-images/blob/fe9c059402181390eac083cbdd7229b5d123236e/library/ubuntu but intentionally slimmed down (just "latest" on one architecture, no email addresses) | ||
|
||
Maintainers: Tomáš Virtus (@woky), Cristóvão Cordeiro (@cjdcordeiro) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UTF-8 support established |
||
GitRepo: https://git.launchpad.net/cloud-images/+oci/ubuntu-base | ||
GitCommit: fa42be9027eccb928a1f0f43d95ffd9a45d36737 | ||
Builder: oci-import | ||
File: index.json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this necessary? It has to be https://github.com/opencontainers/image-spec/blob/main/image-layout.md There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The If See also https://github.com/docker-library/meta-scripts/pull/20/files#diff-a64244565ecee6714e591bafe1b0771f08c5217287fb88a6ff0e9f1457eb8ac3R296-R299 for where in this PR those get "upgraded" into a correct (Technically, the code I've written there to "upgrade" that case to |
||
|
||
# 20240111 (jammy) | ||
Tags: 22.04, jammy-20240111, jammy, latest | ||
Architectures: amd64 | ||
Directory: oci | ||
# https://git.launchpad.net/cloud-images/+oci/ubuntu-base/tree/?h=dist-jammy-amd64-20240111-e6e3490a | ||
amd64-GitFetch: refs/tags/dist-jammy-amd64-20240111-e6e3490a | ||
amd64-GitCommit: e6e3490ad3f524ccaa072edafe525f8ca8ac5490 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -265,10 +265,76 @@ def build_command: | |
] | join("\n") | ||
elif $builder == "oci-import" then | ||
[ | ||
"git init temp", # TODO figure out a good, safe place to temporary "git init"?? | ||
@sh "git -C temp fetch \(.source.entry.GitRepo) \(.source.entry.GitCommit): || git -C temp fetch \(.source.entry.GitRepo) \(.source.entry.GitFetch):", | ||
@sh "git -C temp checkout -q \(.source.entry.GitCommit)", | ||
# TODO something clever, especially to deal with "index.json" vs not-"index.json" (possibly using "jq" to either synthesize/normalize to what we actually need it to be for "crane push temp/dir \(.build.img)") | ||
# initialize "~/.cache/bashbrew/git" | ||
#"gitCache=\"$(bashbrew cat --format '{{ gitCache }}' <(echo 'Maintainers: empty hack (@example)'))\"", | ||
# https://github.com/docker-library/bashbrew/blob/5152c0df682515cbe7ac62b68bcea4278856429f/cmd/bashbrew/git.go#L52-L80 | ||
"export BASHBREW_CACHE=\"${BASHBREW_CACHE:-${XDG_CACHE_HOME:-$HOME/.cache}/bashbrew}\"", | ||
"gitCache=\"$BASHBREW_CACHE/git\"", | ||
"git init --bare \"$gitCache\"", | ||
"_git() { git -C \"$gitCache\" \"$@\"; }", | ||
"_git config gc.auto 0", | ||
# "bashbrew fetch" but in Bash (because we have bashbrew, but not the library file -- we could synthesize a library file instead, but six of one half a dozen of another) | ||
@sh "_commit() { _git rev-parse \(.source.entry.GitCommit + "^{commit}"); }", | ||
@sh "if ! _commit &> /dev/null; then _git fetch \(.source.entry.GitRepo) \(.source.entry.GitCommit + ":") || _git fetch \(.source.entry.GitFetch + ":"); fi", | ||
"_commit", | ||
|
||
# TODO figure out a good, safe place to store our temporary build/push directory (maybe this is fine? we do it for buildx build too) | ||
"mkdir temp", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
local tmpdir=$(umask 077 && d=ztemp-doi-bb-$$-$RANDOM; mkdir "$d" && echo "$d") There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is, but |
||
# https://github.com/docker-library/bashbrew/blob/5152c0df682515cbe7ac62b68bcea4278856429f/cmd/bashbrew/git.go#L140-L147 (TODO "bashbrew context" ?) | ||
@sh "_git archive --format=tar \(.source.entry.GitCommit + ":" + (.source.entry.Directory | if . == "." then "" else . + "/" end)) | tar -xvC temp", | ||
|
||
# validate oci-layout file (https://github.com/docker-library/bashbrew/blob/4e0ea8d8aba49d54daf22bd8415fabba65dc83ee/cmd/bashbrew/oci-builder.go#L104-L112) | ||
@sh "jq -s \(" | ||
if length != 1 then | ||
error(\"unexpected 'oci-layout' document count: \" + length) | ||
else .[0] end | ||
| if .imageLayoutVersion != \"1.0.0\" then | ||
error(\"unsupported imageLayoutVersion: \" + .imageLayoutVersion) | ||
else . end | ||
" | unindent_and_decomment_jq(3)) temp/oci-layout > /dev/null", | ||
|
||
# https://github.com/docker-library/bashbrew/blob/4e0ea8d8aba49d54daf22bd8415fabba65dc83ee/cmd/bashbrew/oci-builder.go#L116 | ||
if .source.entry.File != "index.json" then | ||
@sh "jq -s \("{ schemaVersion: 2, manifests: . }") \("./" + .source.entry.File) > temp/index.json" | ||
else empty end, | ||
|
||
@sh "jq -s \(" | ||
if length != 1 then | ||
error(\"unexpected 'index.json' document count: \" + length) | ||
else .[0] end | ||
|
||
# https://github.com/docker-library/bashbrew/blob/4e0ea8d8aba49d54daf22bd8415fabba65dc83ee/cmd/bashbrew/oci-builder.go#L117-L127 | ||
| if .schemaVersion != 2 then | ||
error(\"unsupported schemaVersion: \" + .schemaVersion) | ||
else . end | ||
# TODO check .mediaType ? (technically optional, but does not have to be *and* shouldn't be); https://github.com/moby/buildkit/issues/4595 | ||
| if .manifests | length != 1 then | ||
error(\"expected only one manifests entry, not \" + (.manifests | length)) | ||
else . end | ||
|
||
| .manifests[0] |= ( | ||
# https://github.com/docker-library/bashbrew/blob/4e0ea8d8aba49d54daf22bd8415fabba65dc83ee/cmd/bashbrew/oci-builder.go#L135-L144 | ||
if .mediaType != \"application/vnd.oci.image.manifest.v1+json\" then | ||
error(\"unsupported descriptor mediaType: \" + .mediaType) | ||
else . end | ||
# TODO validate .digest somehow (`crane validate`? see below) - would also be good to validate all descriptors recursively (not sure if `crane push` does that) | ||
| if .size < 0 then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is a size of zero valid? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's valid for the descriptor format, but in this case it would mean the image manifest itself is zero bytes, which isn't valid. |
||
error(\"invalid descriptor size: \" + .size) | ||
else . end | ||
|
||
# purge maintainer-provided URLs / annotations (https://github.com/docker-library/bashbrew/blob/4e0ea8d8aba49d54daf22bd8415fabba65dc83ee/cmd/bashbrew/oci-builder.go#L146-L147) | ||
| del(.annotations, .urls) | ||
|
||
# inject our annotations | ||
| .annotations = \(build_annotations(.source.entry.GitRepo) | @json) | ||
) | ||
" | unindent_and_decomment_jq(3)) temp/index.json > temp/index.json.new", | ||
"mv temp/index.json.new temp/index.json", | ||
|
||
# TODO consider / check what "crane validate" does and if it would be appropriate here | ||
|
||
# TODO generate SBOM? ... somehow | ||
|
||
empty | ||
] | join("\n") | ||
else | ||
|
@@ -289,7 +355,11 @@ def push_command: | |
empty | ||
] | join("\n") | ||
elif $builder == "oci-import" then | ||
"TODO" | ||
[ | ||
@sh "crane push --index temp \(.build.img)", | ||
"rm -rf temp", | ||
empty | ||
] | join("\n") | ||
else | ||
error("unknown/unimplemented Builder: \($builder)") | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With docker-library/official-images@795e049, this is now even safer as part of our tests because this exact
buildId
will never be officially built. 😄 😇