allow usage of -f flag with oci Compose artifact
Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
parent
7c46beb8af
commit
26064d4b60
@ -36,7 +36,7 @@ func publishCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Servic
|
|||||||
ProjectOptions: p,
|
ProjectOptions: p,
|
||||||
}
|
}
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "publish [OPTIONS] [REPOSITORY]",
|
Use: "publish [OPTIONS] REPOSITORY[:TAG]",
|
||||||
Short: "Publish compose application",
|
Short: "Publish compose application",
|
||||||
RunE: Adapt(func(ctx context.Context, args []string) error {
|
RunE: Adapt(func(ctx context.Context, args []string) error {
|
||||||
return runPublish(ctx, dockerCli, backend, opts, args[0])
|
return runPublish(ctx, dockerCli, backend, opts, args[0])
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
command: docker compose alpha publish
|
command: docker compose alpha publish
|
||||||
short: Publish compose application
|
short: Publish compose application
|
||||||
long: Publish compose application
|
long: Publish compose application
|
||||||
usage: docker compose alpha publish [OPTIONS] [REPOSITORY]
|
usage: docker compose alpha publish [OPTIONS] REPOSITORY[:TAG]
|
||||||
pname: docker compose alpha
|
pname: docker compose alpha
|
||||||
plink: docker_compose_alpha.yaml
|
plink: docker_compose_alpha.yaml
|
||||||
options:
|
options:
|
||||||
|
@ -178,6 +178,7 @@ func generateManifest(layers []v1.Descriptor, ociCompat api.OCIVersion) ([]Pusha
|
|||||||
case api.OCIVersion1_1:
|
case api.OCIVersion1_1:
|
||||||
config = v1.DescriptorEmptyJSON
|
config = v1.DescriptorEmptyJSON
|
||||||
artifactType = ComposeProjectArtifactType
|
artifactType = ComposeProjectArtifactType
|
||||||
|
config.ArtifactType = artifactType
|
||||||
// N.B. the descriptor has the data embedded in it
|
// N.B. the descriptor has the data embedded in it
|
||||||
toPush = append(toPush, Pushable{Descriptor: config, Data: make([]byte, len(config.Data))})
|
toPush = append(toPush, Pushable{Descriptor: config, Data: make([]byte, len(config.Data))})
|
||||||
default:
|
default:
|
||||||
|
@ -291,6 +291,7 @@ type ConfigOptions struct {
|
|||||||
type PushOptions struct {
|
type PushOptions struct {
|
||||||
Quiet bool
|
Quiet bool
|
||||||
IgnoreFailures bool
|
IgnoreFailures bool
|
||||||
|
ImageMandatory bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// PullOptions group options of the Pull API
|
// PullOptions group options of the Pull API
|
||||||
|
@ -35,7 +35,7 @@ func (s *composeService) Publish(ctx context.Context, project *types.Project, re
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *composeService) publish(ctx context.Context, project *types.Project, repository string, options api.PublishOptions) error {
|
func (s *composeService) publish(ctx context.Context, project *types.Project, repository string, options api.PublishOptions) error {
|
||||||
err := s.Push(ctx, project, api.PushOptions{})
|
err := s.Push(ctx, project, api.PushOptions{IgnoreFailures: true, ImageMandatory: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,9 @@ func (s *composeService) push(ctx context.Context, project *types.Project, optio
|
|||||||
w := progress.ContextWriter(ctx)
|
w := progress.ContextWriter(ctx)
|
||||||
for _, service := range project.Services {
|
for _, service := range project.Services {
|
||||||
if service.Build == nil || service.Image == "" {
|
if service.Build == nil || service.Image == "" {
|
||||||
|
if options.ImageMandatory && service.Image == "" {
|
||||||
|
return fmt.Errorf("%q attribut is mandatory to push an image for service %q", "service.image", service.Name)
|
||||||
|
}
|
||||||
w.Event(progress.Event{
|
w.Event(progress.Event{
|
||||||
ID: service.Name,
|
ID: service.Name,
|
||||||
Status: progress.Done,
|
Status: progress.Done,
|
||||||
|
@ -30,6 +30,7 @@ import (
|
|||||||
"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"
|
||||||
|
"github.com/docker/compose/v2/internal/ocipush"
|
||||||
v1 "github.com/opencontainers/image-spec/specs-go/v1"
|
v1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -113,6 +114,8 @@ func (g ociRemoteLoader) Load(ctx context.Context, path string) (string, error)
|
|||||||
|
|
||||||
err2 := g.pullComposeFiles(ctx, local, composeFile, manifest, ref, resolver)
|
err2 := g.pullComposeFiles(ctx, local, composeFile, manifest, ref, resolver)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
|
// we need to clean up the directory to be sure we won't let empty files present
|
||||||
|
_ = os.RemoveAll(local)
|
||||||
return "", err2
|
return "", err2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,8 +140,8 @@ func (g ociRemoteLoader) pullComposeFiles(ctx context.Context, local string, com
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close() //nolint:errcheck
|
defer f.Close() //nolint:errcheck
|
||||||
|
if (manifest.ArtifactType != "" && manifest.ArtifactType != ocipush.ComposeProjectArtifactType) ||
|
||||||
if manifest.ArtifactType != "application/vnd.docker.compose.project" {
|
(manifest.ArtifactType == "" && manifest.Config.MediaType != ocipush.ComposeEmptyConfigMediaType) {
|
||||||
return fmt.Errorf("%s is not a compose project OCI artifact, but %s", ref.String(), manifest.ArtifactType)
|
return fmt.Errorf("%s is not a compose project OCI artifact, but %s", ref.String(), manifest.ArtifactType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user