mirror of https://github.com/docker/compose.git
Merge pull request #11390 from ndeloof/compose-go-v2.0.0-rc.2
bump compose-go to v2.0.0-rc.2
This commit is contained in:
commit
143ac0f1b6
2
go.mod
2
go.mod
|
@ -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
|
||||
|
|
4
go.sum
4
go.sum
|
@ -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=
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
err = g.checkout(ctx, local, ref)
|
||||
|
||||
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
|
||||
}
|
||||
err = g.checkout(ctx, local, ref)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
g.known[path] = local
|
||||
}
|
||||
if ref.SubDir != "" {
|
||||
local = filepath.Join(local, ref.SubDir)
|
||||
}
|
||||
|
@ -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]
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -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://"
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
cache, err := cacheDir()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("initializing remote resource cache: %w", err)
|
||||
}
|
||||
|
||||
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)
|
||||
local, ok := g.known[path]
|
||||
if !ok {
|
||||
ref, err := reference.ParseDockerRef(path[len(prefix):])
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
err2 := g.pullComposeFiles(ctx, local, composeFile, manifest, ref, resolver)
|
||||
if err2 != nil {
|
||||
return "", err2
|
||||
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
|
||||
}
|
||||
|
||||
cache, err := cacheDir()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("initializing remote resource cache: %w", err)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
err2 := g.pullComposeFiles(ctx, local, composeFile, manifest, ref, resolver)
|
||||
if err2 != nil {
|
||||
return "", err2
|
||||
}
|
||||
}
|
||||
g.known[path] = local
|
||||
}
|
||||
return composeFile, nil
|
||||
|
||||
return filepath.Join(local, "compose.yaml"), nil
|
||||
}
|
||||
|
||||
func (g ociRemoteLoader) Dir(path string) string {
|
||||
return g.known[path]
|
||||
}
|
||||
|
||||
func (g ociRemoteLoader) pullComposeFiles(ctx context.Context, local string, composeFile string, manifest v1.Manifest, ref reference.Named, resolver *imagetools.Resolver) error {
|
||||
|
|
Loading…
Reference in New Issue