Skip to content

Commit

Permalink
warn user remote resource is disabled
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Sep 29, 2023
1 parent 4f69491 commit 8ae00fe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
20 changes: 4 additions & 16 deletions cmd/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
15 changes: 12 additions & 3 deletions pkg/remote/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ 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"
"github.com/docker/compose/v2/pkg/api"
"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)
Expand Down Expand Up @@ -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
Expand Down
17 changes: 13 additions & 4 deletions pkg/remote/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 8ae00fe

Please sign in to comment.