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

Commit ea46924

Browse files
authored
Merge pull request #1790 from docker/split_compose_v2
2 parents a29d3e6 + 49e7f2d commit ea46924

File tree

177 files changed

+1134
-1233
lines changed

Some content is hidden

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

177 files changed

+1134
-1233
lines changed

aci/aci.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ import (
3939
"github.com/docker/compose-cli/api/client"
4040
"github.com/docker/compose-cli/api/containers"
4141
"github.com/docker/compose-cli/api/context/store"
42-
"github.com/docker/compose-cli/api/errdefs"
43-
"github.com/docker/compose-cli/api/progress"
42+
"github.com/docker/compose-cli/pkg/api"
43+
"github.com/docker/compose-cli/pkg/progress"
4444
)
4545

4646
func createACIContainers(ctx context.Context, aciContext store.AciContext, groupDefinition containerinstance.ContainerGroup) error {
@@ -85,7 +85,7 @@ func autocreateFileshares(ctx context.Context, project *types.Project) error {
8585
}
8686
_, err = clt.VolumeService().Inspect(ctx, fmt.Sprintf("%s/%s", accountName, shareName))
8787
if err != nil { // Not found, autocreate fileshare
88-
if !errdefs.IsNotFoundError(err) {
88+
if !api.IsNotFoundError(err) {
8989
return err
9090
}
9191
aciVolumeOpts := &VolumeCreateOptions{
@@ -198,7 +198,7 @@ func stopACIContainerGroup(ctx context.Context, aciContext store.AciContext, con
198198

199199
result, err := containerGroupsClient.Stop(ctx, aciContext.ResourceGroup, containerGroupName)
200200
if result.IsHTTPStatus(http.StatusNotFound) {
201-
return errdefs.ErrNotFound
201+
return api.ErrNotFound
202202
}
203203
return err
204204
}

aci/backend.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ import (
2626
"github.com/docker/compose-cli/aci/convert"
2727
"github.com/docker/compose-cli/aci/login"
2828
"github.com/docker/compose-cli/api/backend"
29-
"github.com/docker/compose-cli/api/compose"
3029
"github.com/docker/compose-cli/api/containers"
3130
"github.com/docker/compose-cli/api/resources"
3231
"github.com/docker/compose-cli/api/secrets"
3332
"github.com/docker/compose-cli/api/volumes"
33+
"github.com/docker/compose-cli/pkg/api"
3434

3535
"github.com/docker/compose-cli/api/cloud"
3636
apicontext "github.com/docker/compose-cli/api/context"
@@ -115,7 +115,7 @@ func (a *aciAPIService) ContainerService() containers.Service {
115115
return a.aciContainerService
116116
}
117117

118-
func (a *aciAPIService) ComposeService() compose.Service {
118+
func (a *aciAPIService) ComposeService() api.Service {
119119
return a.aciComposeService
120120
}
121121

aci/compose.go

+57-58
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ import (
2727

2828
"github.com/docker/compose-cli/aci/convert"
2929
"github.com/docker/compose-cli/aci/login"
30-
"github.com/docker/compose-cli/api/compose"
3130
"github.com/docker/compose-cli/api/context/store"
32-
"github.com/docker/compose-cli/api/errdefs"
33-
"github.com/docker/compose-cli/api/progress"
31+
"github.com/docker/compose-cli/pkg/api"
32+
"github.com/docker/compose-cli/pkg/progress"
3433
"github.com/docker/compose-cli/utils/formatter"
3534
)
3635

@@ -46,47 +45,47 @@ func newComposeService(ctx store.AciContext) aciComposeService {
4645
}
4746
}
4847

49-
func (cs *aciComposeService) Build(ctx context.Context, project *types.Project, options compose.BuildOptions) error {
50-
return errdefs.ErrNotImplemented
48+
func (cs *aciComposeService) Build(ctx context.Context, project *types.Project, options api.BuildOptions) error {
49+
return api.ErrNotImplemented
5150
}
5251

53-
func (cs *aciComposeService) Push(ctx context.Context, project *types.Project, options compose.PushOptions) error {
54-
return errdefs.ErrNotImplemented
52+
func (cs *aciComposeService) Push(ctx context.Context, project *types.Project, options api.PushOptions) error {
53+
return api.ErrNotImplemented
5554
}
5655

57-
func (cs *aciComposeService) Pull(ctx context.Context, project *types.Project, options compose.PullOptions) error {
58-
return errdefs.ErrNotImplemented
56+
func (cs *aciComposeService) Pull(ctx context.Context, project *types.Project, options api.PullOptions) error {
57+
return api.ErrNotImplemented
5958
}
6059

61-
func (cs *aciComposeService) Create(ctx context.Context, project *types.Project, opts compose.CreateOptions) error {
62-
return errdefs.ErrNotImplemented
60+
func (cs *aciComposeService) Create(ctx context.Context, project *types.Project, opts api.CreateOptions) error {
61+
return api.ErrNotImplemented
6362
}
6463

65-
func (cs *aciComposeService) Start(ctx context.Context, project *types.Project, options compose.StartOptions) error {
66-
return errdefs.ErrNotImplemented
64+
func (cs *aciComposeService) Start(ctx context.Context, project *types.Project, options api.StartOptions) error {
65+
return api.ErrNotImplemented
6766
}
6867

69-
func (cs *aciComposeService) Restart(ctx context.Context, project *types.Project, options compose.RestartOptions) error {
70-
return errdefs.ErrNotImplemented
68+
func (cs *aciComposeService) Restart(ctx context.Context, project *types.Project, options api.RestartOptions) error {
69+
return api.ErrNotImplemented
7170
}
7271

73-
func (cs *aciComposeService) Stop(ctx context.Context, project *types.Project, options compose.StopOptions) error {
74-
return errdefs.ErrNotImplemented
72+
func (cs *aciComposeService) Stop(ctx context.Context, project *types.Project, options api.StopOptions) error {
73+
return api.ErrNotImplemented
7574
}
7675

77-
func (cs *aciComposeService) Pause(ctx context.Context, project string, options compose.PauseOptions) error {
78-
return errdefs.ErrNotImplemented
76+
func (cs *aciComposeService) Pause(ctx context.Context, project string, options api.PauseOptions) error {
77+
return api.ErrNotImplemented
7978
}
8079

81-
func (cs *aciComposeService) UnPause(ctx context.Context, project string, options compose.PauseOptions) error {
82-
return errdefs.ErrNotImplemented
80+
func (cs *aciComposeService) UnPause(ctx context.Context, project string, options api.PauseOptions) error {
81+
return api.ErrNotImplemented
8382
}
8483

85-
func (cs *aciComposeService) Copy(ctx context.Context, project *types.Project, options compose.CopyOptions) error {
86-
return errdefs.ErrNotImplemented
84+
func (cs *aciComposeService) Copy(ctx context.Context, project *types.Project, options api.CopyOptions) error {
85+
return api.ErrNotImplemented
8786
}
8887

89-
func (cs *aciComposeService) Up(ctx context.Context, project *types.Project, options compose.UpOptions) error {
88+
func (cs *aciComposeService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error {
9089
return progress.Run(ctx, func(ctx context.Context) error {
9190
return cs.up(ctx, project)
9291
})
@@ -130,12 +129,12 @@ func (cs aciComposeService) warnKeepVolumeOnDown(ctx context.Context, projectNam
130129
return nil
131130
}
132131

133-
func (cs *aciComposeService) Down(ctx context.Context, projectName string, options compose.DownOptions) error {
132+
func (cs *aciComposeService) Down(ctx context.Context, projectName string, options api.DownOptions) error {
134133
if options.Volumes {
135-
return errors.Wrap(errdefs.ErrNotImplemented, "--volumes option is not supported on ACI")
134+
return errors.Wrap(api.ErrNotImplemented, "--volumes option is not supported on ACI")
136135
}
137136
if options.Images != "" {
138-
return errors.Wrap(errdefs.ErrNotImplemented, "--rmi option is not supported on ACI")
137+
return errors.Wrap(api.ErrNotImplemented, "--rmi option is not supported on ACI")
139138
}
140139
return progress.Run(ctx, func(ctx context.Context) error {
141140
logrus.Debugf("Down on project with name %q", projectName)
@@ -149,14 +148,14 @@ func (cs *aciComposeService) Down(ctx context.Context, projectName string, optio
149148
return err
150149
}
151150
if cg.IsHTTPStatus(http.StatusNoContent) {
152-
return errdefs.ErrNotFound
151+
return api.ErrNotFound
153152
}
154153

155154
return err
156155
})
157156
}
158157

159-
func (cs *aciComposeService) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) {
158+
func (cs *aciComposeService) Ps(ctx context.Context, projectName string, options api.PsOptions) ([]api.ContainerSummary, error) {
160159
groupsClient, err := login.NewContainerGroupsClient(cs.ctx.SubscriptionID)
161160
if err != nil {
162161
return nil, err
@@ -171,23 +170,23 @@ func (cs *aciComposeService) Ps(ctx context.Context, projectName string, options
171170
return nil, fmt.Errorf("no containers found in ACI container group %s", projectName)
172171
}
173172

174-
res := []compose.ContainerSummary{}
173+
res := []api.ContainerSummary{}
175174
for _, container := range *group.Containers {
176175
if isContainerVisible(container, group, false) {
177176
continue
178177
}
179-
var publishers []compose.PortPublisher
178+
var publishers []api.PortPublisher
180179
urls := formatter.PortsToStrings(convert.ToPorts(group.IPAddress, *container.Ports), convert.FQDN(group, cs.ctx.Location))
181180
for i, p := range *container.Ports {
182-
publishers = append(publishers, compose.PortPublisher{
181+
publishers = append(publishers, api.PortPublisher{
183182
URL: urls[i],
184183
TargetPort: int(*p.Port),
185184
PublishedPort: int(*p.Port),
186185
Protocol: string(p.Protocol),
187186
})
188187
}
189188
id := getContainerID(group, container)
190-
res = append(res, compose.ContainerSummary{
189+
res = append(res, api.ContainerSummary{
191190
ID: id,
192191
Name: id,
193192
Project: projectName,
@@ -199,26 +198,26 @@ func (cs *aciComposeService) Ps(ctx context.Context, projectName string, options
199198
return res, nil
200199
}
201200

202-
func (cs *aciComposeService) List(ctx context.Context, opts compose.ListOptions) ([]compose.Stack, error) {
201+
func (cs *aciComposeService) List(ctx context.Context, opts api.ListOptions) ([]api.Stack, error) {
203202
containerGroups, err := getACIContainerGroups(ctx, cs.ctx.SubscriptionID, cs.ctx.ResourceGroup)
204203
if err != nil {
205204
return nil, err
206205
}
207206

208-
var stacks []compose.Stack
207+
var stacks []api.Stack
209208
for _, group := range containerGroups {
210209
if _, found := group.Tags[composeContainerTag]; !found {
211210
continue
212211
}
213-
state := compose.RUNNING
212+
state := api.RUNNING
214213
for _, container := range *group.ContainerGroupProperties.Containers {
215214
containerState := convert.GetStatus(container, group)
216-
if containerState != compose.RUNNING {
215+
if containerState != api.RUNNING {
217216
state = containerState
218217
break
219218
}
220219
}
221-
stacks = append(stacks, compose.Stack{
220+
stacks = append(stacks, api.Stack{
222221
ID: *group.ID,
223222
Name: *group.Name,
224223
Status: state,
@@ -227,41 +226,41 @@ func (cs *aciComposeService) List(ctx context.Context, opts compose.ListOptions)
227226
return stacks, nil
228227
}
229228

230-
func (cs *aciComposeService) Logs(ctx context.Context, projectName string, consumer compose.LogConsumer, options compose.LogOptions) error {
231-
return errdefs.ErrNotImplemented
229+
func (cs *aciComposeService) Logs(ctx context.Context, projectName string, consumer api.LogConsumer, options api.LogOptions) error {
230+
return api.ErrNotImplemented
232231
}
233232

234-
func (cs *aciComposeService) Convert(ctx context.Context, project *types.Project, options compose.ConvertOptions) ([]byte, error) {
235-
return nil, errdefs.ErrNotImplemented
233+
func (cs *aciComposeService) Convert(ctx context.Context, project *types.Project, options api.ConvertOptions) ([]byte, error) {
234+
return nil, api.ErrNotImplemented
236235
}
237236

238-
func (cs *aciComposeService) Kill(ctx context.Context, project *types.Project, options compose.KillOptions) error {
239-
return errdefs.ErrNotImplemented
237+
func (cs *aciComposeService) Kill(ctx context.Context, project *types.Project, options api.KillOptions) error {
238+
return api.ErrNotImplemented
240239
}
241240

242-
func (cs *aciComposeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) {
243-
return 0, errdefs.ErrNotImplemented
241+
func (cs *aciComposeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) {
242+
return 0, api.ErrNotImplemented
244243
}
245244

246-
func (cs *aciComposeService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) error {
247-
return errdefs.ErrNotImplemented
245+
func (cs *aciComposeService) Remove(ctx context.Context, project *types.Project, options api.RemoveOptions) error {
246+
return api.ErrNotImplemented
248247
}
249248

250-
func (cs *aciComposeService) Exec(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) {
251-
return 0, errdefs.ErrNotImplemented
249+
func (cs *aciComposeService) Exec(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) {
250+
return 0, api.ErrNotImplemented
252251
}
253-
func (cs *aciComposeService) Top(ctx context.Context, projectName string, services []string) ([]compose.ContainerProcSummary, error) {
254-
return nil, errdefs.ErrNotImplemented
252+
func (cs *aciComposeService) Top(ctx context.Context, projectName string, services []string) ([]api.ContainerProcSummary, error) {
253+
return nil, api.ErrNotImplemented
255254
}
256255

257-
func (cs *aciComposeService) Events(ctx context.Context, project string, options compose.EventsOptions) error {
258-
return errdefs.ErrNotImplemented
256+
func (cs *aciComposeService) Events(ctx context.Context, project string, options api.EventsOptions) error {
257+
return api.ErrNotImplemented
259258
}
260259

261-
func (cs *aciComposeService) Port(ctx context.Context, project string, service string, port int, options compose.PortOptions) (string, int, error) {
262-
return "", 0, errdefs.ErrNotImplemented
260+
func (cs *aciComposeService) Port(ctx context.Context, project string, service string, port int, options api.PortOptions) (string, int, error) {
261+
return "", 0, api.ErrNotImplemented
263262
}
264263

265-
func (cs *aciComposeService) Images(ctx context.Context, projectName string, options compose.ImagesOptions) ([]compose.ImageSummary, error) {
266-
return nil, errdefs.ErrNotImplemented
264+
func (cs *aciComposeService) Images(ctx context.Context, projectName string, options api.ImagesOptions) ([]api.ImageSummary, error) {
265+
return nil, api.ErrNotImplemented
267266
}

aci/containers.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"github.com/docker/compose-cli/aci/login"
3434
"github.com/docker/compose-cli/api/containers"
3535
"github.com/docker/compose-cli/api/context/store"
36-
"github.com/docker/compose-cli/api/errdefs"
36+
"github.com/docker/compose-cli/pkg/api"
3737
)
3838

3939
type aciContainerService struct {
@@ -107,7 +107,7 @@ func (cs *aciContainerService) Start(ctx context.Context, containerID string) er
107107
var aerr autorest.DetailedError
108108
if ok := errors.As(err, &aerr); ok {
109109
if aerr.StatusCode == http.StatusNotFound {
110-
return errdefs.ErrNotFound
110+
return api.ErrNotFound
111111
}
112112
}
113113
return err
@@ -207,7 +207,7 @@ func (cs *aciContainerService) Delete(ctx context.Context, containerID string, r
207207
cg, err := containerGroupsClient.Get(ctx, cs.ctx.ResourceGroup, groupName)
208208
if err != nil {
209209
if cg.StatusCode == http.StatusNotFound {
210-
return errdefs.ErrNotFound
210+
return api.ErrNotFound
211211
}
212212
return err
213213
}
@@ -216,15 +216,15 @@ func (cs *aciContainerService) Delete(ctx context.Context, containerID string, r
216216
status := convert.GetStatus(container, cg)
217217

218218
if status == convert.StatusRunning {
219-
return errdefs.ErrForbidden
219+
return api.ErrForbidden
220220
}
221221
}
222222
}
223223

224224
cg, err := deleteACIContainerGroup(ctx, cs.ctx, groupName)
225225
// Delete returns `StatusNoContent` if the group is not found
226226
if cg.IsHTTPStatus(http.StatusNoContent) {
227-
return errdefs.ErrNotFound
227+
return api.ErrNotFound
228228
}
229229
if err != nil {
230230
return err
@@ -244,7 +244,7 @@ func (cs *aciContainerService) Inspect(ctx context.Context, containerID string)
244244
return containers.Container{}, err
245245
}
246246
if cg.IsHTTPStatus(http.StatusNoContent) || cg.ContainerGroupProperties == nil || cg.ContainerGroupProperties.Containers == nil {
247-
return containers.Container{}, errdefs.ErrNotFound
247+
return containers.Container{}, api.ErrNotFound
248248
}
249249

250250
var cc containerinstance.Container
@@ -257,7 +257,7 @@ func (cs *aciContainerService) Inspect(ctx context.Context, containerID string)
257257
}
258258
}
259259
if !found {
260-
return containers.Container{}, errdefs.ErrNotFound
260+
return containers.Container{}, api.ErrNotFound
261261
}
262262

263263
return convert.ContainerGroupToContainer(containerID, cg, cc, cs.ctx.Location), nil

aci/context.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828
"github.com/pkg/errors"
2929

3030
"github.com/docker/compose-cli/api/context/store"
31-
"github.com/docker/compose-cli/api/errdefs"
32-
"github.com/docker/compose-cli/utils/prompt"
31+
"github.com/docker/compose-cli/pkg/api"
32+
"github.com/docker/compose-cli/pkg/prompt"
3333
)
3434

3535
// ContextParams options for creating ACI context
@@ -41,7 +41,7 @@ type ContextParams struct {
4141
}
4242

4343
// ErrSubscriptionNotFound is returned when a required subscription is not found
44-
var ErrSubscriptionNotFound = errors.Wrapf(errdefs.ErrNotFound, "subscription")
44+
var ErrSubscriptionNotFound = errors.Wrapf(api.ErrNotFound, "subscription")
4545

4646
// IsSubscriptionNotFoundError returns true if the unwrapped error is IsSubscriptionNotFoundError
4747
func IsSubscriptionNotFoundError(err error) bool {
@@ -145,7 +145,7 @@ func (helper contextCreateACIHelper) chooseGroup(ctx context.Context, subscripti
145145
group, err := helper.selector.Select("Select a resource group", groupNames)
146146
if err != nil {
147147
if err == terminal.InterruptErr {
148-
return resources.Group{}, errdefs.ErrCanceled
148+
return resources.Group{}, api.ErrCanceled
149149
}
150150

151151
return resources.Group{}, err

0 commit comments

Comments
 (0)