dockergitlabgitlab-ciartifactorykaniko

Unable to build and push Docker image into (private) Artifactory from GitLab CI using kaniko


I'm designing a GitLab CI pipeline to build a Docker image for a given service.

This is how (the relevant excerpt from) the Gitlab CI manifest looks like so far:

...

publish-docker-image:
  stage: publish
  dependencies:
    - assemble
  image:
    name: docker.tld.com/namespace/kaniko:latest # At work they offer a custom kaniko image
    entrypoint: [""]
  script:
    - mkdir --parents /kaniko/.docker/
    - mv $kaniko_config /kaniko/.docker/config.json # $kaniko_config is a file variable from GitLab CI
    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination artifactory.tld.com/artifactory/docker-snapshot/organization/project/kaniko-test:0.1.0

The $kaniko_config file translates into this JSON:

{
  "auths": {
    "https://artifactory.tld.com/": {
      "username": "the_real_username",
      "password": "the_real_password"
    }
  }
}

Now every time I run the pipeline I get this output:

$ mkdir --parents /kaniko/.docker/
$ mv $kaniko_config /kaniko/.docker/config.json
$ cat /kaniko/.docker/config.json
{
  "auths": {
    "https://artifactory.tld.com/": {
      "username": "the_real_username",
      "password": "the_real_password"
    }
  }
}
$ /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination artifactory.tld.com/artifactory/docker-snapshot/organization/project/kaniko-test:0.1.0
error checking push permissions -- make sure you entered the correct tag name, and that you are authenticated correctly, and try again: checking push permission for "artifactory.tld.com/artifactory/docker-snapshot/organization/project/kaniko-test:0.1.0": creating push check transport for artifactory.tld.com failed: GET https://artifactory.tld.com/v2/: : Not Found
Cleaning up file based variables

What am I doing wrong here? Moreover, I don't know why the error message have https://artifactory.tld.com/v2/ (the /v2) on it since I'm not using anything like that.


Solution

  • To anyone who encounters this issue in the future - the kaniko-config.json file should have the following structure:

    {
      "auths": {
        "<artifactory-docker-registry>": {
          ...
        }
      }
    }
    

    The "artifactory-docker-registry" can be retrieved using the Set Me Up button in the JFrog platform UI.