Skip to content

Commit

Permalink
load-podman
Browse files Browse the repository at this point in the history
Signed-off-by: Horiodino <[email protected]>
  • Loading branch information
Horiodino committed Jun 17, 2024
1 parent b28bba5 commit fe1b9a0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
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

0 comments on commit fe1b9a0

Please sign in to comment.