yq json 到 yaml 添加引号到 docker 撰写标签
yq json to yaml add quotes to docker compose labels
我正在尝试从 JSON 创建一个 docker compose 覆盖 YAML 文件,其中包括 N 个 Traefik 标签。我目前有以下设置:
{
"version": "3.7",
"services": {
"traefik": {
"labels": [
"traefik.http.routers.traefik-secure.tls.domains[0].main=domain1.local",
"traefik.http.routers.traefik-secure.tls.domains[0].sans=*.domain1.local",
"traefik.http.routers.traefik-secure.tls.domains[1].main=domain2.local",
"traefik.http.routers.traefik-secure.tls.domains[1].sans=*.domain2.local",
"traefik.http.routers.traefik-secure.tls.domains[N].main=domainN.local",
"traefik.http.routers.traefik-secure.tls.domains[N].sans=*.domainN.local"
]
}
}
}
当前使用以下命令:
yq e -P docker-compose.override.json
这导致:
version: "3.7"
services:
traefik:
labels:
- traefik.http.routers.traefik-secure.tls.domains[0].main=domain1.local
- traefik.http.routers.traefik-secure.tls.domains[0].sans=*.domain1.local
- traefik.http.routers.traefik-secure.tls.domains[1].main=domain2.local
- traefik.http.routers.traefik-secure.tls.domains[1].sans=*.domain2.local
- traefik.http.routers.traefik-secure.tls.domains[N].main=domainN.local
- traefik.http.routers.traefik-secure.tls.domains[N].sans=*.domainN.local
但我想像这样在 traefik 标签周围加上双引号:
version: "3.7"
services:
traefik:
labels:
- "traefik.http.routers.traefik-secure.tls.domains[0].main=domain1.local"
- "traefik.http.routers.traefik-secure.tls.domains[0].sans=*.domain1.local"
- "traefik.http.routers.traefik-secure.tls.domains[1].main=domain2.local"
- "traefik.http.routers.traefik-secure.tls.domains[1].sans=*.domain2.local"
- "traefik.http.routers.traefik-secure.tls.domains[N].main=domainN.local"
- "traefik.http.routers.traefik-secure.tls.domains[N].sans=*.domainN.local"
我将如何实现这一目标?我可以编辑 JSON,但我更愿意更好地使用 yq
。
yq e '... style="" | with(.traefik.labels[] ; . style="double")' docker-compose.override.json
产生所需的响应。
version: "3.7"
traefik:
labels:
- "traefik.http.routers.traefik-secure.tls.domains[0].main=domain1.local"
- "traefik.http.routers.traefik-secure.tls.domains[0].sans=*.domain1.local"
- "traefik.http.routers.traefik-secure.tls.domains[1].main=domain2.local"
- "traefik.http.routers.traefik-secure.tls.domains[1].sans=*.domain2.local"
- "traefik.http.routers.traefik-secure.tls.domains[N].main=domainN.local"
- "traefik.http.routers.traefik-secure.tls.domains[N].sans=*.domainN.local"
说明
... style=""
为所有节点设置漂亮的打印样式。
with(.traefik.labels[] ; . style="double")
仅 .traefik.labels
设置带双引号的样式
或者也可以使用 yq e '... style="double"' docker-compose.override.json
将键用双引号引起来。
我正在尝试从 JSON 创建一个 docker compose 覆盖 YAML 文件,其中包括 N 个 Traefik 标签。我目前有以下设置:
{
"version": "3.7",
"services": {
"traefik": {
"labels": [
"traefik.http.routers.traefik-secure.tls.domains[0].main=domain1.local",
"traefik.http.routers.traefik-secure.tls.domains[0].sans=*.domain1.local",
"traefik.http.routers.traefik-secure.tls.domains[1].main=domain2.local",
"traefik.http.routers.traefik-secure.tls.domains[1].sans=*.domain2.local",
"traefik.http.routers.traefik-secure.tls.domains[N].main=domainN.local",
"traefik.http.routers.traefik-secure.tls.domains[N].sans=*.domainN.local"
]
}
}
}
当前使用以下命令:
yq e -P docker-compose.override.json
这导致:
version: "3.7"
services:
traefik:
labels:
- traefik.http.routers.traefik-secure.tls.domains[0].main=domain1.local
- traefik.http.routers.traefik-secure.tls.domains[0].sans=*.domain1.local
- traefik.http.routers.traefik-secure.tls.domains[1].main=domain2.local
- traefik.http.routers.traefik-secure.tls.domains[1].sans=*.domain2.local
- traefik.http.routers.traefik-secure.tls.domains[N].main=domainN.local
- traefik.http.routers.traefik-secure.tls.domains[N].sans=*.domainN.local
但我想像这样在 traefik 标签周围加上双引号:
version: "3.7"
services:
traefik:
labels:
- "traefik.http.routers.traefik-secure.tls.domains[0].main=domain1.local"
- "traefik.http.routers.traefik-secure.tls.domains[0].sans=*.domain1.local"
- "traefik.http.routers.traefik-secure.tls.domains[1].main=domain2.local"
- "traefik.http.routers.traefik-secure.tls.domains[1].sans=*.domain2.local"
- "traefik.http.routers.traefik-secure.tls.domains[N].main=domainN.local"
- "traefik.http.routers.traefik-secure.tls.domains[N].sans=*.domainN.local"
我将如何实现这一目标?我可以编辑 JSON,但我更愿意更好地使用 yq
。
yq e '... style="" | with(.traefik.labels[] ; . style="double")' docker-compose.override.json
产生所需的响应。
version: "3.7"
traefik:
labels:
- "traefik.http.routers.traefik-secure.tls.domains[0].main=domain1.local"
- "traefik.http.routers.traefik-secure.tls.domains[0].sans=*.domain1.local"
- "traefik.http.routers.traefik-secure.tls.domains[1].main=domain2.local"
- "traefik.http.routers.traefik-secure.tls.domains[1].sans=*.domain2.local"
- "traefik.http.routers.traefik-secure.tls.domains[N].main=domainN.local"
- "traefik.http.routers.traefik-secure.tls.domains[N].sans=*.domainN.local"
说明
... style=""
为所有节点设置漂亮的打印样式。with(.traefik.labels[] ; . style="double")
仅.traefik.labels
设置带双引号的样式
或者也可以使用 yq e '... style="double"' docker-compose.override.json
将键用双引号引起来。