From fe8c2780c889b324a7cfb0cdd9b001c586ff8970 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Fri, 29 Sep 2023 09:25:52 +0200 Subject: [PATCH] warn user remote resource is disabled Signed-off-by: Nicolas De Loof --- cmd/compose/compose.go | 20 ++++---------------- pkg/remote/git.go | 15 ++++++++++++--- pkg/remote/oci.go | 17 +++++++++++++---- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/cmd/compose/compose.go b/cmd/compose/compose.go index 763b5cf26..7d89db2e4 100644 --- a/cmd/compose/compose.go +++ b/cmd/compose/compose.go @@ -252,29 +252,17 @@ func (o *ProjectOptions) ToProject(dockerCli command.Cli, services []string, po } func (o *ProjectOptions) configureRemoteLoaders(dockerCli command.Cli, po []cli.ProjectOptionsFn) ([]cli.ProjectOptionsFn, error) { - enabled, err := remote.GitRemoteLoaderEnabled() + git, err := remote.NewGitRemoteLoader(o.Offline) if err != nil { return nil, err } - if enabled { - git, err := remote.NewGitRemoteLoader(o.Offline) - if err != nil { - return nil, err - } - po = append(po, cli.WithResourceLoader(git)) - } - enabled, err = remote.OCIRemoteLoaderEnabled() + oci, err := remote.NewOCIRemoteLoader(dockerCli, o.Offline) if err != nil { return nil, err } - if enabled { - git, err := remote.NewOCIRemoteLoader(dockerCli, o.Offline) - if err != nil { - return nil, err - } - po = append(po, cli.WithResourceLoader(git)) - } + + po = append(po, cli.WithResourceLoader(git), cli.WithResourceLoader(oci)) return po, nil } diff --git a/pkg/remote/git.go b/pkg/remote/git.go index 3e7c9a1d8..b6228286b 100644 --- a/pkg/remote/git.go +++ b/pkg/remote/git.go @@ -26,7 +26,6 @@ import ( "strconv" "github.com/adrg/xdg" - "github.com/compose-spec/compose-go/cli" "github.com/compose-spec/compose-go/loader" "github.com/compose-spec/compose-go/types" @@ -34,8 +33,10 @@ import ( "github.com/moby/buildkit/util/gitutil" ) -func GitRemoteLoaderEnabled() (bool, error) { - if v := os.Getenv("COMPOSE_EXPERIMENTAL_GIT_REMOTE"); v != "" { +const GIT_REMOTE_ENABLED = "COMPOSE_EXPERIMENTAL_GIT_REMOTE" + +func gitRemoteLoaderEnabled() (bool, error) { + if v := os.Getenv(GIT_REMOTE_ENABLED); v != "" { enabled, err := strconv.ParseBool(v) if err != nil { return false, fmt.Errorf("COMPOSE_EXPERIMENTAL_GIT_REMOTE environment variable expects boolean value: %w", err) @@ -74,6 +75,14 @@ func (g gitRemoteLoader) Accept(path string) bool { var commitSHA = regexp.MustCompile(`^[a-f0-9]{40}$`) func (g gitRemoteLoader) Load(ctx context.Context, path string) (string, error) { + enabled, err := gitRemoteLoaderEnabled() + if err != nil { + return "", err + } + if !enabled { + return "", fmt.Errorf("experimental git remote resource is disabled. %q must be set", GIT_REMOTE_ENABLED) + } + ref, err := gitutil.ParseGitRef(path) if err != nil { return "", err diff --git a/pkg/remote/oci.go b/pkg/remote/oci.go index 151559bf1..4bb1b713c 100644 --- a/pkg/remote/oci.go +++ b/pkg/remote/oci.go @@ -26,17 +26,18 @@ import ( "strings" "github.com/adrg/xdg" + "github.com/compose-spec/compose-go/loader" "github.com/distribution/reference" "github.com/docker/buildx/store/storeutil" "github.com/docker/buildx/util/imagetools" "github.com/docker/cli/cli/command" v1 "github.com/opencontainers/image-spec/specs-go/v1" - - "github.com/compose-spec/compose-go/loader" ) -func OCIRemoteLoaderEnabled() (bool, error) { - if v := os.Getenv("COMPOSE_EXPERIMENTAL_OCI_REMOTE"); v != "" { +const OCI_REMOTE_ENABLED = "COMPOSE_EXPERIMENTAL_OCI_REMOTE" + +func ociRemoteLoaderEnabled() (bool, error) { + if v := os.Getenv(OCI_REMOTE_ENABLED); v != "" { enabled, err := strconv.ParseBool(v) if err != nil { return false, fmt.Errorf("COMPOSE_EXPERIMENTAL_OCI_REMOTE environment variable expects boolean value: %w", err) @@ -76,6 +77,14 @@ func (g ociRemoteLoader) Accept(path string) bool { } func (g ociRemoteLoader) Load(ctx context.Context, path string) (string, error) { + enabled, err := ociRemoteLoaderEnabled() + if err != nil { + return "", err + } + if !enabled { + return "", fmt.Errorf("experimental OCI remote resource is disabled. %q must be set", OCI_REMOTE_ENABLED) + } + if g.offline { return "", nil }