How to pass private repository credentials to maven docker image when using Google Cloud Build
Asked Answered
A

1

5

I am trying to use Google Cloud Build to build my Java app. It allows to use so called cloud builders - docker images of different builders. I am using Maven. So the problem is that I have to use a private repository (artifactory) to deploy artifacts. This rep is password protected and I do not know how to pass these credentials to GC maven docker container.

I see that the only possible way is:

  1. To run the shell script which will update the maven container settings.xml with something like:

    <servers>
        <server>
            <id>myRepoName</id>
            <username>${server.username}</username>
            <password>${server.password}</password>
        </server>
    </servers>
    
  2. set env variables in the cloudbuild.yml

Are there any other elegant ways to achieve what I'm trying to?

Archaeo answered 15/9, 2019 at 19:22 Comment(6)
To the best of my knowledge, your repository needs to use SSH keys for access control. Here is an example for GitHub private repositories. cloud.google.com/cloud-build/docs/access-private-github-reposHescock
@JohnHanley I think OP is asking about Maven repository not a git repository in github.Hallee
@KarthikeyanVaithilingam - the OP is asking about Cloud Build. My link is an example of accessing a private repository.Hescock
@JohnHanley your link provide example to access github's private repository, but OP need to access private Artifactory repository.Hallee
@KarthikeyanVaithilingam - I got that point. I am showing how to access a private repository so that he might figure out what he needs. If I knew the answer I would post an answer instead of a comment. Since you feel the need to critique my comments, please post the correct answer yourself.Hescock
You may also take a look at this.Teri
P
7

I solved this by doing the following:

  1. Create a Google Cloud Storage bucket and upload your desired settings.xml. I'm using GitHub Packages, following their documentation

  2. Setup your cloudbuild.yaml with the following:

steps:
  - name: gcr.io/cloud-builders/gsutil
    args: ['cp', 'gs://ci-maven/settings.xml', 'settings.xml']
  - name: maven:3.6.3-jdk-11-openj9
    entrypoint: 'mvn'
    args: ['--settings', '/workspace/settings.xml', 'install']
images: ['gcr.io/schemata-np/scheduler']

First, it copies the settings.xml to the current directory (/workspace). Then, using the Docker Maven image directly, we add --settings /workspace/settings.xml to our args to specify the settings.xml location. From there, Google Cloud Build was able to pull my private GitHub package to properly install my project.

It may be possible to copy to /usr/share/maven/ref/ in the first step to allow the default Maven Docker behavior, but I was not able to get this to work. If anyone does, let me know!

Based on this answer to a slightly different question about caching artifacts and Google Cloud Build documentation

Pedicure answered 3/1, 2020 at 1:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.