question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Maven jib:dockerBuild in Google Cloud Build fails

See original GitHub issue

Description of the issue: Attempting to build and deploy a container from within Google Cloud Build. jib:build wants me to authenticate within the same project where GCB and GCR run. It feels wrong to attempt to add this so I am attempting to use jib:dockerBuild.

  - name: 'gcr.io/cloud-builders/mvn'
    id: MVN_COMPILE
    args: ['compile','jib:dockerBuild', '-Dmaven.test.skip=true', '-Ddocker.image.prefix=gcr.io/$PROJECT_ID', '-s', '.mvn/settings.xml']

images:
  - 'gcr.io/$PROJECT_ID/my-company-project'

But I am getting an error that Google Cloud Build does not have a docker daemon running. I can run both the jib:build and jib:dockerBuild locally, but need the CI to work as a trigger in Google Cloud Builder.

Steps to reproduce: Simply using Google cloud build via triggers or gcloud builds submit .

Environment:

jib-maven-plugin Configuration:

            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>jib-maven-plugin</artifactId>
                <version>1.0.0</version>
            </plugin>

Log output:

Step #3 - "MVN_COMPILE": [ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:1.0.0:dockerBuild (default-cli) on project my-company-project: Build to Docker daemon failed, perhaps you should make sure Docker is installed and you have correct privileges to run it -> [Help 1]

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
chanseokohcommented, Mar 13, 2020

UPDATE: the following workarounds to sidestep the Docker credential issue are no longer needed in recent Jib versions.

obsolete workarounds

Another option is to have docker-credential-gcr on $PATH by whatever means:

- name: gcr.io/cloud-builders/mvn
  entrypoint: bash
  args:
  - -c
  - |
    export PATH=$$PATH:. &&
    curl -fsSL https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/v1.5.0/docker-credential-gcr_linux_amd64-1.5.0.tar.gz | tar zxv &&
    chmod +x docker-credential-gcr &&
    mvn -B compile jib:build -Dimage=gcr.io/$PROJECT_ID/chanseok-test

or

- name: gcr.io/cloud-builders/mvn
  dir: /usr/local/bin
  entrypoint: bash
  args:
  - -c
  - |
    curl -fsSL https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/v1.5.0/docker-credential-gcr_linux_amd64-1.5.0.tar.gz | tar zxv &&
    chmod +x docker-credential-gcr
  volumes:
  - name: usr.local.bin
    path: /usr/local/bin
- name: gcr.io/cloud-builders/mvn
  args: ['-B', 'compile', 'jib:build', '-Dimage=gcr.io/$PROJECT_ID/chanseok-test']
  volumes:
  - name: usr.local.bin
    path: /usr/local/bin
3reactions
chanseokohcommented, Mar 13, 2020

Hi @dgvigil,

GCB recently dropped Docker from gcr.io/cloud-builders/mvn. In fact, now the image has essentially become the official mvn Docker Hub image. Therefore, jib:dockerBuild no longer works.

Rather, jib:build should just work and push the built image to the GCR. Unforunately, as you mentioned, you have an authentication issue with jib:build on GCB (internal bug: 124388903).

UPDATE: the following workaround for the authentication issue is no longer necessary with recent Jib versions. Note you can’t still do jib:dockerBuild on gcr.io/cloud-builders/mvn, because the Maven image doesn’t have Docker installed.

obsolete workaround

However, there is a bug that prevents jib:build from working. On GCB, /builder/home/.docker/config.json, which holds the GCR credentials, is not being copied/linked into /root/.docker/config.json.

That said, one ugly workaround you can use is to link that file yourself. Something like

steps:
- name: gcr.io/cloud-builders/mvn
  dir: /root
  entrypoint: bash
  args:
  - -c
  - # Links the Docker config to /root/.docker/config.json so that Jib picks it up.
    # Note that this is only a temporary workaround.
    # See https://github.com/GoogleContainerTools/jib/pull/1500.
    |
    mkdir .docker &&
    ln -s /builder/home/.docker/config.json .docker/config.json
  volumes:
  - name: user.home
    path: /root

- name: gcr.io/cloud-builders/mvn
  args: ['-B', 'compile', 'jib:build', '-Dmaven.test.skip=true', ...]
  volumes:
  - name: user.home
    path: /root

(I know this is not pretty. Should be unnecessary once the bug is fixed.)

Or,

# This is untested, but should work basically.
- name: gcr.io/cloud-builders/mvn
  entrypoint: bash
  args:
  - -c
  - |
    ln -s /builder/home/.docker /root/.docker &&
    mvn -B compile jib:build -Dimage=gcr.io/$PROJECT_ID/chanseok-test

Or, see https://github.com/GoogleContainerTools/jib/issues/1500#issuecomment-477364975.

Read more comments on GitHub >

github_iconTop Results From Across the Web

error:Failed to execute goal com.google.cloud.tools:jib-maven ...
This is a "generic error message". My solution is: docker system prune. This clean the docker images/container and the build docker images ...
Read more >
Troubleshooting build errors | Cloud Build Documentation
This page provides troubleshooting strategies as well as solutions for some common error messages that you might see when running a build.
Read more >
google/jib - Gitter
... got this [ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:0.10.1:build (default) on project fcq-api-launcher: Build image failed, ...
Read more >
Jib Build - Skaffold
Skaffold requires using Jib v1.4.0 or later. Skaffold supports building with Jib. locally and; remotely on Google Cloud Build. Jib Maven and ...
Read more >
Dockerizing Java Apps using Jib - Baeldung
We'll take a simple Spring Boot application and build its Docker image ... mvn compile com.google.cloud.tools:jib-maven-plugin:2.5.0:build ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found