Skip to content

Instantly share code, notes, and snippets.

@mhutter
Created June 26, 2023 12:15
Show Gist options
  • Save mhutter/f0067275c47eab2ce5ee4045049fca4d to your computer and use it in GitHub Desktop.
Save mhutter/f0067275c47eab2ce5ee4045049fca4d to your computer and use it in GitHub Desktop.
---
stages:
- build
build-image:
stage: build
image:
# Use Google's Kaniko builder
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
variables:
# Determine the image name based on the repository n
IMAGE: "${CI_REGISTRY_IMAGE}:${CI_BUILD_REF_SLUG}"
before_script:
# Ensure Kaniko's docker config folder exists
- mkdir -p /kaniko/.docker
# Write registry credentials
- printf '{"auths":{"%s":{"username":"%s","password":"%s"}}}\n' "${IMAGE/:master/:latest}" "$CI_REGISTRY_USER" "$CI_REGISTRY_PASSWORD" > /kaniko/.docker/config.json
script:
# Build & push image; use VSHN's Dockerhub mirror to pull
- /kaniko/executor --context "$CI_PROJECT_DIR" --destination "${IMAGE/:master/:latest}" --registry-mirror dockerhub.vshn.net
after_script:
# Clean up registry credentials
- rm -f /kaniko/.docker/config.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment