Skip to content

Instantly share code, notes, and snippets.

@carlallen
Created May 28, 2020 19:58
Show Gist options
  • Save carlallen/781a3e40247cff021a7e77de5fb81a47 to your computer and use it in GitHub Desktop.
Save carlallen/781a3e40247cff021a7e77de5fb81a47 to your computer and use it in GitHub Desktop.
variables:
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://docker:2375/
DOCKER_BUILDKIT: 1
build:
stage: build
services:
- name: docker:dind
command: ["dockerd", "--host=tcp://0.0.0.0:2375"]
alias: 'docker'
image: carlallen/docker:buildx
before_script:
- docker buildx create --driver=docker-container --name=buildkit-builder --use
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
script: |
docker buildx build \
--cache-from type=registry,ref=$CI_REGISTRY_IMAGE:cache \
--cache-to type=registry,ref=$CI_REGISTRY_IMAGE:cache \
--push \
--tag $CI_REGISTRY_IMAGE:latest \
.
only:
- master
@svetozar02
Copy link

@carlallen
Copy link
Author

I don't do multi-arch builds, I use other expirimental features in buildx

@svetozar02
Copy link

svetozar02 commented May 20, 2021 via email

@carlallen
Copy link
Author

Oh, I feel like making new cache images is weird since something changed, but I haven't done that in a while. I do know that cache images can not be deleted in the registry unless you push a real image over the same tag and then delete it.

@svetozar02
Copy link

Interesting... Thanks for the info!

@Tacioandrade
Copy link

Tacioandrade commented Dec 17, 2021

Thank you very much! For a long time I was puzzled about how to generate an image for ARM64 and AMD64, I ended up getting it this way:

build:
  stage: build
  services:
    - name: docker:dind
      command: ["dockerd", "--host=tcp://0.0.0.0:2375"]
      alias: 'docker'
  image: carlallen/docker:buildx
  before_script:
    - docker buildx create --driver=docker-container --name=buildkit-builder --use
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
  script: |
    docker buildx build \
          --cache-from type=registry,ref=$CI_REGISTRY_IMAGE:cache \
          --cache-to type=registry,ref=$CI_REGISTRY_IMAGE:cache \
          --platform linux/arm64,linux/amd64 \
          --push \
          --tag $CI_REGISTRY_IMAGE:latest \
          .

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