I struggle to build and then push a docker image to Google artifacts. I’ve tried different approaches I hope someone can help me getting this done correct.
What I like to achieve is to build and push an image in one step (if possible).
The following setup doesn’t work because the authentication is not handed to the next step.
Is it possible to authenticate gcloud in one step where I need to use the google/cloud-sdk image, and push in the next step where I need to docker image?
Are gcloud auth commands generating any files with tokens, or some kind of environment variable that are used during docker push? If so, you can use artifacts to store the login data during setup, and those artifacts will be downloaded automatically in the next stage (your build_api job), and placed in the same folder structure as they were in the previous job.
Thanks for the quick answer, but the solution wasn’t so easy for me at least.
The way I solved it was to install google cloud cli in the image and authenticate with docker login.
You can technically also eliminate the “setup” job, and just download and prepare the binary in the same job (build_api) - not sure if there is any need for separation. Alltogether might be slightly faster with one job as well.