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

load-podman #32

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 13 additions & 2 deletions cmd/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
)

var (
platform, output string
push, loadDocker bool
platform, output string
push, loadDocker, loadPodman bool
)
var (
supportedPlatforms = []string{"linux/amd64", "linux/arm64"}
Expand Down Expand Up @@ -154,6 +154,16 @@ var OCICmd = &cobra.Command{

}

if loadPodman {
fmt.Println(styles.HighlightStyle.Render("Loading image to podman..."))
err = oci.LoadPodman(output+"/result", env.Name)
if err != nil {
fmt.Println(styles.ErrorStyle.Render("error:", err.Error()))
os.Exit(1)
}
fmt.Println(styles.SucessStyle.Render(fmt.Sprintf("Image %s loaded to podman", env.Name)))
}

if push {
fmt.Println(styles.HighlightStyle.Render("Pushing image to registry..."))
err = oci.Push(output+"/result", env.Name)
Expand Down Expand Up @@ -248,6 +258,7 @@ func init() {
OCICmd.Flags().StringVarP(&platform, "platform", "p", "", "The platform to build the image for")
OCICmd.Flags().StringVarP(&output, "output", "o", "", "location of the build artifacts generated")
OCICmd.Flags().BoolVarP(&loadDocker, "load-docker", "", false, "Load the image into docker daemon")
OCICmd.Flags().BoolVarP(&loadPodman, "load-podman", "", false, "Load the image into podman")
OCICmd.Flags().BoolVarP(&push, "push", "", false, "Push the image to the registry")

}
13 changes: 13 additions & 0 deletions pkg/oci/skopeo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ func LoadDocker(daemon, dir, imageName string) error {
return nil
}

// LoadPodman loads the image to the poadman
func LoadPodman(dir, imageName string) error {
cmd := exec.Command("nix", "run", "nixpkgs#skopeo", "--", "copy", "--insecure-policy", "dir:"+dir, "containers-storage:"+imageName)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
return err
}

return nil
}

// Push image to registry
func Push(dir, imageName string) error {
cmd := exec.Command("nix", "run", "nixpkgs#skopeo", "--", "copy", "--insecure-policy", "dir:"+dir, "docker://"+imageName)
Expand Down
Loading