Reputation: 27486
I am building docker images with dynamic tags in CloudBuilder. I would like to be able to then run that same image, but I'm having trouble getting it to work.
Here's what I've got:
steps:
- id: "Store value for docker image tag"
name: ubuntu
entrypoint: bash
args:
- -c
- date +%Y%m%d%H%M%S > /workspace/image_tag.txt
- name: 'gcr.io/cloud-builders/docker'
entrypoint: bash
args: [ '-c', 'docker build -t gcr.io/blah/my_image:$(cat /workspace/image_tag.txt) -f src/Dockerfile ./src' ]
- name: 'gcr.io/cloud-builders/docker'
entrypoint: bash
args: [ '-c', 'docker push gcr.io/blah/my_image:$(cat /workspace/image_tag.txt)' ]
...
- name: 'gcr.io/blah/my_image:$(cat /workspace/image_tag.txt)'
entrypoint: /bin/sh
args:
- -c
# - execute some commands and script within the image...
(gcr.io/blah/my_image
is a custom builder)
Obviously, the name 'gcr.io/blah/my_image:$(cat /workspace/image_tag.txt)' does not work, I get an error:
Your build failed to run: generic::invalid_argument: invalid build: invalid build step name "gcr.io/blah/my_image:$(cat /workspace/image_tag.txt)": could not parse reference: gcr.io/blah/my_image:$(cat /workspace/image_tag.txt)
The image gets pushed fine, but I want the a step that runs the image that got pushed earlier. Did I just mess up the syntax? If I can't do it as easily as I want, is there some other way to do this?
Upvotes: 0
Views: 274
Reputation: 75765
If you want to interpret the content, use " instead of ', like that
- name: 'gcr.io/cloud-builders/docker'
entrypoint: bash
args: [ '-c', "docker build -t gcr.io/blah/my_image:$(cat /workspace/image_tag.txt) -f src/Dockerfile ./src" ]
- name: 'gcr.io/cloud-builders/docker'
entrypoint: bash
args: [ '-c', "docker push gcr.io/blah/my_image:$(cat /workspace/image_tag.txt)" ]
Upvotes: 1