This is similar to Passing files from Google Cloud Container Builder to Docker build task but I can't seem to figure out what the difference is.
I am attempting to build a simple Java program and package it into a Container using Google Cloud Build. I am following mostly along with https://cloud.google.com/build/docs/building/build-java but using my own repo which is a fork of https://github.com/jchraibi/cloud-native-workshop
steps:
- name: 'maven:3-openjdk-11'
args:
- test
- '-f=code/inventory-quarkus/pom.xml'
entrypoint: mvn
- name: 'maven:3-openjdk-11'
args:
- package
- '-f=code/inventory-quarkus/pom.xml'
- '-Dmaven.test.skip=true'
entrypoint: mvn
- name: 'gcr.io/cloud-builders/docker'
args:
- 'build'
- '-t'
- 'gcr.io/$PROJECT_ID/inventory-quarkus'
- '--build-arg=JAR_FILE=workspace/code/inventory-quarkus/target/$_BUILD_ARTIFACT'
- '-f'
- 'code/inventory-quarkus/gcp/Dockerfile'
- '/workspace'
The above are the build steps. When the maven package completes, the output is as follows:
Step #1: [INFO] [io.quarkus.deployment.pkg.steps.JarResultBuildStep] Building thin jar: /workspace/code/inventory-quarkus/target/inventory-quarkus-1.0.0-SNAPSHOT-runner.jar
However, no matter what combination of copying things and contexts I attempt, I can't seem to find inventory-quarkus-1.0.0-SNAPSHOT-runner.jar
anywhere in the filesystem of the Docker build. Note that the Dockerfile lives in a different place than where the target of the build seems to end up.
FROM openjdk:11
ARG JAR_FILE=JAR_FILE_MUST_BE_SPECIFIED_AS_BUILD_ARG
RUN find .
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java", "-Djava.security.edg=file:/dev/./urandom","-jar","/app.jar"]
In the logs, interestingly, the output of the find
command doesn't have a workspace folder at all. I'm sure this has something to do with the fact that the Dockerfile
is not in the root of the repo, but I just can't find the right invocation.
The link at the beginning of this post to the other thread ended up using an extra step with the git
image to do some kind of copy, but I don't see why that would be required given all of the Google examples don't have to go through any hoops like that.
The build containers documentation has the following statement:
If your Dockerfile and source code are in different directories, add -f and the path to the Dockerfile to the list of arguments in the args field:
This is definitely what I'm doing in my build step. It's clearly finding the Dockerfile, because it's processing the find and the copy. I just can't seem to find where/how to get the Maven package step's workspace folder into the builder, or what the source path would be to copy the file from it.