Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/cmd-build-with-buildah
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,20 @@ build_with_buildah() {
fi
fi

# Here we call prepare_git_artifacts just for its git logic, We don't
# actually care about the JSON file; the source of truth is in the labels.
prepare_git_artifacts src/config "${tempdir}/coreos-assembler-config-git.json"
source=$(jq -r .git.origin "${tempdir}/coreos-assembler-config-git.json")
commit=$(jq -r .git.commit "${tempdir}/coreos-assembler-config-git.json")
rm -f "${tempdir}/coreos-assembler-config-git.json"

# For the source: check if there's only one remote, if so use it with get-url
# For revision: rev-parse
Comment on lines +141 to +142
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These comments are a bit confusing as they describe the logic within prepare_git_artifacts, which has already been executed. They don't seem to apply to the buildah build command that follows. Removing them would improve the script's clarity.

set -- build --security-opt=label=disable --cap-add=all --device /dev/fuse \
--build-arg-file "$argsfile" -v "$(realpath "${tempdir}/src")":/run/src \
--build-arg VERSION="${VERSION}"
--build-arg VERSION="${VERSION}" \
--label org.opencontainers.image.source="${source}" \
--label org.opencontainers.image.revision="${commit}"

# XXX: Temporary hack until we have https://github.com/coreos/rpm-ostree/pull/5454
# which would allow us to fold this back into the build process.
Expand Down
21 changes: 20 additions & 1 deletion src/cmd-import
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def generate_build_meta(tmp_oci_archive, tmp_oci_manifest, metadata, ostree_comm
created_timestamp = parse_timestamp(metadata['Created'])
arch = get_basearch()

return {
meta = {
'ostree-commit': ostree_commit,
'ostree-version': buildid,
'buildid': buildid,
Expand All @@ -145,6 +145,25 @@ def generate_build_meta(tmp_oci_archive, tmp_oci_manifest, metadata, ostree_comm
},
}

# proxy build repo and commit to the standard cosa key
source = metadata.get('Labels', {}).get('org.opencontainers.image.source')
commit = metadata.get('Labels', {}).get('org.opencontainers.image.revision')
Comment on lines +149 to +150
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To avoid calling metadata.get('Labels', {}) twice and to improve readability, you can store the Labels dictionary in a variable first.

Suggested change
source = metadata.get('Labels', {}).get('org.opencontainers.image.source')
commit = metadata.get('Labels', {}).get('org.opencontainers.image.revision')
labels = metadata.get('Labels', {})
source, commit = labels.get('org.opencontainers.image.source'), labels.get('org.opencontainers.image.revision')

if source and commit:
meta['coreos-assembler.container-config-git'] = {
'origin': source,
'commit': commit,
}

# add a reference to ourselves as well
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the comment about this from cmd-build. For some reason it makes it a little more clear to me where the information is being sourced from:

# And the build information about our container, if we are executing
# from a container.                                                 

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will tweak in the next patch set.

try:
with open('/cosa/coreos-assembler-git.json') as f:
cosa_git = json.load(f)
meta['coreos-assembler.container-image-git'] = cosa_git['git']
except FileNotFoundError:
pass

return meta


def finalize_build(builds, build_meta, tmp_oci_archive, tmp_oci_manifest, tmp_lockfile):
buildid = build_meta['buildid']
Expand Down
Loading