Skip to content

Commit

Permalink
bump compose-go to v2.0.0-rc.2
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Jan 22, 2024
1 parent 1e8241f commit eb4249e
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 51 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/Microsoft/go-winio v0.6.1
github.com/buger/goterm v1.0.4
github.com/compose-spec/compose-go/v2 v2.0.0-rc.1
github.com/compose-spec/compose-go/v2 v2.0.0-rc.2
github.com/containerd/console v1.0.3
github.com/containerd/containerd v1.7.12
github.com/davecgh/go-spew v1.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+g
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE=
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4=
github.com/compose-spec/compose-go/v2 v2.0.0-rc.1 h1:0nnSpdYg29uaQOU/YJ1YSgYgwkQr/XNZ0QAFtEPTtIA=
github.com/compose-spec/compose-go/v2 v2.0.0-rc.1/go.mod h1:IVsvFyGVhw4FASzUtlWNVaAOhYmakXAFY9IlZ7LAuD8=
github.com/compose-spec/compose-go/v2 v2.0.0-rc.2 h1:eJ01FpliL/02KvsaPyH1bSLbM1S70yWQUojHVRbyvy4=
github.com/compose-spec/compose-go/v2 v2.0.0-rc.2/go.mod h1:IVsvFyGVhw4FASzUtlWNVaAOhYmakXAFY9IlZ7LAuD8=
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw=
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
Expand Down
49 changes: 29 additions & 20 deletions pkg/remote/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ func gitRemoteLoaderEnabled() (bool, error) {
func NewGitRemoteLoader(offline bool) loader.ResourceLoader {
return gitRemoteLoader{
offline: offline,
known: map[string]string{},
}
}

type gitRemoteLoader struct {
offline bool
known map[string]string
}

func (g gitRemoteLoader) Accept(path string) bool {
Expand All @@ -76,31 +78,34 @@ func (g gitRemoteLoader) Load(ctx context.Context, path string) (string, error)
return "", err
}

if ref.Commit == "" {
ref.Commit = "HEAD" // default branch
}

err = g.resolveGitRef(ctx, path, ref)
if err != nil {
return "", err
}

cache, err := cacheDir()
if err != nil {
return "", fmt.Errorf("initializing remote resource cache: %w", err)
}

local := filepath.Join(cache, ref.Commit)
if _, err := os.Stat(local); os.IsNotExist(err) {
if g.offline {
return "", nil
local, ok := g.known[path]
if !ok {
if ref.Commit == "" {
ref.Commit = "HEAD" // default branch

Check warning on line 84 in pkg/remote/git.go

View check run for this annotation

Codecov / codecov/patch

pkg/remote/git.go#L81-L84

Added lines #L81 - L84 were not covered by tests
}
err = g.checkout(ctx, local, ref)

err = g.resolveGitRef(ctx, path, ref)

Check warning on line 87 in pkg/remote/git.go

View check run for this annotation

Codecov / codecov/patch

pkg/remote/git.go#L87

Added line #L87 was not covered by tests
if err != nil {
return "", err
}
}

cache, err := cacheDir()
if err != nil {
return "", fmt.Errorf("initializing remote resource cache: %w", err)
}

Check warning on line 95 in pkg/remote/git.go

View check run for this annotation

Codecov / codecov/patch

pkg/remote/git.go#L92-L95

Added lines #L92 - L95 were not covered by tests

local = filepath.Join(cache, ref.Commit)
if _, err := os.Stat(local); os.IsNotExist(err) {
if g.offline {
return "", nil
}
err = g.checkout(ctx, local, ref)
if err != nil {
return "", err
}

Check warning on line 105 in pkg/remote/git.go

View check run for this annotation

Codecov / codecov/patch

pkg/remote/git.go#L97-L105

Added lines #L97 - L105 were not covered by tests
}
g.known[path] = local

Check warning on line 107 in pkg/remote/git.go

View check run for this annotation

Codecov / codecov/patch

pkg/remote/git.go#L107

Added line #L107 was not covered by tests
}
if ref.SubDir != "" {
local = filepath.Join(local, ref.SubDir)
}
Expand All @@ -114,6 +119,10 @@ func (g gitRemoteLoader) Load(ctx context.Context, path string) (string, error)
return local, err
}

func (g gitRemoteLoader) Dir(path string) string {
return g.known[path]

Check warning on line 123 in pkg/remote/git.go

View check run for this annotation

Codecov / codecov/patch

pkg/remote/git.go#L122-L123

Added lines #L122 - L123 were not covered by tests
}

func (g gitRemoteLoader) resolveGitRef(ctx context.Context, path string, ref *gitutil.GitRef) error {
if !commitSHA.MatchString(ref.Commit) {
cmd := exec.CommandContext(ctx, "git", "ls-remote", "--exit-code", ref.Remote, ref.Commit)
Expand Down
67 changes: 39 additions & 28 deletions pkg/remote/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ func NewOCIRemoteLoader(dockerCli command.Cli, offline bool) loader.ResourceLoad
return ociRemoteLoader{
dockerCli: dockerCli,
offline: offline,
known: map[string]string{},
}
}

type ociRemoteLoader struct {
dockerCli command.Cli
offline bool
known map[string]string
}

const prefix = "oci://"
Expand All @@ -77,42 +79,51 @@ func (g ociRemoteLoader) Load(ctx context.Context, path string) (string, error)
return "", nil
}

ref, err := reference.ParseDockerRef(path[len(prefix):])
if err != nil {
return "", err
}

opt, err := storeutil.GetImageConfig(g.dockerCli, nil)
if err != nil {
return "", err
}
resolver := imagetools.New(opt)

content, descriptor, err := resolver.Get(ctx, ref.String())
if err != nil {
return "", err
}
local, ok := g.known[path]
if !ok {
ref, err := reference.ParseDockerRef(path[len(prefix):])
if err != nil {
return "", err
}

Check warning on line 87 in pkg/remote/oci.go

View check run for this annotation

Codecov / codecov/patch

pkg/remote/oci.go#L82-L87

Added lines #L82 - L87 were not covered by tests

cache, err := cacheDir()
if err != nil {
return "", fmt.Errorf("initializing remote resource cache: %w", err)
}
opt, err := storeutil.GetImageConfig(g.dockerCli, nil)
if err != nil {
return "", err
}
resolver := imagetools.New(opt)

Check warning on line 93 in pkg/remote/oci.go

View check run for this annotation

Codecov / codecov/patch

pkg/remote/oci.go#L89-L93

Added lines #L89 - L93 were not covered by tests

local := filepath.Join(cache, descriptor.Digest.Hex())
composeFile := filepath.Join(local, "compose.yaml")
if _, err = os.Stat(local); os.IsNotExist(err) {
var manifest v1.Manifest
err = json.Unmarshal(content, &manifest)
content, descriptor, err := resolver.Get(ctx, ref.String())

Check warning on line 95 in pkg/remote/oci.go

View check run for this annotation

Codecov / codecov/patch

pkg/remote/oci.go#L95

Added line #L95 was not covered by tests
if err != nil {
return "", err
}

err2 := g.pullComposeFiles(ctx, local, composeFile, manifest, ref, resolver)
if err2 != nil {
return "", err2
cache, err := cacheDir()
if err != nil {
return "", fmt.Errorf("initializing remote resource cache: %w", err)
}

Check warning on line 103 in pkg/remote/oci.go

View check run for this annotation

Codecov / codecov/patch

pkg/remote/oci.go#L100-L103

Added lines #L100 - L103 were not covered by tests

local = filepath.Join(cache, descriptor.Digest.Hex())
composeFile := filepath.Join(local, "compose.yaml")
if _, err = os.Stat(local); os.IsNotExist(err) {
var manifest v1.Manifest
err = json.Unmarshal(content, &manifest)
if err != nil {
return "", err
}

Check warning on line 112 in pkg/remote/oci.go

View check run for this annotation

Codecov / codecov/patch

pkg/remote/oci.go#L105-L112

Added lines #L105 - L112 were not covered by tests

err2 := g.pullComposeFiles(ctx, local, composeFile, manifest, ref, resolver)
if err2 != nil {
return "", err2
}

Check warning on line 117 in pkg/remote/oci.go

View check run for this annotation

Codecov / codecov/patch

pkg/remote/oci.go#L114-L117

Added lines #L114 - L117 were not covered by tests
}
g.known[path] = local

Check warning on line 119 in pkg/remote/oci.go

View check run for this annotation

Codecov / codecov/patch

pkg/remote/oci.go#L119

Added line #L119 was not covered by tests
}
return composeFile, nil

return filepath.Join(local, "compose.yaml"), nil

Check warning on line 122 in pkg/remote/oci.go

View check run for this annotation

Codecov / codecov/patch

pkg/remote/oci.go#L122

Added line #L122 was not covered by tests
}

func (g ociRemoteLoader) Dir(path string) string {
return g.known[path]

Check warning on line 126 in pkg/remote/oci.go

View check run for this annotation

Codecov / codecov/patch

pkg/remote/oci.go#L125-L126

Added lines #L125 - L126 were not covered by tests
}

func (g ociRemoteLoader) pullComposeFiles(ctx context.Context, local string, composeFile string, manifest v1.Manifest, ref reference.Named, resolver *imagetools.Resolver) error {
Expand Down

0 comments on commit eb4249e

Please sign in to comment.