Skip to content

Commit

Permalink
Generate copy images script
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Sep 29, 2024
1 parent f42c604 commit e766832
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions pkg/cmds/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ mkdir -p images
buf.WriteRune('\n')
buf.WriteString(`tar -czvf images.tar.gz images
`)
err = os.WriteFile(filepath.Join(outdir, "export-images.sh"), buf.Bytes(), 0o644)
err = os.WriteFile(filepath.Join(outdir, "export-images.sh"), buf.Bytes(), 0o755)
if err != nil {
return err
}
Expand Down Expand Up @@ -183,7 +183,46 @@ tar -zxvf $TARBALL
buf.WriteString("$REGISTRY/" + ref.Repository + ":" + ref.Tag)
buf.WriteRune('\n')
}
err = os.WriteFile(filepath.Join(outdir, "import-images.sh"), buf.Bytes(), 0o644)
err = os.WriteFile(filepath.Join(outdir, "import-images.sh"), buf.Bytes(), 0o755)
if err != nil {
return err
}

buf.Reset()
buf.WriteString(`#!/bin/bash
set -x
TARBALL=${1:-}
REGISTRY=${2:-}
tar -zxvf $TARBALL
`)
for _, img := range images {
// crane push images/cluster-ui.tar $REGISTRY/cluster-ui:0.4.16
ref, err := name.ParseReference(img)
if err != nil {
return err
}
if ref.Tag == "" {
return fmt.Errorf("image %s has no tag", img)
}

buf.WriteString("crane cp")
if nondistro {
buf.WriteString(" --allow-nondistributable-artifacts")
}
if insecure {
buf.WriteString(" --insecure")
}
buf.WriteString(" ")
buf.WriteString(img)
buf.WriteString(" ")
buf.WriteString("$REGISTRY/" + ref.Repository + ":" + ref.Tag)
buf.WriteRune('\n')
}
err = os.WriteFile(filepath.Join(outdir, "copy-images.sh"), buf.Bytes(), 0o755)
if err != nil {
return err
}
Expand Down

0 comments on commit e766832

Please sign in to comment.