docker stack: text after an unbraced `$VAR` is dropped when it starts with `-`, `:-`, `?` or `:?`
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
cli/compose/template/template.goから始めて、defaultPatternを調べます。特に、namedグループとbracedグループが置換パターンをどのように使うかを確認してください。提供されたcomposeファイルとdocker stack configで再現し、期待される出力とdocker compose configを比較します。中括弧のない変数の後のテキストがそのまま残り、中括弧で囲まれた修飾子は引き続き機能すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Description
In compose files used with docker stack config and docker stack deploy, an unbraced variable that is followed by -, :-, ? or :? is parsed as if it were the braced form with a modifier. The text after the variable is consumed as a default value or an error message.
For example nginx:$NGINX_VERSION-alpine is treated like nginx:${NGINX_VERSION-alpine}, and http://localhost:$PORT?ready=1 like http://localhost:${PORT?ready=1}.
The compose specification, docker compose, and shell parameter expansion only support modifiers in the braced form (${VAR:-default}); for $VAR the following characters are literal.
Reproduce
# c.yml
version: "3.8"
services:
web:
image: "nginx:$NGINX_VERSION-alpine"
healthcheck:
test: ["CMD", "wget", "-q", "http://localhost:$PORT?ready=1"]
$ NGINX_VERSION=1.27 PORT=8080 docker stack config -c c.yml
version: "3.8"
services:
web:
healthcheck:
test:
- CMD
- wget
- -q
- http://localhost:8080
image: nginx:1.27
With PORT unset, the command fails with required variable PORT is missing a value: ready=1.
Expected behavior
$ NGINX_VERSION=1.27 PORT=8080 docker stack config -c c.yml
...
- http://localhost:8080?ready=1
image: nginx:1.27-alpine
This is what docker compose config prints for the same file.
Root cause
In cli/compose/template/template.go the named group of defaultPattern uses the same sub-pattern as the braced group:
subst = "[_a-z][_a-z0-9]*(?::?[-?][^}]*)?"
...
"%s(?i:(?P<escaped>%s)|(?P<named>%s)|{(?P<braced>%s)}|(?P<invalid>))",
delimiter, delimiter, subst, subst,
so the optional (?::?[-?][^}]*) modifier suffix also matches after an unbraced name, and everything up to the next } (or the end of the string) is consumed.
Version
master at 52a2671034814f1ec6145aa8238c5fd4f92d5ee7
- 主要言語
- Go
- スター
- 6.1k
- フォーク
- 2.2k
- 平均マージ
- 15時間 11分
- マージ済み PR(30日)
- 42
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
docker/cli のほかの issue
-
filename completion on `docker load -i`対応中かも @cra が 5 日前に担当しました。 オープンkind/feature status/0-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
docker build treats uppercase HTTP(S) URLs as local paths対応中かも @TanvirTian が 11 日前に担当しました。 オープンkind/bug status/0-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
`docker context export` writes a truncated tar archive対応中かも @2arian3 が 27 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
メンテナーはふだん 1 日以内に返信
-
Truncating log lines at 75 characters makes them useless.対応中かも @locker95 が 72 日前に担当しました。 オープンkind/bug status/0-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
cli-plugins/hooks: max-message enforcement is off by one対応中かも @fallintoplace が 150 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
native
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
prime-radiant-inc/evener#4839 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
521xueweihan/HelloGitHub#4073 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
goharbor/terraform-provider-harbor#655 · コメント 1 件 ·
-
bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
syncthing/syncthing#10935 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信