Kerry
Kerry

Reputation: 323

Publishing Docker Image by Kaniko Gitlab CI/CD to JFrog as Docker Registry

I am very new to this concept and I believe I am trying to solve a simple problem. I am trying to make a CI/CD pipeline that builds a Dockerfile and deploys the image to JFrog so that I can pull it in for other CI/CD pipelines. We are using a Kubernetes cluster so I am using Kaniko to try this. The below yml passes. I believe I need to add --destination and point it to my jfrog repo.

Has anyone been successful using Kaniko and publishing to a different Artifactory than GitLab?

build-container:
  stage: build
  needs: []
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  script:
    - mkdir -p /kaniko/.docker
    - >-
      /kaniko/executor
      --context ${CI_PROJECT_DIR}/src/main/docker
      --dockerfile Dockerfile --no-push
    - echo ${CI_REGISTRY}
    - echo ${CI_REGISTRY_USER}

Upvotes: 2

Views: 2554

Answers (1)

Harsh Manvar
Harsh Manvar

Reputation: 30110

You can refer below the example below, yes you have to use the --destination it will work with other registries also like GCR, ECR

build:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  script:
    - mkdir -p /kaniko/.docker
    - echo "{\"auths\":{\"${CI_REGISTRY}\":{\"auth\":\"$(printf "%s:%s" "${CI_REGISTRY_USER}" "${CI_REGISTRY_PASSWORD}" | base64 | tr -d '\n')\"}}}" > /kaniko/.docker/config.json
    - >-
      /kaniko/executor
      --context "${CI_PROJECT_DIR}"
      --dockerfile "${CI_PROJECT_DIR}/Dockerfile"
      --destination "${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG}"
  rules:
    - if: $CI_COMMIT_TAG

you just have to takecare about the auth part of docker repo and kaniko will push the image

AWS ECR :

build:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  script:
    - echo "{\"credsStore\":\"ecr-login\",\"credHelpers\":{\"$AWS_ACCOUNT_ID.dkr.ecr.region.amazonaws.com\":\"ecr-login\"}}" > /kaniko/.docker/config.json
    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $AWS_REPOSITORY:$CI_COMMIT_TAG
  only:
    - tags

Ref : https://gitlab.com/s4l1h/kaniko-amazon-elastic-container-registry/blob/master/.gitlab-ci.yml

Upvotes: 3

Related Questions