Skip to content

Instantly share code, notes, and snippets.

@leepa
Last active March 8, 2024 20:15
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save leepa/260a7f8765a48db094f5cbf2fb45ea48 to your computer and use it in GitHub Desktop.
Save leepa/260a7f8765a48db094f5cbf2fb45ea48 to your computer and use it in GitHub Desktop.
A buildspec for CodeBuild... for cross platform building with buildx - enjoy :)
version: 0.2
phases:
install:
runtime-versions:
docker: 19
commands:
- docker version
- curl -JLO https://github.com/docker/buildx/releases/download/v0.4.2/buildx-v0.4.2.linux-amd64
- mkdir -p ~/.docker/cli-plugins
- mv buildx-v0.4.2.linux-amd64 ~/.docker/cli-plugins/docker-buildx
- chmod a+rx ~/.docker/cli-plugins/docker-buildx
- docker run --privileged --rm tonistiigi/binfmt --install all
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- docker buildx create --use --name crossx
- docker buildx build --push --platform=linux/amd64,linux/arm64 -t $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG .
@rchernobelskiy
Copy link

Thanks!

@kapilt
Copy link

kapilt commented Oct 31, 2021

❤️ 👏 💯

i assume that the old version here is due to the ancient docker version in codebuild.

@rkhan-cfs
Copy link

This helped me out quite a bit getting buildx to work in codebuild. This was my full command list:

- mkdir -p $HOME/.docker/cli-plugins
      - wget -O $HOME/.docker/cli-plugins/docker-buildx https://github.com/docker/buildx/releases/download/v0.10.3/buildx-v0.10.3.linux-arm64
      - chmod a+rx $HOME/.docker/cli-plugins/docker-buildx
      - docker run --privileged --rm tonistiigi/binfmt --install all
      - export DOCKER_BUILDKIT=1
      - export DOCKER_CLI_EXPERIMENTAL=enabled
      - docker buildx create --name mybuilder --use
      - docker buildx version

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