简体   繁体   中英

Push Docker images to Google Container Registry using fabric8-maven-plugin?

I'm using the fabric8-maven-plugin to build a Docker image on Jenkins running on Google Cloud Platform.

The plugin provides functionality to push the image to a Docker registry, but I can't make it work with Google Container Registry , because it cannot authenticate.

From my Jenkins pipeline, I can access the registry just fine using GCloudBuildWrapper and gcloud docker -- push .

For accessing Docker registries, the fabric8 Maven plugin can be used with credentials or extended authentication , but that seems to be for AWS only at this point.

So is it possible at all to use the fabric8 Maven plugin to push Docker images to Google Container Registry?

Found a solution to my problem in the docs for Google Container Registry . This page offers 2 approaches: Docker credential helper, which I could not get to work unfortunately, and using an access token .

With the access token approach, you use 'oauth2accesstoken' as the username for GCR, and a token generated with gcloud auth application-default print-access-token as the password. Not exactly beautiful, but it works.

Building off of otto's solution:

You need to specify, in ~/.m2/settings.xml :

<server>
  <id>gcr.io/<!--your-registry--></id>
  <username>oauth2accesstoken</username>
  <password><!-- gcloud oauth token goes here --></password>
</server>

Then when you refer to this registry by id in your pom.xml it'll login automatically.

You must use oauth2accesstoken as the username.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM