Skip to content

Instantly share code, notes, and snippets.

@frafra
Created November 6, 2020 15:46
Show Gist options
  • Save frafra/12a27ddbcaba5fea951e9af0d0037768 to your computer and use it in GitHub Desktop.
Save frafra/12a27ddbcaba5fea951e9af0d0037768 to your computer and use it in GitHub Desktop.
Build containers with GitLab CI without root nor daemons by using buildkit
build-container:
stage: build
image:
name: moby/buildkit:rootless
entrypoint: [ "sh", "-c" ]
variables:
BUILDKITD_FLAGS: --oci-worker-no-process-sandbox
before_script:
- |
mkdir ~/.docker
auth=$(echo -n "$CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD" | base64)
echo "{\"auths\": {\"$CI_REGISTRY\": {\"auth\": \"$auth\"}}}" > ~/.docker/config.json
script:
- |
buildctl-daemonless.sh build \
--frontend=dockerfile.v0 \
--local context=. \
--local dockerfile=. \
--import-cache type=registry,ref=$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG \
--export-cache type=inline \
--output type=image,name=$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG,push=true
@sherbang
Copy link

sherbang commented Feb 1, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment