-
Notifications
You must be signed in to change notification settings - Fork 182
Make cosa build
support building "ostree" artifact using podman/buildah
#4242
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
base: main
Are you sure you want to change the base?
Conversation
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.
Code Review
This pull request introduces support for building ostree
artifacts using podman/buildah, gated by the COREOS_ASSEMBLER_BUILD_OCI
environment variable. The changes also include optimizations for cosa import
when dealing with oci-archives and a necessary adjustment to ostree
ref creation. The implementation is solid, and I have a suggestion to enhance robustness in the modified code.
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.
Nice ! Minor comments.
It looks like the second commit message is missing a word?
I'm making another change here to build without the additional volume mounts. With that we can drophttps://github.com/coreos/fedora-coreos-config/pull/3628 |
# --force is needed for builds from cosa build-oci (using buildah) where | ||
# the ref seems to be already present in the repo. | ||
subprocess.check_call(['ostree', 'refs', '--repo', tmpd, refs[0], '--create', ref, '--force']) |
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.
I'm not sure this is needed. What we need to do is make our versions unique on every build. Right now it's just statically set.
So yeah. If you do consecutive container builds they are going to have conflicts, but we should make our tooling not have that problem.
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.
I was getting conflict on the first build itself.
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.
Weird.
Currently You can:
I'm kind of of the opinion we should change existing WDYT? |
Sounds good. I'll review when you're ready |
I have pushed it a separate commit here 9f09123 |
We can provide the same functionality with this new way. We can check if there are additional arguments except |
2fccb66
to
c1fb721
Compare
/gemini review |
cmd/build-with-buildah.go
Outdated
"-v", "/srv/tmp:/run/tmp", | ||
"-t", fmt.Sprintf("oci-archive:%s/out.ociarchive", tempdir), | ||
"src/config"} | ||
podmanCmd := []string{"/usr/lib/coreos-assembler/build-with-buildah.sh", fmt.Sprintf("%s/out.ociarchive", tempdir)} |
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.
/usr/lib/coreos-assembler/build-with-buildah.sh
I don't see this script added to this commit, but I will say at the same time that I did like it the way it was before with the entire command in this file :)
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.
Ah. Missed it when I renamed it.
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.
but I will say at the same time that I did like it the way it was before with the entire command in this file :)
The problem with those changes is that we might need to modify Containerfile to as you see in the related PR. This makes it the podman command from the Containerfiles's comments or the GH Actions to fails.
Is there any other way to run multiple command in the supermin vm?
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.
Removed the script and added all command in the go file.
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.
Code Review
This pull request introduces a new build path for cosa build
using buildah
, triggered by a new --with-buildah
flag or an environment variable. The changes include a new Go function to orchestrate the build, logic to switch to this new path, and an optimization for importing local OCI archives.
My review focuses on improving the Go code to follow language idioms and fixing a logic bug in how the new build path is triggered. The bug could cause command-line arguments to be silently ignored, leading to unexpected build behavior. The suggestions for the Go code aim to improve maintainability by using standard library functions for path manipulation.
mustEnvOption, ok := os.LookupEnv("COREOS_ASSEMBLER_BUILD_WITH_BUILDAH") | ||
// We don't expect any other arguments | ||
// Possible to make better by checking if '--native' in argv. | ||
return (len(argv) == 1 && argv[0] == "--with-buildah") || (ok && mustEnvOption == "1") |
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.
The current logic for determining whether to use the buildah path has a flaw. If the COREOS_ASSEMBLER_BUILD_WITH_BUILDAH
environment variable is set to 1
, mustBuildWithBuildah
will return true
even if other command-line arguments (like --force
) are provided. These arguments are then silently ignored because buildWithBuildah()
doesn't process them. This could lead to unexpected behavior.
The buildah path should only be taken if --with-buildah
is the sole argument, or if the environment variable is set and no arguments are provided. This aligns with the help text that states 'Cannot be used with other options'.
return (len(argv) == 1 && argv[0] == "--with-buildah") || (ok && mustEnvOption == "1") | |
return (len(argv) == 1 && argv[0] == "--with-buildah") || (ok && mustEnvOption == "1" && len(argv) == 0) |
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.
I think this is ok. Ignoring.
ehh. Like I said earlier, I actually think the existing behavior isn't ideal from a code organiziation perspective, but it is nice from a dev UX perspective. If we did try to keep at least the current default behavior I certainly wouldn't call out to the existing Again. I think we should bite the bullet and drop the current behavior IMO. |
/retest |
If build subcommand is called with `--native` flag, build ostree artifacts using buildah. Else, got the traditional way.
Import command can do a simple of ociarchive instead of importing each layer. Output of cosa build using podman/buildah is an ociarchive and this can be leveraged there.
Builds from cosa using podman/buildah seems to existing ref of the same name we create.
d490bc1
to
0dc9389
Compare
Changes in Containerfile fedora-coreos-config can be drop with this.
0dc9389
to
9223f47
Compare
--with-buildah Use the container runtime (buildah) to build ostree and container artifacts. | ||
Cannot be used with other options. |
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.
so what's weird here is we are adding to the documentation to the cmd-build
but this is an option src/cmd-build
doesn't actually support.
--with-buildah
is supported by cmd/build-container-native.go
and switched on at the cmd/coreos-assembler.go
level.
It's OK as a PoC to support it only in cmd/build-container-native.go
but also what about all of these other options?
For example, --versionary
is really useful in the context of making our versions unique on each build and --autolock=VERSION
is required for both bodhi testing and downstream for RHCOS multi-arch builds.
I think more likely what we'd need to do is do away with the switch that happens in cmd/coreos-assembler.go
and then just shell out here to cmd-supermin-run
based on --with-buildah
.
Of course, this could happen in a followup PR, but would probably be required before say we could switch any of our pipelines over to actually using this code.
OK yeah, this is somewhat my fault. But... yes we need at least the versionary bits and the autolock stuff. The latter would be obsoleted longer term once we move to hermetic builds in Konflux. The versionary bits happen quite early in |
Another big thing I think a goal once we've cut over is that |
--with-builda
flag is passed orCOREOS_ASSEMBLER_BUILD_WITH_BUILDAH=1
, build ostree artifacts using buildah. Else, got the traditional way.cosa import
rather than importing layer by layer.buildid
ref on importing ociarchiveWants: coreos/fedora-coreos-config#3628 (optional, if de96356 is acceptable)