-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --init option to docker service create
#479
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave this a spin against a docker 17.09-rc2 daemon (which should have the SwarmKit changes), but it didn't seem to work;
Creating a service with --init
looks to create the right request:
docker service create --init --name initservice nginx:alpine
Sep 20 10:29:30 moby root: time="2017-09-20T10:29:30.328450671Z" level=debug msg="Calling POST /v1.31/services/create"
Sep 20 10:29:30 moby root: time="2017-09-20T10:29:30.328573170Z" level=debug msg="form data: {\"EndpointSpec\":{\"Mode\":\"vip\"},\"Labels\":{},\"Mode\":{\"Replicated\":{}},\"Name\":\"initservice\",\"TaskTemplate\":{\"ContainerSpec\":{\"DNSConfig\":{},\"Image\":\"nginx:alpine@sha256:83f10f82722087e6944e0348b2e64a95baf247135de7c237f4dec7729a386d7f\",\"Init\":true},\"ForceUpdate\":0,\"Placement\":{\"Platforms\":[{\"Architecture\":\"amd64\",\"OS\":\"linux\"}]},\"Resources\":{\"Limits\":{},\"Reservations\":{}}}}"
(formatted for readability): I can see the Init
to be passed to the daemon;
{
"EndpointSpec": {
"Mode": "vip"
},
"Labels": {
},
"Mode": {
"Replicated": {
}
},
"Name": "initservice",
"TaskTemplate": {
"ContainerSpec": {
"DNSConfig": {
},
"Image": "nginx:alpine@sha256:83f10f82722087e6944e0348b2e64a95baf247135de7c237f4dec7729a386d7f",
"Init": true
},
"ForceUpdate": 0,
"Placement": {
"Platforms": [
{
"Architecture": "amd64",
"OS": "linux"
}
]
},
"Resources": {
"Limits": {
},
"Reservations": {
}
}
}
}
However, I don't see the Init
option set for the task backing the container:
docker container inspect initservice.1.xsbsrewdxj0eq9sg2sa51p3im | grep Init
(no response)
Inspecting the service also does not show this information, which may be either because there's an issue there, or because docker service inspect
does not show all information;
[
{
"ID": "3kju7dy0b7gz0hl8mf5yy93ub",
"Version": {
"Index": 90211
},
"CreatedAt": "2017-09-20T10:29:30.329124642Z",
"UpdatedAt": "2017-09-20T10:29:30.329124642Z",
"Spec": {
"Name": "initservice",
"Labels": {},
"TaskTemplate": {
"ContainerSpec": {
"Image": "nginx:alpine@sha256:83f10f82722087e6944e0348b2e64a95baf247135de7c237f4dec7729a386d7f",
"StopGracePeriod": 10000000000,
"DNSConfig": {}
},
"Resources": {
"Limits": {},
"Reservations": {}
},
"RestartPolicy": {
"Condition": "any",
"Delay": 5000000000,
"MaxAttempts": 0
},
"Placement": {
"Platforms": [
{
"Architecture": "amd64",
"OS": "linux"
}
]
},
"ForceUpdate": 0,
"Runtime": "container"
},
"Mode": {
"Replicated": {
"Replicas": 1
}
},
"UpdateConfig": {
"Parallelism": 1,
"FailureAction": "pause",
"Monitor": 5000000000,
"MaxFailureRatio": 0,
"Order": "stop-first"
},
"RollbackConfig": {
"Parallelism": 1,
"FailureAction": "pause",
"Monitor": 5000000000,
"MaxFailureRatio": 0,
"Order": "stop-first"
},
"EndpointSpec": {
"Mode": "vip"
}
},
"Endpoint": {
"Spec": {}
}
}
]
cli/command/service/create.go
Outdated
@@ -57,6 +57,8 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command { | |||
flags.SetAnnotation(flagDNSSearch, "version", []string{"1.25"}) | |||
flags.Var(&opts.hosts, flagHost, "Set one or more custom host-to-IP mappings (host:ip)") | |||
flags.SetAnnotation(flagHost, "version", []string{"1.25"}) | |||
flags.BoolVar(&opts.init, flagInit, false, "Use an init inside each service container to forward signals and reap processes") | |||
flags.SetAnnotation(flagInit, "version", []string{"1.30"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will probably need to be bumped to 1.33 (1.32 has shipped in a release)
@@ -55,6 +55,7 @@ type ContainerSpec struct { | |||
User string `json:",omitempty"` | |||
Groups []string `json:",omitempty"` | |||
Privileges *Privileges `json:",omitempty"` | |||
Init bool `json:",omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As commented in moby/moby#34529 (comment) - SwarmKit changes are merged in moby/moby, so can you open a pull request there to make the required changes in moby/moby?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(you, or @denverdino ) 😇
Actually, nevermind, the daemon API of course doesn't yet put this property forward, so that's expected that it's non functional yet. 😅 |
Bumping moby/moby in #679, which should bring in the required changes |
Any chances we'll see this feature in near future? |
Codecov Report
@@ Coverage Diff @@
## master #479 +/- ##
=========================================
Coverage ? 48.52%
=========================================
Files ? 199
Lines ? 16409
Branches ? 0
=========================================
Hits ? 7962
Misses ? 8033
Partials ? 414 |
I am carrying this PR, opened upstream PR on moby and swarmkit |
btw, design LGTM 👼 |
Just so that I don't forget;
|
b4d89ba
to
cbaf7d9
Compare
|
Oh, last two bullets;
|
cli/command/service/update_test.go
Outdated
} | ||
cspec := spec.TaskTemplate.ContainerSpec | ||
|
||
// Update with --stop-signal=SIGUSR1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/--stop-signal=SIGUSR1/--init=true/
cli/command/service/update_test.go
Outdated
updateService(nil, nil, flags, spec) | ||
assert.Check(t, is.Equal(true, cspec.Init)) | ||
|
||
// Update without --stop-signal, no change |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/--stop-signal/--init/
cli/command/service/update_test.go
Outdated
updateService(nil, nil, flags, spec) | ||
assert.Check(t, is.Equal(true, cspec.Init)) | ||
|
||
// Update with --stop-signal=SIGWINCH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/--stop-signal= SIGWINCH/--init=false/
Validate is complaining:
|
@thaJeztah actually there is quite some field from the ContainerSpec that are not showed in the |
We should probably add more of those yes; but it's a good start to make sure that new fields are not missed Moby vendoring was updated in another PR, so looks like we can continue on this one 👍 |
docker service create
docker service create
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 😝
test is complaining 😂
|
--container-label-add list Add or update a container label | ||
--container-label-rm list Remove a container label by its key | ||
--credential-spec credential-spec Credential spec for managed service account (Windows only) | ||
--args command Service command args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this whole file changed from using spaces to tabs; can you revert that change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😱
A test is failing:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after the test is fixed
Signed-off-by: Timothy Higinbottom <[email protected]> Signed-off-by: Vincent Demeester <[email protected]>
Follow up for the compose-file format; #1129 |
Helps #51, but requires more work to add stack/compose v3 file support.
See moby/swarmkit#2350, and moby/moby#34529. We've got it all set in swarmkit, this should finish the CLI, and we're waiting on the final pieces in moby.
- What I did
Added a
--init
option todocker service create
- How I did it
Added an options string (
flagInit
), the swarm api field inopts.ToService()
, and a boolean flag innewCreateCommand()
I also changed a line in the vendor code to add the
Init
option to the swarm container api. I understand I'm not supposed to do this, but I'll wait till they get a PR into moby/moby, and then do the vendoring properly.- How to verify it
Run the tests for the
service
subcommand. Since the daemon doesn't supportinit
for swarm yet, it won't actually do anything.- Description for the changelog
Add --init option to
docker service create
Waiting for the following PR to get merged
deepcopy.Copy
panicing with BoolValue moby/swarmkit#2652init
on services moby/moby#37183