Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify the path to the docker config file #1618

Closed
msoub opened this issue Apr 11, 2019 · 12 comments
Closed

Specify the path to the docker config file #1618

msoub opened this issue Apr 11, 2019 · 12 comments
Assignees
Milestone

Comments

@msoub
Copy link

msoub commented Apr 11, 2019

I'd like to specify the path to my Docker config file, by default it reads it from ${user.home}/.docker/config.json.

I can see from CredentialRetrieverFactory#dockerConfig(java.nio.file.Path) that it's possible, however the documentation does not specify how to do it.

Thank you for your help.

@dgageot

This comment has been minimized.

@chanseokoh

This comment has been minimized.

@jontro
Copy link

jontro commented Jan 14, 2020

I successfully worked around the issue.

Using jenkins docker.withRegistry will store the path in an environment variable. https://jenkins.io/doc/book/pipeline/docker/

Using kotlin dsl syntax:

jib {
    var credential: JavaOptional<com.google.cloud.tools.jib.api.Credential> = JavaOptional.empty()
    val path = System.getenv("DOCKER_CONFIG")
    if (path != null) {
        credential = com.google.cloud.tools.jib.registry.credentials.DockerConfigCredentialRetriever("<repository>", Paths.get(path + "/config.json")).retrieve {
            System.out.println(it.message)
        }
    }

    to {
        image = "<image>"
        if (credential.isPresent) {
            auth {
                username = credential.get().username
                password = credential.get().password
            }
        }
    }

}

@chanseokoh
Copy link
Member

@jontro for Jenkins, another way is to use withCredentials() to pass credentials through environment variables. (See https://stackoverflow.com/a/59688329/1701388 for more details.)

    def dockerImage
    stage('publish docker') {
        withCredentials([usernamePassword(credentialsId: 'myregistry-login', passwordVariable: 'DOCKER_REGISTRY_PWD', usernameVariable: 'DOCKER_REGISTRY_USER')]) {
            // assumes Jib is configured to use the environment variables
            sh "./mvnw -ntp jib:build"
        }
    }

@jontro
Copy link

jontro commented Jan 14, 2020

@chanseokoh Not sure how to use that with ecr since credentials are fetched using the aws api. This plugin https://wiki.jenkins.io/display/JENKINS/Amazon+ECR makes it easy to use with withRegistry

@jontro
Copy link

jontro commented Jan 21, 2020

When thinking a bit more about it the environment variable DOCKER_CONFIG is the standard way of changing the location. The plugin could take this into account automatically and fall back to $HOME/.docker

@chanseokoh chanseokoh added this to the v2.2.0 milestone Mar 9, 2020
@chanseokoh
Copy link
Member

It'd be useful to fix the original issue (feature request to specify a Docker config path on the command line). For example, Tekton currently creates a file at /tekton/home/.docker/config.json, where /tekton/home is often not the home directory of a running user. (And for future versions, Tekton proposed a plan to use a fixed directory instead of /tekton/home unrelated to any home.)

@TadCordle TadCordle self-assigned this Apr 13, 2020
@TadCordle
Copy link
Contributor

For now, I think it makes sense to just use the DOCKER_CONFIG environment variable at the plugin level (but keep things as they are in jib-core). In the future we can add a config parameter or system property if it makes sense.

@chanseokoh
Copy link
Member

The environment variable makes sense.

In the future we can add a config parameter or system property if it makes sense.

When deciding this, one factor is that this config is highly platform-dependent.

@loosebazooka
Copy link
Member

fixed by #2402

@TadCordle
Copy link
Contributor

@msoub @jontro We've released v2.2.0, which now respects the DOCKER_CONFIG environment variable.

@jontro
Copy link

jontro commented May 27, 2020

Thanks! can confirm this now works out of the box. Great work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants