Skip to content

Commit 5052466

Browse files
committed
introduce development mode
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent 9e17a09 commit 5052466

File tree

9 files changed

+59
-3
lines changed

9 files changed

+59
-3
lines changed

cmd/compose/create.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type createOptions struct {
4949
quietPull bool
5050
scale []string
5151
AssumeYes bool
52+
Development bool
5253
}
5354

5455
func createCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *cobra.Command {
@@ -120,6 +121,7 @@ func runCreate(ctx context.Context, _ command.Cli, backend api.Service, createOp
120121
Timeout: createOpts.GetTimeout(),
121122
QuietPull: createOpts.quietPull,
122123
AssumeYes: createOpts.AssumeYes,
124+
Development: createOpts.Development,
123125
})
124126
}
125127

cmd/compose/up.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *c
181181
}
182182
return pflag.NormalizedName(name)
183183
})
184+
flags.BoolVar(&create.Development, "dev", false, "Enable development mode.")
184185
return upCmd
185186
}
186187

@@ -276,6 +277,7 @@ func runUp(
276277
Timeout: createOptions.GetTimeout(),
277278
QuietPull: createOptions.quietPull,
278279
AssumeYes: createOptions.AssumeYes,
280+
Development: createOptions.Development,
279281
}
280282

281283
if upOptions.noStart {

docs/reference/compose_up.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ If the process is interrupted using `SIGINT` (ctrl + C) or `SIGTERM`, the contai
3232
| `--attach-dependencies` | `bool` | | Automatically attach to log output of dependent services |
3333
| `--build` | `bool` | | Build images before starting containers |
3434
| `-d`, `--detach` | `bool` | | Detached mode: Run containers in the background |
35+
| `--dev` | `bool` | | Enable development mode. |
3536
| `--dry-run` | `bool` | | Execute command in dry run mode |
3637
| `--exit-code-from` | `string` | | Return the exit code of the selected service container. Implies --abort-on-container-exit |
3738
| `--force-recreate` | `bool` | | Recreate containers even if their configuration and image haven't changed |

docs/reference/docker_compose_up.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ options:
9898
experimentalcli: false
9999
kubernetes: false
100100
swarm: false
101+
- option: dev
102+
value_type: bool
103+
default_value: "false"
104+
description: Enable development mode.
105+
deprecated: false
106+
hidden: false
107+
experimental: false
108+
experimentalcli: false
109+
kubernetes: false
110+
swarm: false
101111
- option: exit-code-from
102112
value_type: string
103113
description: |

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,5 @@ exclude (
212212
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
213213
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2
214214
)
215+
216+
replace github.com/compose-spec/compose-go/v2 => github.com/ndeloof/compose-go/v2 v2.0.1-0.20250708142739-c0abfc6735a4

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004 h1:lkAMpLVBDaj17e
8080
github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004/go.mod h1:yMWuSON2oQp+43nFtAV/uvKQIFpSPerB57DCt9t8sSA=
8181
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE=
8282
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4=
83-
github.com/compose-spec/compose-go/v2 v2.7.1 h1:EUIbuaD0R/J1KA+FbJMNbcS9+jt/CVudbp5iHqUllSs=
84-
github.com/compose-spec/compose-go/v2 v2.7.1/go.mod h1:TmjkIB9W73fwVxkYY+u2uhMbMUakjiif79DlYgXsyvU=
8583
github.com/containerd/cgroups/v3 v3.0.5 h1:44na7Ud+VwyE7LIoJ8JTNQOa549a8543BmzaJHo6Bzo=
8684
github.com/containerd/cgroups/v3 v3.0.5/go.mod h1:SA5DLYnXO8pTGYiAHXz94qvLQTKfVM5GEVisn4jpins=
8785
github.com/containerd/console v1.0.5 h1:R0ymNeydRqH2DmakFNdmjR2k0t7UPuiOV/N/27/qqsc=
@@ -361,6 +359,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m
361359
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
362360
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
363361
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
362+
github.com/ndeloof/compose-go/v2 v2.0.1-0.20250708142739-c0abfc6735a4 h1:k84kfjgpENwxepUBphnu7DdHve4k+J+JLgKa52+mI1Q=
363+
github.com/ndeloof/compose-go/v2 v2.0.1-0.20250708142739-c0abfc6735a4/go.mod h1:Zow/3eYNOnl2T4qLGZEizf8d/ht1qfy09G7WGOSzGOY=
364364
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
365365
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
366366
github.com/onsi/ginkgo v1.12.0 h1:Iw5WCbBcaAAd0fpRb1c9r5YCylv4XDoCSigm1zLevwU=

pkg/api/api.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ type CreateOptions struct {
225225
// QuietPull makes the pulling process quiet
226226
QuietPull bool
227227
// AssumeYes assume "yes" as answer to all prompts and run non-interactively
228-
AssumeYes bool
228+
AssumeYes bool
229+
Development bool
229230
}
230231

231232
// StartOptions group options of the Start API

pkg/compose/create.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ func (s *composeService) Create(ctx context.Context, project *types.Project, cre
6868
}
6969

7070
func (s *composeService) create(ctx context.Context, project *types.Project, options api.CreateOptions) error {
71+
if options.Development {
72+
project = enableDevelopmentMode(project)
73+
}
74+
7175
if len(options.Services) == 0 {
7276
options.Services = project.ServiceNames()
7377
}

pkg/compose/development.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 "github.com/compose-spec/compose-go/v2/types"
20+
21+
func enableDevelopmentMode(project *types.Project) *types.Project {
22+
for name, service := range project.Services {
23+
dev := service.Develop
24+
if dev == nil {
25+
continue
26+
}
27+
service.Ports = append(service.Ports, dev.Ports...)
28+
if len(dev.Command) > 0 {
29+
service.Command = dev.Command
30+
}
31+
project.Services[name] = service
32+
}
33+
return project
34+
}

0 commit comments

Comments
 (0)