-
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
Fix substitution with non-empty env-var #1392
Fix substitution with non-empty env-var #1392
Conversation
This should be cherry-picked in the 18.09 branch as well ping @anokun7 @vdemeester @silvin-lubecki PTAL |
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 🐸
(but test is red ?)
Oh, interesting; I tried my new test, but the existing ones broke 🤔 let me check why |
Looks like the "soft default" doesn't actually check for empty values, so that's an existing bug as well (which went unnoticed because we never reached that part). I'll have a look after dinner 😅 |
Due to a typo, substitution would not work if the given environment-variable was set. Given the following docker compose file; ```yaml version: "3.7" services: app: image: nginx:${version:-latest} ``` Deploying a stack with `$version` set would ignore the `$version` environment variable, and use the default value instead; ```bash version=alpine docker stack deploy -c docker-compose.yml foobar Creating network foobar_default Creating service foobar_app docker service ls ID NAME MODE REPLICAS IMAGE PORTS rskkjxe6sm0w foobar_app replicated 1/1 nginx:latest ``` This patch also fixes "soft default" not detecting empty environment variables, only non-set environment variables. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
4e1d8ad
to
ec3daea
Compare
Codecov Report
@@ Coverage Diff @@
## master #1392 +/- ##
==========================================
+ Coverage 54.88% 54.89% +0.01%
==========================================
Files 293 293
Lines 19428 19434 +6
==========================================
+ Hits 10663 10669 +6
Misses 8089 8089
Partials 676 676 |
Fixed; should be good to go now |
@@ -176,15 +176,21 @@ func extractVariable(value interface{}, pattern *regexp.Regexp) ([]extractedValu | |||
|
|||
// Soft default (fall back if unset or empty) | |||
func softDefault(substitution string, mapping Mapping) (string, bool, error) { | |||
return withDefault(substitution, mapping, "-:") | |||
sep := ":-" | |||
if !strings.Contains(substitution, sep) { |
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 guess it can be factorized with hardDefault
but I don't see an obvious and/or clean way to do it.
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.
Yes, I was looking at that, but adding an (e.g.) checkIfSet func(val) bool
argument felt like over engineering just to prevent just a few lines of duplicated code.
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
…on_empty_value Fix substitution with non-empty env-var Signed-off-by: Lifubang <lifubang@acmcoder.com>
fixes #1391
Due to a typo introduced in #1249, substitution would not work if the given environment-variable was set.
Given the following docker compose file;
Deploying a stack with
$version
set would ignore the$version
environment variable, and use the default value instead;