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

allow to set DOCKER_CONFIG to a file #2894

Open
sebhoss opened this issue Dec 7, 2023 · 2 comments
Open

allow to set DOCKER_CONFIG to a file #2894

sebhoss opened this issue Dec 7, 2023 · 2 comments
Labels
gitlab kind/feature-request priority/p2 High impact feature/bug. Will get a lot of users happy work-around-available

Comments

@sebhoss
Copy link

sebhoss commented Dec 7, 2023

We are using GitLab CI pipelines and would like to set DOCKER_CONFIG to a file instead of a directory so that we can use CI variables of type file. The current working approach in GitLab looks similar to this (see official docs):

build:
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  script:
    - echo "{\"auths\":{\"${REGISTRY}\":{\"auth\":\"$(printf "%s:%s" "${USER}" "${PASSWORD}" | base64 | tr -d '\n')\"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor ...

The above examples requires 3 variables (REGISTRY, USER, PASSWORD) to write a file into the kaniko container. We can use file variables to reduce this to:

build:
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  variables:
    DOCKER_CONFIG: ${DOCKER_CONFIG_JSON}
  script:
    - /kaniko/executor ...

In this example, DOCKER_CONFIG_JSON is the file variable which contains the entire JSON document. GitLab will automatically add that file to the container and populate the DOCKER_CONFIG_JSON value with the path to the created file.

I have noticed that there is https://github.com/GoogleContainerTools/kaniko/blob/main/pkg/util/gcr_util.go which does the right thing(tm) but does not appear to be used anywhere. The various other places where DOCKER_CONFIG is read all assume that it is a directory.

Triage Notes for the Maintainers

Description Yes/No
Please check if this a new feature you are proposing
Please check if the build works in docker but not in kaniko
Please check if this error is seen when you use --cache flag
Please check if your dockerfile is a multistage dockerfile
@braykov
Copy link

braykov commented Dec 7, 2023

Did you try this:

cp ${DOCKER_CONFIG_JSON} /kaniko/.docker/config.json

So, you don't have to keep 3 variables.
You could still have the whole config file in one CI/CD variable (of type file) in GitLab.

@sebhoss
Copy link
Author

sebhoss commented Dec 7, 2023

Yeah that works and its my current workaround, however I would still prefer to just use the variables section as a nice-to-have feature.

That said, I have checked other tools and none of them seem to support setting DOCKER_CONFIG to a file, so I can understand if kaniko won't support this either..

@JeromeJu JeromeJu added kind/feature-request work-around-available priority/p2 High impact feature/bug. Will get a lot of users happy gitlab labels Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gitlab kind/feature-request priority/p2 High impact feature/bug. Will get a lot of users happy work-around-available
Projects
None yet
Development

No branches or pull requests

3 participants