0
votes

I am trying to GCP Cloud Build based on Trigger of Spring Boot java Application Code Pushed in Bit Bucket. so far I am doing it manually, coping code into GCP VM, build there, create Docker Image, push to GCP Container Registry and Deploy on Kubernetes Engine which is working fine. I need to automate the build on the basis of the trigger every time I push the code. I have code on my private bitbucket. GCP Container Registry has access to my Bitbucket Repository. my docker file is

> FROM java:8 WORKDIR / ADD
> build/libs/SpringBootApplication-0.0.1-SNAPSHOT.jar
> SpringBootApplication.jar EXPOSE 8080 ENTRYPOINT
> ["java","-jar","SpringBootApplication.jar"]

but at the time of build, its giving error that

SpringBootApplication.jar is not available-- no such file or directory. 

I know it because on GCP VM I have not clone and build the code. do I have to write clone and build code in Dockerfile as well ?? if yes then what's the point of authenticating Bitbucket with GCP Cloud Build.

1

1 Answers

0
votes

Could be because the working directory of cloudbuild is initially /workspace

https://cloud.google.com/cloud-build/docs/build-config

So that’s why the file is not found, your WORKDIR is /

Also this would not solve your whole CI/CD problem as you still need to update your cluster.

Instead of using the Dockerfile only, you need to create a cloudbuild.yaml file with steps

Step 1, build docker image (make sure to use cache to make it faster) Step 2, tag it Step 3, push to registry Step 4, update gke cluster