I have been using Dockerfile and cloudbuild.yaml to build images succesfully,
But now I need to have the BRANCH_NAME value inside the Dockerfile, and since this requirement showed up, my docker builds have started failing.
Here below is my cloudbuild.yaml file :
steps:
- name: 'gcr.io/cloud-builders/docker'
env:
- '$BRANCH_NAME=${_$BRANCH_NAME}'
entrypoint: 'bash'
args: ['-c', 'docker pull gcr.io/$PROJECT_ID/github.com/videoo-io/videoo-render-$BRANCH_NAME:latest || exit 0']
- name: 'gcr.io/cloud-builders/docker'
env:
- '$BRANCH_NAME=${_$BRANCH_NAME}'
args: [
'build',
"--build-arg=ENV=$_BRANCH_NAME",
'-t', 'gcr.io/$PROJECT_ID/github.com/videoo-io/videoo-render-$BRANCH_NAME:latest',
'--cache-from', 'gcr.io/$PROJECT_ID/github.com/videoo-io/videoo-render-$BRANCH_NAME:latest',
'.'
]
substitutions:
_BRANCH_NAME: $BRANCH_NAME
options:
dynamic_substitutions: true
images: ['gcr.io/$PROJECT_ID/github.com/videoo-io/videoo-render-$BRANCH_NAME:latest']
timeout: 7200s
And below is my Dockerfile :
ARG BRANCH_NAME=$_BRANCH_NAME
FROM --platform=amd64 gcr.io/videoo7/github.com/videoo-io/videoo-render-${BRANCH_NAME}:latest
EXPOSE 80
COPY . /app
WORKDIR /app
RUN cd /app && cmake . && make
# Define default command.
RUN chmod +x /app/entrypoint.sh
ENTRYPOINT ["/app/entrypoint.sh"]
I cannot get BRANCH_NAME correctly as a substitute variable as suggested here : Google Cloud Build Substitute Variables Link
This is the failing build logs :
Step #0: a561219ed4f5: Pull complete
Step #0: Digest: sha256:09a3f79713e906ff0640bac04c9cb74523ee33e930afe8683f15f2cd5904fbc1
Step #0: Status: Downloaded newer image for gcr.io/videoo7/github.com/videoo-io/videoo-render-main:latest
Step #0: gcr.io/videoo7/github.com/videoo-io/videoo-render-main:latest
Finished Step #0
Starting Step #1
Step #1: Already have image (with digest): gcr.io/cloud-builders/docker
Step #1: Sending build context to Docker daemon 196.9MB
Step #1: Step 1/8 : ARG BRANCH_NAME=$_BRANCH_NAME
Step #1: Step 2/8 : FROM --platform=amd64 gcr.io/videoo7/github.com/videoo-io/videoo-render-${BRANCH_NAME}:latest
Step #1: invalid reference format
Finished Step #1
ERROR
ERROR: build step 1 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1
Here is my google cloud build trigger setup :
What shall I do in order to have BRANCH_NAME value inside the Dockerfile ?