Skip to content
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 convert command using bib #58

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

germag
Copy link
Collaborator

@germag germag commented Jul 5, 2024

Add convert command that uses bootc image builder (bib) to create disk images

It's marked as draft because it requires some refactoring to cache the results. And complete the AMI options
The bib doc (https://github.com/osbuild/bootc-image-builder?tab=readme-ov-file#%EF%B8%8F-cloud-uploaders) show how to pass some of the AWS configuration using env vars and the aws directory:

  -v $HOME/.aws:/root/.aws:ro \
  --env AWS_PROFILE=default \
$ cat aws.secrets
AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

..
 --env-file=aws.secrets \
..

So, I'm not sure if adding a generic --env-file or more specific ones: --aws-env-vars and --aws-cfg-dir

I think there is a bug in osbuild, the export function (that calls "cp --reflink=auto ...") returns an error if stdin is not connected to the container, that is the reason --quiet shows an error even after succeeding, and for some reason that error doesn't happen if podman machine uses virtiofsd.

@vrothberg
Copy link
Member

I'd be tempted to ignore the AWS-specific features. I am sure there AWS-specific CLI tools which can do that already, so just converting to an AMI checks the box for me.

@germag
Copy link
Collaborator Author

germag commented Jul 8, 2024

I'd be tempted to ignore the AWS-specific features. I am sure there AWS-specific CLI tools which can do that already, so just converting to an AMI checks the box for me.

Do you mean also removing --aws-ami-name, --aws-bucket, and --aws-region ?

@vrothberg
Copy link
Member

Do you mean also removing --aws-ami-name, --aws-bucket, and --aws-region ?

For now, yes. Let's focus on converting first. AWS integration is up to debate IMO.

@germag
Copy link
Collaborator Author

germag commented Jul 8, 2024

Do you mean also removing --aws-ami-name, --aws-bucket, and --aws-region ?

For now, yes. Let's focus on converting first. AWS integration is up to debate IMO.

I almost forgot, at DevConf.cz I talked to @ondrejbudai, and he told me that he intends to use podman-bootc convert to test boot-image-builder as part of their CI/CD. That is the reason behind the PODMAN_BOOTC_BIB_IMAGE env var, so maybe we can add a PODMAN_BOOTC_BIB_EXTRA_ARGS env var so they can pass any arguments even if we don't support it (it will not work for -v, --env and --env-file, tho)

@vrothberg
Copy link
Member

SGTM 👍

cmd/convert.go Outdated Show resolved Hide resolved
@rhatdan
Copy link
Member

rhatdan commented Jul 8, 2024

If we are going to support uploads, I would prefer these options to become more generic.
--aws-ami-name, --aws-bucket, and --aws-region ?

I would figure users would want similar support for Azure and Google Cloud ...

@germag
Copy link
Collaborator Author

germag commented Jul 8, 2024

If we are going to support uploads, I would prefer these options to become more generic. --aws-ami-name, --aws-bucket, and --aws-region ?

I would figure users would want similar support for Azure and Google Cloud ...

I'm worried about an explosion of options, maybe instead of podman-bootc --format ami|qcow2|etc ... we need to do something like:

podman-bootc convert-to ami --name --bucket --reagion ...

so each "format" is a sub-command with its own options if it's needed, o none like

podman-bootc convert-to qcow2 ...

@cgwalters
Copy link
Contributor

This strongly relates to https://gitlab.com/fedora/bootc/tracker/-/issues/2 which argues that in a nutshell:

  • bootc-image-builder becomes bootc-sdk
  • podman-bootc becomes a thin wrapper to execute code in bootc-sdk

In this world it's actually bootc-sdk that has sub-verbs, not the tool here.

@germag
Copy link
Collaborator Author

germag commented Jul 9, 2024

This strongly relates to https://gitlab.com/fedora/bootc/tracker/-/issues/2 which argues that in a nutshell:

* bootc-image-builder becomes bootc-sdk

* podman-bootc becomes a thin wrapper to execute code in bootc-sdk

In this world it's actually bootc-sdk that has sub-verbs, not the tool here.

Agreed, but in the meantime we need to do something here to support bib. I think going to a sub-command per format is nicer from a UI perspective.

I still need to understand how the sdk will work, I thought it will be more like a library, in any case I agree that podma-bootc should be a wrapper around it

@vrothberg
Copy link
Member

I still need to understand how the sdk will work, I thought it will be more like a library, in any case I agree that podma-bootc should be a wrapper around it

👍 podman-bootc convert is something we need short term. The SDK idea needs more cooking beyond August.

@germag
Copy link
Collaborator Author

germag commented Jul 9, 2024

  • Removed all the AMI specific options
  • Read an env var PODMAN_BOOTC_BIB_EXTRA for additional arguments for BIB (should I also add that for podman?)
  • It uses the BIB defined in the bootc.diskimage-builder label, if present

Although I prefer podman-bootc convert-to <format> than podman-bootc convert --format <format> I think we can go with this I change that later

Add convert command that uses bootc image builder (bib)
to create disk images

Signed-off-by: German Maglione <[email protected]>
RootCmd.AddCommand(convertCmd)
convertCmd.Flags().BoolVar(&quiet, "quiet", false, "Suppress output from disk image creation")
convertCmd.Flags().StringVar(&options.Config, "config", "", "Image builder config file")
convertCmd.Flags().StringVar(&options.Output, "output", ".", "output directory (default \".\")")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
convertCmd.Flags().StringVar(&options.Output, "output", ".", "output directory (default \".\")")
convertCmd.Flags().StringVar(&options.Output, "output", ".", "output directory")

Copy link
Member

Choose a reason for hiding this comment

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

To avoid it being displayed twice.


_, err = os.Stat(buildOption.Config)
if err != nil {
return fmt.Errorf("config file %s: %w", buildOption.Config, err)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("config file %s: %w", buildOption.Config, err)
return fmt.Errorf("config file %q: %w", buildOption.Config, err)

func Build(ctx context.Context, user user.User, imageNameOrId string, quiet bool, buildOption BuildOption) error {
outputInfo, err := os.Stat(buildOption.Output)
if err != nil {
return fmt.Errorf("output directory %s: %w", buildOption.Output, err)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("output directory %s: %w", buildOption.Output, err)
return fmt.Errorf("output directory %q: %w", buildOption.Output, err)

BibExtraArgs []string
}

func Build(ctx context.Context, user user.User, imageNameOrId string, quiet bool, buildOption BuildOption) error {
Copy link
Member

Choose a reason for hiding this comment

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

I think we should error out early here when --output or --config haven't been set.

For the config, we could consider creating an empty temp file and pass that on?

}

if !outputInfo.IsDir() {
return fmt.Errorf("%s is not a directory ", buildOption.Output)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("%s is not a directory ", buildOption.Output)
return fmt.Errorf("%q is not a directory ", buildOption.Output)

Copy link

@cdrage cdrage left a comment

Choose a reason for hiding this comment

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

Awesome work! 🚀

// the image
convertCmd.Flags().StringVar(&options.Filesystem, "filesystem", "", "Overrides the root filesystem (e.g. xfs, btrfs, ext4)")
// Corresponds to bib '--type', using '--format' to be consistent with podman
convertCmd.Flags().StringVar(&options.Format, "format", "qcow2", "Disk image type (ami, anaconda-iso, iso, qcow2, raw, vmdk) [default: qcow2]")
Copy link

Choose a reason for hiding this comment

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

should iso be dropped as it's an alias for anaconda-iso?

Copy link

Choose a reason for hiding this comment

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


func bibArguments(imageNameOrId string, buildOption BuildOption) []string {
args := []string{
"--local", // we pull the image if necessary, so don't pull it from a registry
Copy link

Choose a reason for hiding this comment

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

--local is always true now and is being deprecated, so no need for this.

},
{
Source: "/var/lib/containers/storage",
Destination: "/var/lib/containers/storage",
Copy link

Choose a reason for hiding this comment

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

I'm assuming that this command is always running in sudo / root and we shouldn't use ~/.local/share/containers/storage/ right?

This would cause an issue if a user did podman pull not sudo podman pull before running podman-bootc.

Unsure to be honest how this should be worked around / I guess we assume that podman-bootc is always running privileged?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we assume that podman-bootc is always running privileged?

No; we assume the container is running privileged inside podman machine.

@vrothberg
Copy link
Member

I'd still shoot for a convert command, see https://issues.redhat.com/browse/BIFROST-353

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants