Here is my first input (recorded as bash var $services)
It can contain multiple key based values.
[
{
"key": "movies-wikibase-jobrunner",
"subPath": "LocalSettings.php",
"cm": "movies-wikibase-jobrunner-localsettings-override-php"
},
{
"key": "movies-wikibase-jobrunner",
"subPath": "jobrunner-entrypoint.sh",
"cm": "movies-wikibase-jobrunner-jobrunner-entrypoint-sh"
},
{
"key": "movies-wikibase-wdqs-frontend",
"subPath": "wdqs_front_index.html",
"cm": "movies-wikibase-wdqs-frontend-index-html"
}
]
I’d like to use subPath to update deployment.json.
{
"spec": {
"template": {
"spec": {
"containers": [
{
"volumeMounts": [
{
"mountPath": "/usr/share/nginx/html/index.html",
"name": "movies-wikibase-wdqs-frontend-index-html",
"subPath": "wdqs_front_index.html"
}]}]}}}}
I tried to pass subPath as a bash argument to jq but nothing works
cat deployment.json | jq -r --arg services $services
'.spec.template.spec.containers[].volumeMounts[]? |=
{ mountPath: .mountPath, name: (.key, subPath: $services
|select(.key=="movies-wikibase-wdqs-frontend").subPath) }'
How can I achieve this, and is this the good way?
2
Answers
A simple bash loop based answer