Skip to content

Commit c9d54f0

Browse files
committed
introduce publish (alpha) command
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent aeb835a commit c9d54f0

File tree

9 files changed

+153
-0
lines changed

9 files changed

+153
-0
lines changed

cmd/compose/alpha.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func alphaCommand(p *ProjectOptions, backend api.Service) *cobra.Command {
3232
cmd.AddCommand(
3333
watchCommand(p, backend),
3434
vizCommand(p, backend),
35+
publishCommand(p, backend),
3536
)
3637
return cmd
3738
}

cmd/compose/publish.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright 2020 Docker Compose CLI authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package compose
18+
19+
import (
20+
"context"
21+
22+
"github.com/spf13/cobra"
23+
24+
"github.com/docker/compose/v2/pkg/api"
25+
)
26+
27+
func publishCommand(p *ProjectOptions, backend api.Service) *cobra.Command {
28+
opts := pushOptions{
29+
ProjectOptions: p,
30+
}
31+
publishCmd := &cobra.Command{
32+
Use: "publish [OPTIONS] [REPOSITORY]",
33+
Short: "Publish compose application",
34+
RunE: Adapt(func(ctx context.Context, args []string) error {
35+
return runPublish(ctx, backend, opts, args[0])
36+
}),
37+
Args: cobra.ExactArgs(1),
38+
}
39+
return publishCmd
40+
}
41+
42+
func runPublish(ctx context.Context, backend api.Service, opts pushOptions, repository string) error {
43+
project, err := opts.ToProject(nil)
44+
if err != nil {
45+
return err
46+
}
47+
48+
return backend.Publish(ctx, project, repository)
49+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# docker compose alpha publish
2+
3+
<!---MARKER_GEN_START-->
4+
Publish compose application
5+
6+
### Options
7+
8+
| Name | Type | Default | Description |
9+
|:------------|:-----|:--------|:--------------------------------|
10+
| `--dry-run` | | | Execute command in dry run mode |
11+
12+
13+
<!---MARKER_GEN_END-->
14+

docs/reference/docker_compose_alpha.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ long: Experimental commands
44
pname: docker compose
55
plink: docker_compose.yaml
66
cname:
7+
- docker compose alpha publish
78
- docker compose alpha viz
89
- docker compose alpha watch
910
clink:
11+
- docker_compose_alpha_publish.yaml
1012
- docker_compose_alpha_viz.yaml
1113
- docker_compose_alpha_watch.yaml
1214
inherited_options:
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
command: docker compose alpha publish
2+
short: Publish compose application
3+
long: Publish compose application
4+
usage: docker compose alpha publish [OPTIONS] [REPOSITORY]
5+
pname: docker compose alpha
6+
plink: docker_compose_alpha.yaml
7+
inherited_options:
8+
- option: dry-run
9+
value_type: bool
10+
default_value: "false"
11+
description: Execute command in dry run mode
12+
deprecated: false
13+
hidden: false
14+
experimental: false
15+
experimentalcli: false
16+
kubernetes: false
17+
swarm: false
18+
deprecated: false
19+
hidden: false
20+
experimental: false
21+
experimentalcli: true
22+
kubernetes: false
23+
swarm: false
24+

pkg/api/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ type Service interface {
7474
Events(ctx context.Context, projectName string, options EventsOptions) error
7575
// Port executes the equivalent to a `compose port`
7676
Port(ctx context.Context, projectName string, service string, port uint16, options PortOptions) (string, int, error)
77+
// Publish executes the equivalent to a `compose publish`
78+
Publish(ctx context.Context, project *types.Project, repository string) error
7779
// Images executes the equivalent of a `compose images`
7880
Images(ctx context.Context, projectName string, options ImagesOptions) ([]ImageSummary, error)
7981
// MaxConcurrency defines upper limit for concurrent operations against engine API

pkg/api/proxy.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type ServiceProxy struct {
5555
DryRunModeFn func(ctx context.Context, dryRun bool) (context.Context, error)
5656
VizFn func(ctx context.Context, project *types.Project, options VizOptions) (string, error)
5757
WaitFn func(ctx context.Context, projectName string, options WaitOptions) (int64, error)
58+
PublishFn func(ctx context.Context, project *types.Project, repository string) error
5859
interceptors []Interceptor
5960
}
6061

@@ -91,6 +92,7 @@ func (s *ServiceProxy) WithService(service Service) *ServiceProxy {
9192
s.TopFn = service.Top
9293
s.EventsFn = service.Events
9394
s.PortFn = service.Port
95+
s.PublishFn = service.Publish
9496
s.ImagesFn = service.Images
9597
s.WatchFn = service.Watch
9698
s.MaxConcurrencyFn = service.MaxConcurrency
@@ -311,6 +313,10 @@ func (s *ServiceProxy) Port(ctx context.Context, projectName string, service str
311313
return s.PortFn(ctx, projectName, service, port, options)
312314
}
313315

316+
func (s *ServiceProxy) Publish(ctx context.Context, project *types.Project, repository string) error {
317+
return s.PublishFn(ctx, project, repository)
318+
}
319+
314320
// Images implements Service interface
315321
func (s *ServiceProxy) Images(ctx context.Context, project string, options ImagesOptions) ([]ImageSummary, error) {
316322
if s.ImagesFn == nil {

pkg/compose/publish.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright 2020 Docker Compose CLI authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package compose
18+
19+
import (
20+
"context"
21+
22+
"github.com/compose-spec/compose-go/types"
23+
"github.com/distribution/distribution/v3/reference"
24+
"github.com/docker/compose/v2/pkg/api"
25+
)
26+
27+
func (s *composeService) Publish(ctx context.Context, project *types.Project, repository string) error {
28+
err := s.Push(ctx, project, api.PushOptions{})
29+
if err != nil {
30+
return err
31+
}
32+
33+
_, err = reference.ParseDockerRef(repository)
34+
if err != nil {
35+
return err
36+
}
37+
38+
// TODO publish project.ComposeFiles
39+
40+
return api.ErrNotImplemented
41+
}

pkg/mocks/mock_docker_compose_api.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)