Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bundle): introduce bundle archive format, implement copy command…
… to convert archive to registry and vice versa * `werf bundle copy` command: * `--repo` param has been deprecated in favor of new `--from=ADDR` param * `--tag` param has been deprecated in favor of new `--from=ADDR` param * `--to-tag` param has been deprecated in favor of `--to=ADDR` param new format * New `--from=ADDR` and `--to=ADDR` params accept addr in different formats: * `archive:PATH_TO_ARCHIVE.tar.gz` — bundle archive * `docker://registry.example.com/group/project` — remote bundle in container registry * without explicitly specified schema address parsed also as a remote bundle in container registry * Bundle archive has following structure: * `chart.tar.gz` — regular helm chart archive * `images/TAG.tar.gz` — dir contains all werf images referenced from chart values `.Values.werf.image.NAME`, named by tags Refs werf/3p-helm#216 Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
- Loading branch information
1 parent
3a7c68d
commit 345cdf0
Showing
12 changed files
with
895 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package bundles | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/werf/werf/pkg/deploy/bundles/registry" | ||
) | ||
|
||
const ( | ||
ArchiveSchema = "archive:" | ||
RegistrySchema = "docker://" | ||
) | ||
|
||
type Addr struct { | ||
*ArchiveAddress | ||
*RegistryAddress | ||
} | ||
|
||
func (addr *Addr) String() string { | ||
if addr.RegistryAddress != nil { | ||
return addr.RegistryAddress.FullName() | ||
} | ||
if addr.ArchiveAddress != nil { | ||
return addr.ArchiveAddress.Path | ||
} | ||
return "" | ||
} | ||
|
||
type ArchiveAddress struct { | ||
Path string | ||
} | ||
|
||
type RegistryAddress struct { | ||
*registry.Reference | ||
} | ||
|
||
func ParseAddr(addr string) (*Addr, error) { | ||
switch { | ||
case strings.HasPrefix(addr, ArchiveSchema): | ||
return &Addr{ArchiveAddress: parseArchiveAddress(addr)}, nil | ||
case strings.HasPrefix(addr, RegistrySchema): | ||
if regAddr, err := parseRegistryAddress(addr); err != nil { | ||
return nil, fmt.Errorf("unable to parse registry address %q: %w", addr, err) | ||
} else { | ||
return &Addr{RegistryAddress: regAddr}, nil | ||
} | ||
default: | ||
if regAddr, err := parseRegistryAddress(addr); err != nil { | ||
return nil, fmt.Errorf("unable to parse registry address %q: %w", addr, err) | ||
} else { | ||
return &Addr{RegistryAddress: regAddr}, nil | ||
} | ||
} | ||
} | ||
|
||
func parseRegistryAddress(addr string) (*RegistryAddress, error) { | ||
cleanAddr := strings.TrimPrefix(addr, RegistrySchema) | ||
|
||
ref, err := registry.ParseReference(cleanAddr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if ref.Tag == "" { | ||
ref.Tag = "latest" | ||
} | ||
|
||
return &RegistryAddress{Reference: ref}, nil | ||
} | ||
|
||
func parseArchiveAddress(addr string) *ArchiveAddress { | ||
path := strings.TrimPrefix(addr, ArchiveSchema) | ||
return &ArchiveAddress{Path: path} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package bundles | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Bundle addr", func() { | ||
It("should parse different bundle address schemas", func() { | ||
{ | ||
addr, err := ParseAddr("registry.werf.io/group/image:mytag") | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(addr.RegistryAddress).NotTo(BeNil()) | ||
Expect(addr.ArchiveAddress).To(BeNil()) | ||
Expect(addr.Repo).To(Equal("registry.werf.io/group/image")) | ||
Expect(addr.Tag).To(Equal("mytag")) | ||
} | ||
|
||
{ | ||
addr, err := ParseAddr("registry.werf.io/group/image") | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(addr.RegistryAddress).NotTo(BeNil()) | ||
Expect(addr.ArchiveAddress).To(BeNil()) | ||
Expect(addr.Repo).To(Equal("registry.werf.io/group/image")) | ||
Expect(addr.Tag).To(Equal("latest")) | ||
} | ||
|
||
{ | ||
addr, err := ParseAddr("archive:path/to/file.tar.gz") | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(addr.RegistryAddress).To(BeNil()) | ||
Expect(addr.ArchiveAddress).NotTo(BeNil()) | ||
Expect(addr.Path).To(Equal("path/to/file.tar.gz")) | ||
} | ||
|
||
{ | ||
addr, err := ParseAddr("archive:/absolute/path/to/file.tar.gz") | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(addr.RegistryAddress).To(BeNil()) | ||
Expect(addr.ArchiveAddress).NotTo(BeNil()) | ||
Expect(addr.Path).To(Equal("/absolute/path/to/file.tar.gz")) | ||
} | ||
}) | ||
}) |
Oops, something went wrong.