docker stack: text after an unbraced `$VAR` is dropped when it starts with `-`, `:-`, `?` or `:?`
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 87/100
Direção de pesquisa
Comece em cli/compose/template/template.go e examine defaultPattern, especialmente como os grupos named e braced usam o padrão de substituição. Reproduza com o arquivo compose fornecido e docker stack config; depois, compare com a saída esperada e com docker compose config. O trabalho está concluído quando o texto após variáveis sem chaves permanece literal, enquanto os modificadores entre chaves continuam funcionando.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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
- Linguagem predominante
- Go
- Estrelas
- 6.1k
- Forks
- 2.2k
- Merge médio
- 15h 11min
- PRs com merge (30d)
- 42
Preparar o ambiente
- Inclui um Dockerfile ou arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de docker/cli
-
filename completion on `docker load -i`Talvez já em andamento @cra assumiu há 4 dias. Abertakind/feature status/0-triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Mantenedores costumam responder em até 1 dia
-
docker build treats uppercase HTTP(S) URLs as local pathsTalvez já em andamento @TanvirTian assumiu há 11 dias. Abertakind/bug status/0-triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
Mantenedores costumam responder em até 1 dia
-
`docker context export` writes a truncated tar archiveTalvez já em andamento @2arian3 assumiu há 26 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 92/100
Mantenedores costumam responder em até 1 dia
-
Truncating log lines at 75 characters makes them useless.Talvez já em andamento @locker95 assumiu há 71 dias. Abertakind/bug status/0-triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
docker/cli#7176 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
cli-plugins/hooks: max-message enforcement is off by oneTalvez já em andamento @fallintoplace assumiu há 149 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
docker/cli#7005 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
Issues semelhantes
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
Mantenedores costumam responder em até 1 dia
-
Mend: dependency security vulnerability
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
kube-tarian/sigrun#202 ·
-
good first issue help wanted
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
eugenioenko/ttt#1085 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
fullsend-ai/fullsend#8688 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
question raised-by:verifier
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
medici-finance/assay#4013 ·
Mantenedores costumam responder em até 1 dia