Skip to content

Commit

Permalink
allow usage of -f flag with oci Compose artifact
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
  • Loading branch information
glours committed Oct 21, 2024
1 parent 82417bd commit 5a1a384
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/compose/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func publishCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Servic
ProjectOptions: p,
}
cmd := &cobra.Command{
Use: "publish [OPTIONS] [REPOSITORY]",
Use: "publish [OPTIONS] REPOSITORY[:TAG]",
Short: "Publish compose application",
RunE: Adapt(func(ctx context.Context, args []string) error {
return runPublish(ctx, dockerCli, backend, opts, args[0])
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/docker_compose_alpha_publish.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
command: docker compose alpha publish
short: 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
plink: docker_compose_alpha.yaml
options:
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,5 @@ require (
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace github.com/compose-spec/compose-go/v2 => github.com/glours/compose-go/v2 v2.0.0-20241021140134-fb48d1a80750
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa h1:jQCWAUqqlij9Pgj2i/P
github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa/go.mod h1:x/1Gn8zydmfq8dk6e9PdstVsDgu9RuyIIJqAaF//0IM=
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.3.1-0.20241015085011-35c9659361ef h1:E3qLbOpEyqemgAkQQg3uKNFaJJ+cVXGKiy1Xj4zh49k=
github.com/compose-spec/compose-go/v2 v2.3.1-0.20241015085011-35c9659361ef/go.mod h1:lFN0DrMxIncJGYAXTfWuajfwj5haBJqrBkarHcnjJKc=
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.4 h1:F2g4+oChYvBTsASRTz8NP6iIAi97J3TtSAsLbIFn4ro=
Expand Down Expand Up @@ -168,6 +166,8 @@ github.com/fsnotify/fsevents v0.2.0/go.mod h1:B3eEk39i4hz8y1zaWS/wPrAP4O6wkIl7HQ
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fvbommel/sortorder v1.1.0 h1:fUmoe+HLsBTctBDoaBwpQo5N+nrCp8g/BjKb/6ZQmYw=
github.com/fvbommel/sortorder v1.1.0/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0=
github.com/glours/compose-go/v2 v2.0.0-20241021140134-fb48d1a80750 h1:GIctd/gwnOxuWOqSBUg8URtABWMj2yskyif4wVdsHRk=
github.com/glours/compose-go/v2 v2.0.0-20241021140134-fb48d1a80750/go.mod h1:lFN0DrMxIncJGYAXTfWuajfwj5haBJqrBkarHcnjJKc=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
Expand Down
1 change: 1 addition & 0 deletions internal/ocipush/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func generateManifest(layers []v1.Descriptor, ociCompat api.OCIVersion) ([]Pusha
case api.OCIVersion1_1:
config = v1.DescriptorEmptyJSON
artifactType = ComposeProjectArtifactType
config.ArtifactType = artifactType
// N.B. the descriptor has the data embedded in it
toPush = append(toPush, Pushable{Descriptor: config, Data: make([]byte, len(config.Data))})
default:
Expand Down
1 change: 1 addition & 0 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ type ConfigOptions struct {
type PushOptions struct {
Quiet bool
IgnoreFailures bool
ImageMandatory bool
}

// PullOptions group options of the Pull API
Expand Down
2 changes: 1 addition & 1 deletion pkg/compose/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
err := s.Push(ctx, project, api.PushOptions{})
err := s.Push(ctx, project, api.PushOptions{IgnoreFailures: true, ImageMandatory: true})
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/compose/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func (s *composeService) push(ctx context.Context, project *types.Project, optio
w := progress.ContextWriter(ctx)
for _, service := range project.Services {
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{
ID: service.Name,
Status: progress.Done,
Expand Down
2 changes: 2 additions & 0 deletions pkg/remote/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ func (g ociRemoteLoader) Load(ctx context.Context, path string) (string, error)

err2 := g.pullComposeFiles(ctx, local, composeFile, manifest, ref, resolver)
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
}
}
Expand Down

0 comments on commit 5a1a384

Please sign in to comment.