英文:
Using yq to replace name of docker image
问题
我正在使用GitHub Actions创建新的镜像并将其推送到镜像仓库。
这部分代码可以不翻译:
- name: Build the Docker image
run: docker build . --file Dockerfile --tag ${{secrets.DOCKER_USER}}/book:$GITHUB_SHA
这个方法运行得很好。现在,我需要替换镜像的值。所以我考虑使用yq:
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
containers:
- image: xxxxx/book:main
- name: 替换镜像
run: yq -i e '.spec.template.spec.containers.image |= ${{secrets.DOCKER_USER}}/guestbook:$GITHUB_SHA' argo/deployment.yaml
但是出现了这个错误:“错误:1:43:无效的输入文本“xxxx/book:...”
错误:进程以退出码1完成。”
我应该如何进行这个替换操作?
英文:
I'm using github actions for creating new images and pushing them to a registry.
- name: Build the Docker image
run: docker build . --file Dockerfile --tag ${{secrets.DOCKER_USER}}/book:$GITHUB_SHA
This works perfectly. Now, I need to replace the value of the image. So I thought of using yq
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
containers:
- image: xxxxx/book:main
- name: Replace Image
run: yq -i e '.spec.template.spec.containers.image |= ${{secrets.DOCKER_USER}}/guestbook:$GITHUB_SHA' argo/deployment.yaml
But getting this error Error: 1:43: invalid input text "xxxx/book:..."
Error: Process completed with exit code 1.
How I would need to do this replacement?
答案1
得分: 2
使用正确的 JSON 路径表达式来定位 image
属性,并引用替换值。
示例:
$ yq '.spec.template.spec.containers.[0].image = "STRING"' argo/deployment.yaml
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
containers:
- image: STRING
$ yq --version
yq (https://github.com/mikefarah/yq/) 版本 v4.34.1
英文:
Use the correct json path expression to the image
property and quote the replacement value.
Example:
$ yq '.spec.template.spec.containers.[0].image = "STRING"' argo/deployment.yaml
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
containers:
- image: STRING
$ yq --version
yq (https://github.com/mikefarah/yq/) version v4.34.1
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论