kubernetes 使用yq替换docker镜像的名称

nuypyhwy  于 2023-06-05  发布在  Kubernetes
关注(0)|答案(1)|浏览(256)

我正在使用github操作来创建新的图像并将它们推送到注册表。

  1. - name: Build the Docker image
  2. run: docker build . --file Dockerfile --tag ${{secrets.DOCKER_USER}}/book:$GITHUB_SHA

这工作完美。现在,我需要替换图像的值。所以我想到用yq

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. spec:
  4. template:
  5. spec:
  6. containers:
  7. - image: xxxxx/book:main
  1. - name: Replace Image
  2. run: yq -i e '.spec.template.spec.containers.image |= ${{secrets.DOCKER_USER}}/guestbook:$GITHUB_SHA' argo/deployment.yaml

但是得到这个错误Error: 1:43: invalid input text "xxxx/book:..." Error: Process completed with exit code 1.
我该怎么做这个替换?

r1zhe5dt

r1zhe5dt1#

image属性使用正确的json路径表达式,并在替换值上加上引号。
示例:

  1. $ yq '.spec.template.spec.containers.[0].image = "STRING"' argo/deployment.yaml
  2. apiVersion: apps/v1
  3. kind: Deployment
  4. spec:
  5. template:
  6. spec:
  7. containers:
  8. - image: STRING
  9. $ yq --version
  10. yq (https://github.com/mikefarah/yq/) version v4.34.1

相关问题