Skip to content

Commit

Permalink
Merge pull request #75 from BLaurent/lock-path-prefix
Browse files Browse the repository at this point in the history
Change strip level to match wrapped chart directory layout
  • Loading branch information
mpermar authored Jul 5, 2024
2 parents 7798d72 + 0f7aeb4 commit 871e5a1
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 15 deletions.
1 change: 1 addition & 0 deletions cmd/dt/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/google/go-containerregistry/pkg/crane"
"github.com/stretchr/testify/require"
"github.com/vmware-labs/distribution-tooling-for-helm/internal/testutil"

"helm.sh/helm/v3/pkg/repo/repotest"
)

Expand Down
18 changes: 10 additions & 8 deletions cmd/dt/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

func (suite *CmdSuite) TestInfoCommand() {

t := suite.T()
require := suite.Require()
assert := suite.Assert()
Expand All @@ -29,17 +28,21 @@ func (suite *CmdSuite) TestInfoCommand() {
appVersion := "2.3.4"
scenarioDir := fmt.Sprintf("../../testdata/scenarios/%s", scenarioName)

wrapDir := sb.TempFile()
chartDir := sb.TempFile()

images, err := writeSampleImages(imageName, imageTag, filepath.Join(chartDir, "images"))
images, err := writeSampleImages(imageName, imageTag, filepath.Join(wrapDir, "images"))
require.NoError(err)
err = utils.CopyDir(filepath.Join(wrapDir, "images"), chartDir)
require.NoError(err)

require.NoError(tu.RenderScenario(scenarioDir, chartDir,
map[string]interface{}{"ServerURL": serverURL, "Images": images, "Name": chartName, "Version": version, "AppVersion": appVersion, "RepositoryURL": serverURL},
))

for _, chartPath := range []string{filepath.Join(wrapDir, "chart"), chartDir} {
require.NoError(tu.RenderScenario(scenarioDir, chartPath,
map[string]interface{}{"ServerURL": serverURL, "Images": images, "Name": chartName, "Version": version, "AppVersion": appVersion, "RepositoryURL": serverURL},
))
}
tarFile := sb.TempFile()
if err := utils.Tar(chartDir, tarFile, utils.TarConfig{
if err := utils.Tar(wrapDir, tarFile, utils.TarConfig{
Prefix: chartName,
}); err != nil {
require.NoError(err)
Expand Down Expand Up @@ -83,7 +86,6 @@ func (suite *CmdSuite) TestInfoCommand() {
require.NoError(err)

assert.Equal(lockFileData, yamlInfoData)

})

}
Expand Down
2 changes: 1 addition & 1 deletion cmd/dt/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func NewCmd(cfg *config.Config) *cobra.Command {
chartutils.WithContext(ctx),
chartutils.WithProgressBar(childLog.ProgressBar()),
chartutils.WithArtifactsDir(chart.ImageArtifactsDir()),
chartutils.WithInsecureMode(cfg.Insecure),
); err != nil {
return childLog.Failf("%v", err)
}
Expand Down Expand Up @@ -109,7 +110,6 @@ func NewCmd(cfg *config.Config) *cobra.Command {

func pullImages(chart wrapping.Lockable, imagesDir string, opts ...chartutils.Option) error {
lock, err := chart.GetImagesLock()

if err != nil {
return fmt.Errorf("failed to read Images.lock file")
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/dt/wrap/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ func ResolveInputChartPath(inputPath string, cfg *Config) (string, error) {
var err error

tmpDir, err := cfg.GetTemporaryDirectory()

if err != nil {
return "", fmt.Errorf("failed to create temporary directory: %w", err)
}
Expand Down Expand Up @@ -342,6 +341,7 @@ func pullImages(wrap wrapping.Wrap, cfg *Config) error {
chartutils.WithAuth(cfg.ContainerRegistryAuth.Username, cfg.ContainerRegistryAuth.Password),
chartutils.WithArtifactsDir(wrap.ImageArtifactsDir()),
chartutils.WithProgressBar(childLog.ProgressBar()),
chartutils.WithInsecureMode(cfg.Insecure),
); err != nil {
return childLog.Failf("%v", err)
}
Expand Down Expand Up @@ -439,7 +439,7 @@ func NewCmd(cfg *config.Config) *cobra.Command {
var platforms []string
var fetchArtifacts bool
var carvelize bool
var examples = ` # Wrap a Helm chart from a local folder
examples := ` # Wrap a Helm chart from a local folder
$ dt wrap examples/mariadb
# Wrap a Helm chart in an OCI registry
Expand Down Expand Up @@ -476,7 +476,6 @@ This command will pull all the container images and wrap it into a single tarbal
WithOutputFile(outputFile),
WithTempDirectory(tmpDir),
)

if err != nil {
if _, ok := err.(*log.LoggedError); ok {
// We already logged it, lets be less verbose
Expand Down
1 change: 1 addition & 0 deletions cmd/dt/wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/google/go-containerregistry/pkg/registry"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"helm.sh/helm/v3/pkg/repo/repotest"

"github.com/vmware-labs/distribution-tooling-for-helm/cmd/dt/wrap"
Expand Down
3 changes: 2 additions & 1 deletion internal/testutil/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
"time"

"golang.org/x/crypto/bcrypt"
"helm.sh/helm/v3/pkg/repo/repotest"
"oras.land/oras-go/v2/content/oci"

"helm.sh/helm/v3/pkg/repo/repotest"

"github.com/distribution/distribution/v3/configuration"
"github.com/distribution/distribution/v3/registry"
"github.com/google/go-containerregistry/pkg/crane"
Expand Down
1 change: 1 addition & 0 deletions pkg/artifacts/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

"github.com/containerd/containerd/remotes/docker"

"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/registry"
Expand Down
3 changes: 1 addition & 2 deletions pkg/chartutils/chartutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ func getChartFile(c *chart.Chart, name string) *chart.File {
for _, f := range c.Raw {
if f.Name == name {
return f

}
}
return nil
Expand Down Expand Up @@ -165,7 +164,7 @@ func ReadLockFromChart(chartPath string) (*imagelock.ImagesLock, error) {
if err := utils.FindFileInTar(context.Background(), chartPath, "Images.lock", func(tr *tar.Reader) error {
lock, err = imagelock.FromYAML(tr)
return err
}, utils.TarConfig{StripComponents: 1}); err != nil {
}, utils.TarConfig{StripComponents: 2}); err != nil {
return nil, err
}
if lock == nil {
Expand Down

0 comments on commit 871e5a1

Please sign in to comment.