Add --env-file flag to docker create service#24844
Conversation
369631e to
575ebf5
Compare
|
Thanks @yongtang For reference, this was not yet decided on; we may want to make a design document, describing which flags make sense for services (and which not); also that some flags are very platform specific, so may need a more "generic" approach so that they can be used in a cross-platform Swarm (win/linux/solaris?) |
|
Thanks @thaJeztah. No worries. Just keep me posted. |
|
@thaJeztah While I'm impartial, I just wanted to further make a point on this. This particular flag seems critical for practical use of services. Every company that I have experience with uses "--env-file" for starting their containers as their microservices use a non-trivial number of environment vars that are not ideal to bake into the image itself. Until this feature is added, I'll need to either use this PR or create a env-file-to-parameters cli generator that wraps docker service create. |
575ebf5 to
76528c9
Compare
|
@jadbox thanks for the feedback; yes, I can see it being useful, but we're getting really close to GA, and still have a lot of work to do. I understand the current implementation is not perfect, but should be doable. I want to prevent making "quick" decisions, and being stuck with those. For example, maybe we should take #12997 into account (or at least discuss it) |
|
I guess this is fine being that it's a client-only feature. |
4c581af to
109af59
Compare
|
Generally, I'm ok with this as well, some thoughts:
|
|
@thaJeztah Currently So I feel like having something like so that user does not need to pass many From that angle, I am not sure we want to have But that is just my personal opinion. Let me know if we want to support |
I would be definitely against a with regard to:
Possibly that's a matter of properly documenting what the |
|
Ok, we discussed this in the maintainers meeting, and we think just adding it to |
109af59 to
fd2c3e3
Compare
cli/command/service/opts.go
Outdated
There was a problem hiding this comment.
Should env-variables be sorted and duplicates removed here ?
There was a problem hiding this comment.
Thanks @thaJeztah. I updated the PR and duplicates of the env entries have been removed. I leave the order alone (not sorted), as that may potentially be different behavior from docker run. But let me know if we want to change both.
There was a problem hiding this comment.
My thought behind this was that in services, a change in order can result in the service being re-deployed. Not sure if that's important in this case, but worth checking.
fd2c3e3 to
73d40c3
Compare
cli/command/service/opts.go
Outdated
There was a problem hiding this comment.
Hm, having the same key twice, would result in the first value being overwritten by the second one, so wondering if we should keep both, or simply de-duplicate by key
There was a problem hiding this comment.
Thanks @thaJeztah, the PR has been updated with duplicated keys removed.
30a5ec2 to
e1b263c
Compare
e1b263c to
3cff8a4
Compare
cli/command/service/opts.go
Outdated
There was a problem hiding this comment.
We discussed this and think it's better to sort by key, and not trying to preserve the original sort order. This would make sure that the env-vars are always sorted the same way (and duplicates are already removed earlier, so that's no problem)
There was a problem hiding this comment.
Actually, with env, we need to preserve order.
There was a problem hiding this comment.
@stevvooe order is preserved before removing the duplicates (see the loop above), do you think we should not do that?
cli/command/service/opts.go
Outdated
There was a problem hiding this comment.
So, the algorithm for env replacement is simple but inefficient (really):
for _, env := newEnv { // need to process each var, in order
k, _ := splitEnv(env)
for i, current := currentEnv { // remove duplicates
if current == env {
continue next // no update required, may hide this behind flag to preserve order or newEnv
}
if strings.HasPrefix(current, k+"=") {
currentEnv = append(currentEnv[:i], currentEnv[i+1:]...)
}
}
currentEnv = append(currentEnv, env)
}
In practice, N is small enough to keep this from being too slow. There are probably ways to make this more efficient.
It preserves the order of the new and old set, while replacing duplicates. It also assumes that there are no existing duplicates.
3cff8a4 to
bd2607f
Compare
bd2607f to
a550868
Compare
|
Thanks @thaJeztah @stevvooe for the review. The PR has been updated. Please take a look and let me know if there are any issues. |
a550868 to
bd9217b
Compare
cli/command/service/opts.go
Outdated
There was a problem hiding this comment.
currentEnv := make([]string, 0, len(envVariables))
This fix tries to address the issue in 24712 and add `--env-file` file to `docker create service`. Related documentation has been updated. An additional integration has been added. This fix fixes 24712. Signed-off-by: Yong Tang <[email protected]>
bd9217b to
ee3105c
Compare
|
LGTM |
thaJeztah
left a comment
There was a problem hiding this comment.
LGTM (code and docs)
ping @albers @sdurrheimer as this needs an update to the completion scripts
- What I did
This fix tries to address the issue in #24712 and add
--env-filefile todocker create service.- How I did it
The flag has been added and related documentation has been updated.
- How to verify it
An additional integration has been added.
- Description for the changelog
Add
--env-fileflag todocker create service.- A picture of a cute animal (not mandatory but encouraged)
This fix fixes #24712.
Signed-off-by: Yong Tang [email protected]