Created
June 28, 2021 15:44
-
-
Save behroozam/3cf1fd06ccb3ab18afa707b846976fef to your computer and use it in GitHub Desktop.
circleci docker buildx example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use the latest 2.1 version of CircleCI pipeline process engine. See: https://circleci.com/docs/2.0/configuration-reference | |
version: 2.1 | |
commands: | |
configure-dockerhub: | |
description: Configure Docker Hub access | |
steps: | |
- run: | |
name: Configure Docker Hub | |
command: | | |
[ -z "$ACCESS_TOKEN" ] && exit 0 | |
docker login --username youraccountname --password=$ACCESS_TOKEN | |
install-docker-buildx: | |
description: Install Docker Buildx | |
steps: | |
- run: | |
name: Install Docker Buildx | |
command: | | |
mkdir -vp ~/.docker/cli-plugins/ | |
curl --silent -L "https://github.com/docker/buildx/releases/download/v0.5.1/buildx-v0.5.1.linux-amd64" > ~/.docker/cli-plugins/docker-buildx | |
chmod a+x ~/.docker/cli-plugins/docker-buildx | |
docker buildx version | |
sudo apt-get update && sudo apt-get install -y binfmt-support qemu-user-static | |
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes | |
docker run --privileged --rm tonistiigi/binfmt --install arm64 | |
docker context create buildcontext | |
docker buildx create buildcontext --use | |
jobs: | |
build-multiarch-container: | |
parameters: | |
resource_size: | |
description: Resource agent size | |
type: string | |
default: medium | |
repo: | |
description: repository without tag, e.g. yourproject/foo | |
type: string | |
directory: | |
description: Directory path without trailing slash relative to repo root | |
type: string | |
docker: | |
- image: cimg/base:stable | |
resource_class: << parameters.resource_size >> | |
steps: | |
- checkout | |
- setup_remote_docker: | |
version: 19.03.13 | |
docker_layer_caching: true | |
- install-docker-buildx | |
- configure-dockerhub | |
- run: | |
name: Build and push container | |
working_directory: << parameters.directory >> | |
no_output_timeout: 2h | |
command: | | |
export TAG=<< parameters.repo >>:`echo $CIRCLE_SHA1 | cut -c -7` | |
docker buildx inspect --bootstrap | |
docker buildx build --progress plain --push -t $TAG --platform linux/amd64,linux/arm64 . | |
workflows: | |
version: 2 | |
build-images: | |
jobs: | |
- build-multiarch-container: | |
name: build-python-base-arm64 | |
context: | |
- dockerhub | |
- models | |
repo: your_dockerhub/your_image_name | |
resource_size: xlarge #could be also medium depend on your project size | |
directory: private/yourimage # the directory path that contain your Dockerfile | |
filters: | |
branches: | |
only: | |
- master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment