diff --git a/pkg/helpers/docker.go b/pkg/helpers/docker.go index 6cb4b0ac..813541e0 100644 --- a/pkg/helpers/docker.go +++ b/pkg/helpers/docker.go @@ -19,6 +19,7 @@ import ( "context" "encoding/hex" "os" + "strings" "github.com/docker/cli/cli/trust" "github.com/docker/distribution/reference" @@ -122,3 +123,7 @@ func DownloadAndExtractDockerImage(temp, image, dest string, auth *types.AuthCon err = c.Unpack(image, dest) return listedImage, err } + +func StripInvalidStringsFromImage(s string) string { + return strings.ReplaceAll(s, "+", "-") +} diff --git a/pkg/helpers/docker_test.go b/pkg/helpers/docker_test.go new file mode 100644 index 00000000..56f8bbc2 --- /dev/null +++ b/pkg/helpers/docker_test.go @@ -0,0 +1,30 @@ +// Copyright © 2021 Ettore Di Giacinto +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, see . + +package helpers_test + +import ( + . "github.com/mudler/luet/pkg/helpers" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("StripInvalidStringsFromImage", func() { + Context("Image names", func() { + It("strips invalid chars", func() { + Expect(StripInvalidStringsFromImage("foo+bar")).To(Equal("foo-bar")) + }) + }) +}) diff --git a/pkg/installer/client/docker.go b/pkg/installer/client/docker.go index 0fa86021..a03a43a9 100644 --- a/pkg/installer/client/docker.go +++ b/pkg/installer/client/docker.go @@ -136,6 +136,7 @@ func (c *DockerClient) DownloadArtifact(a *artifact.PackageArtifact) (*artifact. } func (c *DockerClient) DownloadFile(name string) (string, error) { + name = helpers.StripInvalidStringsFromImage(name) var file *os.File = nil var err error var temp string diff --git a/pkg/installer/repository_docker.go b/pkg/installer/repository_docker.go index 3e6a2fe5..ce5a0df7 100644 --- a/pkg/installer/repository_docker.go +++ b/pkg/installer/repository_docker.go @@ -166,7 +166,7 @@ func (d *dockerRepositoryGenerator) pushImageFromArtifact(a *artifact.PackageArt if err != nil { return errors.Wrap(err, "failed generating checksums for tree") } - imageTree := fmt.Sprintf("%s:%s", d.imagePrefix, a.GetFileName()) + imageTree := fmt.Sprintf("%s:%s", d.imagePrefix, helpers.StripInvalidStringsFromImage(a.GetFileName())) return d.pushFileFromArtifact(treeArchive, imageTree) } diff --git a/pkg/package/package.go b/pkg/package/package.go index 8e6bc6dd..7771deaf 100644 --- a/pkg/package/package.go +++ b/pkg/package/package.go @@ -309,7 +309,7 @@ func (p *DefaultPackage) GetPackageName() string { } func (p *DefaultPackage) ImageID() string { - return strings.ReplaceAll(p.GetFingerPrint(), "+", "-") + return helpers.StripInvalidStringsFromImage(p.GetFingerPrint()) } // GetBuildTimestamp returns the package build timestamp