mirror of https://github.com/docker/compose.git
warn user remote resource is disabled
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
a345515f91
commit
fe8c2780c8
|
@ -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) {
|
func (o *ProjectOptions) configureRemoteLoaders(dockerCli command.Cli, po []cli.ProjectOptionsFn) ([]cli.ProjectOptionsFn, error) {
|
||||||
enabled, err := remote.GitRemoteLoaderEnabled()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if enabled {
|
|
||||||
git, err := remote.NewGitRemoteLoader(o.Offline)
|
git, err := remote.NewGitRemoteLoader(o.Offline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
po = append(po, cli.WithResourceLoader(git))
|
|
||||||
|
oci, err := remote.NewOCIRemoteLoader(dockerCli, o.Offline)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
enabled, err = remote.OCIRemoteLoaderEnabled()
|
po = append(po, cli.WithResourceLoader(git), cli.WithResourceLoader(oci))
|
||||||
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))
|
|
||||||
}
|
|
||||||
return po, nil
|
return po, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/adrg/xdg"
|
"github.com/adrg/xdg"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/cli"
|
"github.com/compose-spec/compose-go/cli"
|
||||||
"github.com/compose-spec/compose-go/loader"
|
"github.com/compose-spec/compose-go/loader"
|
||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
|
@ -34,8 +33,10 @@ import (
|
||||||
"github.com/moby/buildkit/util/gitutil"
|
"github.com/moby/buildkit/util/gitutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GitRemoteLoaderEnabled() (bool, error) {
|
const GIT_REMOTE_ENABLED = "COMPOSE_EXPERIMENTAL_GIT_REMOTE"
|
||||||
if v := os.Getenv("COMPOSE_EXPERIMENTAL_GIT_REMOTE"); v != "" {
|
|
||||||
|
func gitRemoteLoaderEnabled() (bool, error) {
|
||||||
|
if v := os.Getenv(GIT_REMOTE_ENABLED); v != "" {
|
||||||
enabled, err := strconv.ParseBool(v)
|
enabled, err := strconv.ParseBool(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("COMPOSE_EXPERIMENTAL_GIT_REMOTE environment variable expects boolean value: %w", err)
|
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}$`)
|
var commitSHA = regexp.MustCompile(`^[a-f0-9]{40}$`)
|
||||||
|
|
||||||
func (g gitRemoteLoader) Load(ctx context.Context, path string) (string, error) {
|
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)
|
ref, err := gitutil.ParseGitRef(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
|
@ -26,17 +26,18 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/adrg/xdg"
|
"github.com/adrg/xdg"
|
||||||
|
"github.com/compose-spec/compose-go/loader"
|
||||||
"github.com/distribution/reference"
|
"github.com/distribution/reference"
|
||||||
"github.com/docker/buildx/store/storeutil"
|
"github.com/docker/buildx/store/storeutil"
|
||||||
"github.com/docker/buildx/util/imagetools"
|
"github.com/docker/buildx/util/imagetools"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
v1 "github.com/opencontainers/image-spec/specs-go/v1"
|
v1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/loader"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func OCIRemoteLoaderEnabled() (bool, error) {
|
const OCI_REMOTE_ENABLED = "COMPOSE_EXPERIMENTAL_OCI_REMOTE"
|
||||||
if v := os.Getenv("COMPOSE_EXPERIMENTAL_OCI_REMOTE"); v != "" {
|
|
||||||
|
func ociRemoteLoaderEnabled() (bool, error) {
|
||||||
|
if v := os.Getenv(OCI_REMOTE_ENABLED); v != "" {
|
||||||
enabled, err := strconv.ParseBool(v)
|
enabled, err := strconv.ParseBool(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("COMPOSE_EXPERIMENTAL_OCI_REMOTE environment variable expects boolean value: %w", err)
|
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) {
|
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 {
|
if g.offline {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue