3
votes

I have a google cloud container build with the following steps

  1. gcr.io/cloud-builders/mvn to run a mvn clean package cmd
  2. gcr.io/cloud-builders/docker to create a docker image

My docker image includes and will run tomcat.

Both these steps work fine independently.

How can I copy the artifacts built by step 1 into the correct folder of my docker container? I need to move either the built wars or specific lib files from step 1 to the tomcat dir in my docker container.

Echoing out the /workspace and /root dir in my Dockerfile doesn't show the artifacts. I think I'm misunderstanding this relationship.

Thanks!

Edit:

I ended up changing the Dockerfile to set the WORKDIR to /workspace

and

COPY /{files built by maven} {target}

1
Shouldn't your dockerfile copy all the resources it needs during the build step? You can get a dockerfile runner as a maven plugin. - K.Nicholas
i was unsure of the source path to use when copying files in the docker build step, since echoing out /workspace didn't show anything. however, setting the workdir to /workspace and copying seemed to work - Jon

1 Answers

0
votes

The working directory is a persistent volume mounted in the builder containers, by default under /workdir. You can find more details in the documentation here https://cloud.google.com/container-builder/docs/build-config#dir

I am not sure what is happening in your case. But there is an example with a Maven step and a Docker build step in the documentation of the gcr.io/cloud-builders/mvn builder. https://github.com/GoogleCloudPlatform/cloud-builders/tree/master/mvn/examples/spring_boot. I suggest you compare with your files.

If it does not help, could you share your Dockerfile and cloudbuild.yaml. Please make sure you remove any sensitive information.

Also, you can inspect the working directory by running the build locally https://cloud.google.com/container-builder/docs/build-debug-locally#preserve_intermediary_artifacts