Skip to content

Commit

Permalink
Support customizing the images-dir in images pull/push commands (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
juamedgod authored Jan 11, 2024
1 parent 2183444 commit 6d71fd2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
10 changes: 8 additions & 2 deletions cmd/dt/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import (

var pullCmd = newPullCommand()

func pullChartImages(chart wrapping.Lockable, opts ...chartutils.Option) error {
imagesDir := chart.ImagesDir()
func pullChartImages(chart wrapping.Lockable, imagesDir string, opts ...chartutils.Option) error {
lockFile := chart.LockFilePath()

lock, err := imagelock.FromYAMLFile(lockFile)
Expand All @@ -38,6 +37,7 @@ func compressChart(ctx context.Context, dir, prefix, outputFile string) error {

func newPullCommand() *cobra.Command {
var outputFile string
var imagesDir string

cmd := &cobra.Command{
Use: "pull CHART_PATH",
Expand All @@ -60,9 +60,13 @@ func newPullCommand() *cobra.Command {
if err != nil {
return fmt.Errorf("failed to load chart: %w", err)
}
if imagesDir == "" {
imagesDir = chart.ImagesDir()
}
if err := l.Section(fmt.Sprintf("Pulling images into %q", chart.ImagesDir()), func(childLog log.SectionLogger) error {
if err := pullChartImages(
chart,
imagesDir,
chartutils.WithLog(childLog),
chartutils.WithContext(ctx),
chartutils.WithProgressBar(childLog.ProgressBar()),
Expand Down Expand Up @@ -103,5 +107,7 @@ func newPullCommand() *cobra.Command {
},
}
cmd.PersistentFlags().StringVar(&outputFile, "output-file", outputFile, "generate a tar.gz with the output of the pull operation")
cmd.PersistentFlags().StringVar(&imagesDir, "images-dir", imagesDir,
"directory where the images will be pulled to. If not empty, it overrides the default images directory inside the chart directory")
return cmd
}
18 changes: 12 additions & 6 deletions cmd/dt/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import (

var pushCmd = newPushCmd()

func pushChartImages(wrap wrapping.Wrap, opts ...chartutils.Option) error {

imagesDir := wrap.ImagesDir()

func pushChartImages(wrap wrapping.Wrap, imagesDir string, opts ...chartutils.Option) error {
lockFile := wrap.LockFilePath()

fh, err := os.Open(lockFile)
Expand All @@ -35,8 +32,10 @@ func pushChartImages(wrap wrapping.Wrap, opts ...chartutils.Option) error {
}

func newPushCmd() *cobra.Command {
return &cobra.Command{
Use: "push CHART_PATH OCI_URI",
var imagesDir string

cmd := &cobra.Command{
Use: "push CHART_PATH",
Short: "Pushes the images from Images.lock",
Long: "Pushes the images found on the Images.lock from the given Helm chart path into their current registries",
Example: ` # Push images from a sample local Helm chart
Expand All @@ -57,9 +56,13 @@ func newPushCmd() *cobra.Command {
return fmt.Errorf("failed to load chart: %w", err)
}

if imagesDir == "" {
imagesDir = chart.ImagesDir()
}
if err := l.Section("Pushing Images", func(subLog log.SectionLogger) error {
if err := pushChartImages(
chart,
imagesDir,
chartutils.WithLog(log.SilentLog),
chartutils.WithContext(ctx),
chartutils.WithProgressBar(subLog.ProgressBar()),
Expand All @@ -79,4 +82,7 @@ func newPushCmd() *cobra.Command {
return nil
},
}
cmd.PersistentFlags().StringVar(&imagesDir, "images-dir", imagesDir,
"directory containing the images to push. If not empty, it overrides the default images directory inside the chart directory")
return cmd
}
1 change: 1 addition & 0 deletions cmd/dt/unwrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func pushChartImagesAndVerify(ctx context.Context, wrap wrapping.Wrap, l log.Sec
}
if err := pushChartImages(
wrap,
wrap.ImagesDir(),
chartutils.WithLog(log.SilentLog),
chartutils.WithContext(ctx),
chartutils.WithArtifactsDir(wrap.ImageArtifactsDir()),
Expand Down
1 change: 1 addition & 0 deletions cmd/dt/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func wrapChart(ctx context.Context, inputPath string, outputFile string, platfor
fetchArtifacts, _ := flags.GetBool("fetch-artifacts")
if err := pullChartImages(
wrap,
wrap.ImagesDir(),
chartutils.WithLog(childLog),
chartutils.WithContext(ctx),
chartutils.WithFetchArtifacts(fetchArtifacts),
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/Masterminds/sprig/v3 v3.2.3
github.com/google/go-containerregistry v0.16.1
github.com/opencontainers/go-digest v1.0.0
github.com/pterm/pterm v0.12.63
github.com/pterm/pterm v0.12.72
github.com/sigstore/cosign/v2 v2.2.1
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
Expand Down Expand Up @@ -205,9 +205,9 @@ require (
)

require (
atomicgo.dev/cursor v0.1.3 // indirect
atomicgo.dev/cursor v0.2.0 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
atomicgo.dev/schedule v0.0.2 // indirect
atomicgo.dev/schedule v0.1.0 // indirect
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
Expand Down Expand Up @@ -251,7 +251,7 @@ require (
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/gookit/color v1.5.3 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gosuri/uitable v0.0.4 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ atomicgo.dev/assert v0.0.2 h1:FiKeMiZSgRrZsPo9qn/7vmr7mCsh5SZyXY4YGYiYwrg=
atomicgo.dev/assert v0.0.2/go.mod h1:ut4NcI3QDdJtlmAxQULOmA13Gz6e2DWbSAS8RUOmNYQ=
atomicgo.dev/cursor v0.1.3 h1:w8GcylMdZRyFzvDiGm3wy3fhZYYT7BwaqNjUFHxo0NU=
atomicgo.dev/cursor v0.1.3/go.mod h1:Lr4ZJB3U7DfPPOkbH7/6TOtJ4vFGHlgj1nc+n900IpU=
atomicgo.dev/cursor v0.2.0 h1:H6XN5alUJ52FZZUkI7AlJbUc1aW38GWZalpYRPpoPOw=
atomicgo.dev/cursor v0.2.0/go.mod h1:Lr4ZJB3U7DfPPOkbH7/6TOtJ4vFGHlgj1nc+n900IpU=
atomicgo.dev/keyboard v0.2.9 h1:tOsIid3nlPLZ3lwgG8KZMp/SFmr7P0ssEN5JUsm78K8=
atomicgo.dev/keyboard v0.2.9/go.mod h1:BC4w9g00XkxH/f1HXhW2sXmJFOCWbKn9xrOunSFtExQ=
atomicgo.dev/schedule v0.0.2 h1:2e/4KY6t3wokja01Cyty6qgkQM8MotJzjtqCH70oX2Q=
atomicgo.dev/schedule v0.0.2/go.mod h1:xeUa3oAkiuHYh8bKiQBRojqAMq3PXXbJujjb0hw8pEU=
atomicgo.dev/schedule v0.1.0 h1:nTthAbhZS5YZmgYbb2+DH8uQIZcTlIrd4eYr3UQxEjs=
atomicgo.dev/schedule v0.1.0/go.mod h1:xeUa3oAkiuHYh8bKiQBRojqAMq3PXXbJujjb0hw8pEU=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
Expand Down Expand Up @@ -656,6 +660,8 @@ github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQ
github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo=
github.com/gookit/color v1.5.3 h1:twfIhZs4QLCtimkP7MOxlF3A0U/5cDPseRT9M/+2SCE=
github.com/gookit/color v1.5.3/go.mod h1:NUzwzeehUfl7GIb36pqId+UGmRfQcU/WiiyTTeNjHtE=
github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4=
Expand Down Expand Up @@ -959,6 +965,8 @@ github.com/pterm/pterm v0.12.36/go.mod h1:NjiL09hFhT/vWjQHSj1athJpx6H8cjpHXNAK5b
github.com/pterm/pterm v0.12.40/go.mod h1:ffwPLwlbXxP+rxT0GsgDTzS3y3rmpAO1NMjUkGTYf8s=
github.com/pterm/pterm v0.12.63 h1:fHlrpFiI9qLtEU0TWDWMU+tAt4qKJ/s157BEAPtGm8w=
github.com/pterm/pterm v0.12.63/go.mod h1:Bq1eoUJ6BhUzzXG8WxA4l7T3s7d3Ogwg7v9VXlsVat0=
github.com/pterm/pterm v0.12.72 h1:1W7Oqi5yjEvrI0QroBqUefqXKJW4aD8/wAuqqd5qj0Q=
github.com/pterm/pterm v0.12.72/go.mod h1:+M33aZWQVpmLmLbvjykyGZ4gAfeebznRo8JMbabaxQU=
github.com/puzpuzpuz/xsync/v2 v2.5.1 h1:mVGYAvzDSu52+zaGyNjC+24Xw2bQi3kTr4QJ6N9pIIU=
github.com/puzpuzpuz/xsync/v2 v2.5.1/go.mod h1:gD2H2krq/w52MfPLE+Uy64TzJDVY7lP2znR9qmR35kU=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
Expand Down

0 comments on commit 6d71fd2

Please sign in to comment.