Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit fa05d43

Browse files
authored
Merge pull request #1539 from docker/inject
2 parents f41efa3 + de3fa40 commit fa05d43

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+951
-449
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ RUN --mount=target=. \
7373
GOARCH=${TARGETARCH} \
7474
BUILD_TAGS=${BUILD_TAGS} \
7575
GIT_TAG=${GIT_TAG} \
76-
make BINARY=/out/docker -f builder.Makefile cli
76+
make BINARY=/out/docker COMPOSE_BINARY=/out/docker-compose -f builder.Makefile cli
7777

7878
FROM base AS make-cross
7979
ARG BUILD_TAGS
@@ -83,7 +83,7 @@ RUN --mount=target=. \
8383
--mount=type=cache,target=/root/.cache/go-build \
8484
BUILD_TAGS=${BUILD_TAGS} \
8585
GIT_TAG=${GIT_TAG} \
86-
make BINARY=/out/docker -f builder.Makefile cross
86+
make BINARY=/out/docker COMPOSE_BINARY=/out/docker-compose -f builder.Makefile cross
8787

8888
FROM scratch AS protos
8989
COPY --from=make-protos /compose-cli/cli/server/protos .

api/compose/delegator.go

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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+
)
24+
25+
// ServiceDelegator implements Service by delegating to another implementation. This allows lazy init
26+
type ServiceDelegator struct {
27+
Delegate Service
28+
}
29+
30+
//Build implements Service interface
31+
func (s *ServiceDelegator) Build(ctx context.Context, project *types.Project, options BuildOptions) error {
32+
return s.Delegate.Build(ctx, project, options)
33+
}
34+
35+
//Push implements Service interface
36+
func (s *ServiceDelegator) Push(ctx context.Context, project *types.Project, options PushOptions) error {
37+
return s.Delegate.Push(ctx, project, options)
38+
}
39+
40+
//Pull implements Service interface
41+
func (s *ServiceDelegator) Pull(ctx context.Context, project *types.Project, options PullOptions) error {
42+
return s.Delegate.Pull(ctx, project, options)
43+
}
44+
45+
//Create implements Service interface
46+
func (s *ServiceDelegator) Create(ctx context.Context, project *types.Project, options CreateOptions) error {
47+
return s.Delegate.Create(ctx, project, options)
48+
}
49+
50+
//Start implements Service interface
51+
func (s *ServiceDelegator) Start(ctx context.Context, project *types.Project, options StartOptions) error {
52+
return s.Delegate.Start(ctx, project, options)
53+
}
54+
55+
//Restart implements Service interface
56+
func (s *ServiceDelegator) Restart(ctx context.Context, project *types.Project, options RestartOptions) error {
57+
return s.Delegate.Restart(ctx, project, options)
58+
}
59+
60+
//Stop implements Service interface
61+
func (s *ServiceDelegator) Stop(ctx context.Context, project *types.Project, options StopOptions) error {
62+
return s.Delegate.Stop(ctx, project, options)
63+
}
64+
65+
//Up implements Service interface
66+
func (s *ServiceDelegator) Up(ctx context.Context, project *types.Project, options UpOptions) error {
67+
return s.Delegate.Up(ctx, project, options)
68+
}
69+
70+
//Down implements Service interface
71+
func (s *ServiceDelegator) Down(ctx context.Context, project string, options DownOptions) error {
72+
return s.Delegate.Down(ctx, project, options)
73+
}
74+
75+
//Logs implements Service interface
76+
func (s *ServiceDelegator) Logs(ctx context.Context, project string, consumer LogConsumer, options LogOptions) error {
77+
return s.Delegate.Logs(ctx, project, consumer, options)
78+
}
79+
80+
//Ps implements Service interface
81+
func (s *ServiceDelegator) Ps(ctx context.Context, project string, options PsOptions) ([]ContainerSummary, error) {
82+
return s.Delegate.Ps(ctx, project, options)
83+
}
84+
85+
//List implements Service interface
86+
func (s *ServiceDelegator) List(ctx context.Context, options ListOptions) ([]Stack, error) {
87+
return s.Delegate.List(ctx, options)
88+
}
89+
90+
//Convert implements Service interface
91+
func (s *ServiceDelegator) Convert(ctx context.Context, project *types.Project, options ConvertOptions) ([]byte, error) {
92+
return s.Delegate.Convert(ctx, project, options)
93+
}
94+
95+
//Kill implements Service interface
96+
func (s *ServiceDelegator) Kill(ctx context.Context, project *types.Project, options KillOptions) error {
97+
return s.Delegate.Kill(ctx, project, options)
98+
}
99+
100+
//RunOneOffContainer implements Service interface
101+
func (s *ServiceDelegator) RunOneOffContainer(ctx context.Context, project *types.Project, options RunOptions) (int, error) {
102+
return s.Delegate.RunOneOffContainer(ctx, project, options)
103+
}
104+
105+
//Remove implements Service interface
106+
func (s *ServiceDelegator) Remove(ctx context.Context, project *types.Project, options RemoveOptions) ([]string, error) {
107+
return s.Delegate.Remove(ctx, project, options)
108+
}
109+
110+
//Exec implements Service interface
111+
func (s *ServiceDelegator) Exec(ctx context.Context, project *types.Project, options RunOptions) error {
112+
return s.Delegate.Exec(ctx, project, options)
113+
}
114+
115+
//Pause implements Service interface
116+
func (s *ServiceDelegator) Pause(ctx context.Context, project string, options PauseOptions) error {
117+
return s.Delegate.Pause(ctx, project, options)
118+
}
119+
120+
//UnPause implements Service interface
121+
func (s *ServiceDelegator) UnPause(ctx context.Context, project string, options PauseOptions) error {
122+
return s.Delegate.UnPause(ctx, project, options)
123+
}
124+
125+
//Top implements Service interface
126+
func (s *ServiceDelegator) Top(ctx context.Context, project string, services []string) ([]ContainerProcSummary, error) {
127+
return s.Delegate.Top(ctx, project, services)
128+
}
129+
130+
//Events implements Service interface
131+
func (s *ServiceDelegator) Events(ctx context.Context, project string, options EventsOptions) error {
132+
return s.Delegate.Events(ctx, project, options)
133+
}
134+
135+
//Port implements Service interface
136+
func (s *ServiceDelegator) Port(ctx context.Context, project string, service string, port int, options PortOptions) (string, int, error) {
137+
return s.Delegate.Port(ctx, project, service, port, options)
138+
}
139+
140+
//Images implements Service interface
141+
func (s *ServiceDelegator) Images(ctx context.Context, project string, options ImagesOptions) ([]ImageSummary, error) {
142+
return s.Delegate.Images(ctx, project, options)
143+
}

api/compose/noimpl.go

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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+
24+
"github.com/docker/compose-cli/api/errdefs"
25+
)
26+
27+
// NoImpl implements Service to return ErrNotImplemented
28+
type NoImpl struct{}
29+
30+
//Build implements Service interface
31+
func (s NoImpl) Build(ctx context.Context, project *types.Project, options BuildOptions) error {
32+
return errdefs.ErrNotImplemented
33+
}
34+
35+
//Push implements Service interface
36+
func (s NoImpl) Push(ctx context.Context, project *types.Project, options PushOptions) error {
37+
return errdefs.ErrNotImplemented
38+
}
39+
40+
//Pull implements Service interface
41+
func (s NoImpl) Pull(ctx context.Context, project *types.Project, options PullOptions) error {
42+
return errdefs.ErrNotImplemented
43+
}
44+
45+
//Create implements Service interface
46+
func (s NoImpl) Create(ctx context.Context, project *types.Project, options CreateOptions) error {
47+
return errdefs.ErrNotImplemented
48+
}
49+
50+
//Start implements Service interface
51+
func (s NoImpl) Start(ctx context.Context, project *types.Project, options StartOptions) error {
52+
return errdefs.ErrNotImplemented
53+
}
54+
55+
//Restart implements Service interface
56+
func (s NoImpl) Restart(ctx context.Context, project *types.Project, options RestartOptions) error {
57+
return errdefs.ErrNotImplemented
58+
}
59+
60+
//Stop implements Service interface
61+
func (s NoImpl) Stop(ctx context.Context, project *types.Project, options StopOptions) error {
62+
return errdefs.ErrNotImplemented
63+
}
64+
65+
//Up implements Service interface
66+
func (s NoImpl) Up(ctx context.Context, project *types.Project, options UpOptions) error {
67+
return errdefs.ErrNotImplemented
68+
}
69+
70+
//Down implements Service interface
71+
func (s NoImpl) Down(ctx context.Context, project string, options DownOptions) error {
72+
return errdefs.ErrNotImplemented
73+
}
74+
75+
//Logs implements Service interface
76+
func (s NoImpl) Logs(ctx context.Context, project string, consumer LogConsumer, options LogOptions) error {
77+
return errdefs.ErrNotImplemented
78+
}
79+
80+
//Ps implements Service interface
81+
func (s NoImpl) Ps(ctx context.Context, project string, options PsOptions) ([]ContainerSummary, error) {
82+
return nil, errdefs.ErrNotImplemented
83+
}
84+
85+
//List implements Service interface
86+
func (s NoImpl) List(ctx context.Context, options ListOptions) ([]Stack, error) {
87+
return nil, errdefs.ErrNotImplemented
88+
}
89+
90+
//Convert implements Service interface
91+
func (s NoImpl) Convert(ctx context.Context, project *types.Project, options ConvertOptions) ([]byte, error) {
92+
return nil, errdefs.ErrNotImplemented
93+
}
94+
95+
//Kill implements Service interface
96+
func (s NoImpl) Kill(ctx context.Context, project *types.Project, options KillOptions) error {
97+
return errdefs.ErrNotImplemented
98+
}
99+
100+
//RunOneOffContainer implements Service interface
101+
func (s NoImpl) RunOneOffContainer(ctx context.Context, project *types.Project, options RunOptions) (int, error) {
102+
return 0, errdefs.ErrNotImplemented
103+
}
104+
105+
//Remove implements Service interface
106+
func (s NoImpl) Remove(ctx context.Context, project *types.Project, options RemoveOptions) ([]string, error) {
107+
return nil, errdefs.ErrNotImplemented
108+
}
109+
110+
//Exec implements Service interface
111+
func (s NoImpl) Exec(ctx context.Context, project *types.Project, options RunOptions) error {
112+
return errdefs.ErrNotImplemented
113+
}
114+
115+
//Pause implements Service interface
116+
func (s NoImpl) Pause(ctx context.Context, project string, options PauseOptions) error {
117+
return errdefs.ErrNotImplemented
118+
}
119+
120+
//UnPause implements Service interface
121+
func (s NoImpl) UnPause(ctx context.Context, project string, options PauseOptions) error {
122+
return errdefs.ErrNotImplemented
123+
}
124+
125+
//Top implements Service interface
126+
func (s NoImpl) Top(ctx context.Context, project string, services []string) ([]ContainerProcSummary, error) {
127+
return nil, errdefs.ErrNotImplemented
128+
}
129+
130+
//Events implements Service interface
131+
func (s NoImpl) Events(ctx context.Context, project string, options EventsOptions) error {
132+
return errdefs.ErrNotImplemented
133+
}
134+
135+
//Port implements Service interface
136+
func (s NoImpl) Port(ctx context.Context, project string, service string, port int, options PortOptions) (string, int, error) {
137+
return "", 0, errdefs.ErrNotImplemented
138+
}
139+
140+
//Images implements Service interface
141+
func (s NoImpl) Images(ctx context.Context, project string, options ImagesOptions) ([]ImageSummary, error) {
142+
return nil, errdefs.ErrNotImplemented
143+
}

builder.Makefile

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)
3434
BINARY?=bin/docker
3535
BINARY_WITH_EXTENSION=$(BINARY)$(EXTENSION)
3636

37+
COMPOSE_BINARY?=bin/docker-compose
38+
COMPOSE_BINARY_WITH_EXTENSION=$(COMPOSE_BINARY)$(EXTENSION)
39+
3740
WORK_DIR:=$(shell mktemp -d)
3841

3942
TAGS:=
@@ -42,9 +45,22 @@ ifdef BUILD_TAGS
4245
LINT_TAGS=--build-tags $(BUILD_TAGS)
4346
endif
4447

45-
TAR_TRANSFORM:=--transform s/packaging/docker/ --transform s/bin/docker/ --transform s/docker-linux-amd64/docker/ --transform s/docker-darwin-amd64/docker/ --transform s/docker-linux-arm64/docker/ --transform s/docker-linux-armv6/docker/ --transform s/docker-linux-armv7/docker/ --transform s/docker-darwin-arm64/docker/
48+
TAR_TRANSFORM:=--transform s/packaging/docker/ --transform s/bin/docker/ \
49+
--transform s/docker-linux-amd64/docker/ --transform s/docker-linux-arm64/docker/ \
50+
--transform s/docker-linux-armv6/docker/ --transform s/docker-linux-armv7/docker/ \
51+
--transform s/docker-darwin-amd64/docker/ --transform s/docker-darwin-arm64/docker/ \
52+
--transform s/docker-compose-linux-amd64/docker-compose/ --transform s/docker-compose-linux-arm64/docker-compose/ \
53+
--transform s/docker-compose-linux-armv6/docker-compose/ --transform s/docker-compose-linux-armv7/docker-compose/ \
54+
--transform s/docker-compose-darwin-amd64/docker-compose/ --transform s/docker-compose-darwin-arm64/docker-compose/
55+
4656
ifneq ($(findstring bsd,$(shell tar --version)),)
47-
TAR_TRANSFORM=-s /packaging/docker/ -s /bin/docker/ -s /docker-linux-amd64/docker/ -s /docker-darwin-amd64/docker/ -s /docker-linux-arm64/docker/ -s /docker-linux-armv6/docker/ -s /docker-linux-armv7/docker/ -s /docker-darwin-arm64/docker/
57+
TAR_TRANSFORM=-s /packaging/docker/ -s /bin/docker/ \
58+
-s /docker-linux-amd64/docker/ -s /docker-linux-arm64/docker/ \
59+
-s /docker-linux-armv6/docker/ -s /docker-linux-armv7/docker/ \
60+
-s /docker-darwin-amd64/docker/ -s /docker-darwin-arm64/docker/ \
61+
-s /docker-compose-linux-amd64/docker-compose/ -s /docker-compose-linux-arm64/docker-compose/ \
62+
-s /docker-compose-linux-armv6/docker-compose/ -s /docker-compose-linux-armv7/docker-compose/ \
63+
-s /docker-compose-darwin-amd64/docker-compose/ -s /docker-compose-darwin-arm64/docker-compose/
4864
endif
4965

5066
all: cli
@@ -54,11 +70,15 @@ protos:
5470
protoc -I. --go_out=plugins=grpc,paths=source_relative:. ${PROTOS}
5571

5672
.PHONY: cli
57-
cli:
73+
cli: compose-plugin
5874
GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) $(TAGS) -o $(BINARY_WITH_EXTENSION) ./cli
5975

76+
.PHONY: compose-plugin
77+
compose-plugin:
78+
GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY_WITH_EXTENSION) .
79+
6080
.PHONY: cross
61-
cross:
81+
cross: cross-compose-plugin
6282
GOOS=linux GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-linux-amd64 ./cli
6383
GOOS=linux GOARCH=arm64 $(GO_BUILD) $(TAGS) -o $(BINARY)-linux-arm64 ./cli
6484
GOOS=linux GOARM=6 GOARCH=arm $(GO_BUILD) $(TAGS) -o $(BINARY)-linux-armv6 ./cli
@@ -67,6 +87,16 @@ cross:
6787
GOOS=darwin GOARCH=arm64 $(GO_BUILD) $(TAGS) -o $(BINARY)-darwin-arm64 ./cli
6888
GOOS=windows GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-windows-amd64.exe ./cli
6989

90+
.PHONY: cross-compose-plugin
91+
cross-compose-plugin:
92+
GOOS=linux GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-amd64 .
93+
GOOS=linux GOARCH=arm64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-arm64 .
94+
GOOS=linux GOARM=6 GOARCH=arm $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-armv6 .
95+
GOOS=linux GOARM=7 GOARCH=arm $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-armv7 .
96+
GOOS=darwin GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-darwin-amd64 .
97+
GOOS=darwin GOARCH=arm64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-darwin-arm64 .
98+
GOOS=windows GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-windows-amd64.exe .
99+
70100
.PHONY: test
71101
test:
72102
go test $(TAGS) -cover $(shell go list $(TAGS) ./... | grep -vE 'e2e')
@@ -90,14 +120,15 @@ check-go-mod:
90120
.PHONY: package
91121
package: cross
92122
mkdir -p dist
93-
tar -czf dist/docker-linux-amd64.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-linux-amd64
94-
tar -czf dist/docker-linux-arm64.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-linux-arm64
95-
tar -czf dist/docker-linux-armv6.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-linux-armv6
96-
tar -czf dist/docker-linux-armv7.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-linux-armv7
97-
tar -czf dist/docker-darwin-amd64.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-darwin-amd64
98-
tar -czf dist/docker-darwin-arm64.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-darwin-arm64
123+
tar -czf dist/docker-linux-amd64.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-linux-amd64 $(COMPOSE_BINARY)-linux-amd64
124+
tar -czf dist/docker-linux-arm64.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-linux-arm64 $(COMPOSE_BINARY)-linux-arm64
125+
tar -czf dist/docker-linux-armv6.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-linux-armv6 $(COMPOSE_BINARY)-linux-armv6
126+
tar -czf dist/docker-linux-armv7.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-linux-armv7 $(COMPOSE_BINARY)-linux-armv7
127+
tar -czf dist/docker-darwin-amd64.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-darwin-amd64 $(COMPOSE_BINARY)-darwin-amd64
128+
tar -czf dist/docker-darwin-arm64.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-darwin-arm64 $(COMPOSE_BINARY)-darwin-arm64
99129
cp $(BINARY)-windows-amd64.exe $(WORK_DIR)/docker.exe
100-
rm -f dist/docker-windows-amd64.zip && zip dist/docker-windows-amd64.zip -j packaging/LICENSE $(WORK_DIR)/docker.exe
130+
cp $(COMPOSE_BINARY)-windows-amd64.exe $(WORK_DIR)/docker-compose.exe
131+
rm -f dist/docker-windows-amd64.zip && zip dist/docker-windows-amd64.zip -j packaging/LICENSE $(WORK_DIR)/docker.exe $(WORK_DIR)/docker-compose.exe
101132
rm -r $(WORK_DIR)
102133

103134
.PHONY: yamldocs

0 commit comments

Comments
 (0)