Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Commit

Permalink
Merge branch 'feature/standalone-pipeline' into 'master'
Browse files Browse the repository at this point in the history
standalone pipeline

See merge request ix.ai/docker-buildx-qemu!4
  • Loading branch information
tlex committed Sep 13, 2020
2 parents c1eff48 + dda7abe commit 19c69cf
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 16 deletions.
135 changes: 131 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,134 @@
variables:
# Job and build settings
CI_BUILD_IMAGE: "debian:stable-slim"
CI_BUILDX_ARCHS: 'linux/amd64,linux/arm64'
# Docker and BuildKit variables
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_CERT_PATH: "/certs/client"
DOCKER_TLS: 'true'
DOCKER_HOST: tcp://docker:2376/
BUILDKIT_INLINE_CACHE: '1'
# Dockerhub variables
DOCKERHUB_REPO_NAME: docker-buildx-qemu
ENABLE_ARM64: 'true'
# Debian variables
DEBIAN_FRONTEND: 'noninteractive'
TERM: 'linux'

include:
- project: 'ix.ai/ci-templates'
file: '/common.yml'
stages:
- build
- release

services:
- docker:dind

.init:
interruptible: true
image: ${CI_BUILD_IMAGE}
before_script:
- set -xeu
- apt-get update
- |
apt-get install -y --no-install-recommends \
apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common
- curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
- add-apt-repository "deb https://download.docker.com/linux/debian $(lsb_release -cs) stable"
- apt-get update
- |
apt-get install -y --no-install-recommends \
docker-ce-cli \
binfmt-support \
qemu-user-static \
git \
jq
- mkdir -p ~/.docker/cli-plugins
- |
curl -s https://api.github.com/repos/docker/buildx/releases/latest \
| grep "browser_download_url.*linux-$(dpkg --print-architecture)" | cut -d : -f 2,3 | tr -d \" \
| xargs curl -sL -o ~/.docker/cli-plugins/docker-buildx
- chmod a+x ~/.docker/cli-plugins/docker-buildx;
- export BUILDX_NAME="buildx-$(tr -cd '[:alnum:]' < /dev/urandom | fold -w6 | head -n1)"
- docker version && docker buildx version
- docker context create "${BUILDX_NAME}"
- update-binfmts --enable # Important: Ensures execution of other binary formats is enabled in the kernel
- docker buildx create --driver docker-container --name "${BUILDX_NAME}" --use "${BUILDX_NAME}"
- docker buildx inspect --bootstrap
- echo "$CI_REGISTRY_PASSWORD" | docker login -u "${CI_REGISTRY_USER}" --password-stdin "${CI_REGISTRY}"
- |
if [ -n "${DOCKERHUB_USERNAME:-}" ] \
&& [ -n "${DOCKERHUB_PASSWORD:-}" ] \
&& [ -n "${DOCKERHUB_REPO_NAME:-}" ] \
; then \
echo "${DOCKERHUB_PASSWORD}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin; \
fi
build:dev:
extends:
- .init
stage: build
except:
refs:
- tags
script:
- find . -name build.sh -maxdepth 1 -exec sh {} ';'
- export TAG="dev-master"
# Use the tag `dev-master` if there's a commit to master, else use `dev-branch` for feature branches
- if [ ! "${CI_COMMIT_REF_NAME}" == "master" ]; then export TAG="dev-branch"; fi
- export IMAGE="${CI_REGISTRY_IMAGE}:${TAG}"
- export DESTINATION="--tag=${IMAGE}"
- |
if [[ ( -n "${DOCKERHUB_REPO_NAME:-}" ) && ( -n "${DOCKERHUB_PASSWORD:-}" ) ]]; then \
export DESTINATION="${DESTINATION} --tag=${DOCKERHUB_REPO_PREFIX}/${DOCKERHUB_REPO_NAME}:${TAG}"; \
fi
- |
docker buildx build \
--platform=$CI_BUILDX_ARCHS \
--progress=plain \
--cache-from=${CI_REGISTRY_IMAGE}:cache \
--cache-to=${CI_REGISTRY_IMAGE}:cache \
--pull ${DESTINATION} \
--push .
build:release:
extends:
- .init
stage: release
only:
refs:
- tags
script:
- find . -name build.sh -maxdepth 1 -exec sh {} \;
# Use the tag `latest` and the actual git tag for all the tags
- export IMAGE="${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}"
- export DESTINATION="--tag=${IMAGE}"
- export DESTINATION="${DESTINATION} --tag=${CI_REGISTRY_IMAGE}:latest"
- |
if [[ ( -n "${DOCKERHUB_REPO_NAME:-}" ) && ( -n "${DOCKERHUB_PASSWORD:-}" ) ]]; then \
export DESTINATION="${DESTINATION} --tag=${DOCKERHUB_REPO_PREFIX}/${DOCKERHUB_REPO_NAME}:${CI_COMMIT_REF_NAME}"; \
export DESTINATION="${DESTINATION} --tag=${DOCKERHUB_REPO_PREFIX}/${DOCKERHUB_REPO_NAME}:latest"; \
fi
- |
docker buildx build \
--platform=$CI_BUILDX_ARCHS \
--progress=plain \
--cache-from=${CI_REGISTRY_IMAGE}:cache \
--cache-to=${CI_REGISTRY_IMAGE}:cache \
--pull ${DESTINATION} \
--push .
dockerhub:readme:
stage: release
variables:
README_PATH: ${CI_PROJECT_DIR}/README.md
rules:
- if: '$CI_COMMIT_REF_NAME == "master" && $DOCKERHUB_REPO_NAME =~ /.+/ && $DOCKERHUB_PASSWORD =~ /.+/'
when: on_success
image:
name: sheogorath/readme-to-dockerhub:latest
entrypoint: ['']
script:
- node /app/index.js
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ RUN set -eux; \
echo Running on $ARCH; \
curl -s https://api.github.com/repos/docker/buildx/releases/latest \
| grep "browser_download_url.*linux-$ARCH" | cut -d : -f 2,3 | tr -d \" \
| xargs curl -L -o ~/.docker/cli-plugins/docker-buildx \
| xargs curl -sL -o ~/.docker/cli-plugins/docker-buildx \
; \
chmod a+x ~/.docker/cli-plugins/docker-buildx; \
\
Expand Down
33 changes: 22 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@
[![Pipeline Status](https://gitlab.com/ix.ai/docker-buildx-qemu/badges/master/pipeline.svg)](https://gitlab.com/ix.ai/docker-buildx-qemu/)
[![Docker Stars](https://img.shields.io/docker/stars/ixdotai/docker-buildx-qemu.svg)](https://hub.docker.com/r/ixdotai/docker-buildx-qemu/)
[![Docker Pulls](https://img.shields.io/docker/pulls/ixdotai/docker-buildx-qemu.svg)](https://hub.docker.com/r/ixdotai/docker-buildx-qemu/)
[![Docker Image Version (latest)](https://img.shields.io/docker/v/ixdotai/docker-buildx-qemu/latest)](https://hub.docker.com/r/ixdotai/docker-buildx-qemu/)
[![Docker Image Size (latest)](https://img.shields.io/docker/image-size/ixdotai/docker-buildx-qemu/latest)](https://hub.docker.com/r/ixdotai/docker-buildx-qemu/)
[![Gitlab Project](https://img.shields.io/badge/GitLab-Project-554488.svg)](https://gitlab.com/ix.ai/docker-buildx-qemu/)

This Debian-based image allows you to easily build cross-platform images.
This Debian-slim-based image allows you to easily build cross-platform images.
It's been tested with GitLab CI on gitlab.com, but it should work anywhere that docker-in-docker already works, and with a `binfmt_misc` enabled kernel.

The `ixdotai/docker-buildx-qemu` image supports the following architectures:
* `amd64`
* `arm64`

The following additional tools are installed, to be used in your pipelines:
* `curl`
* `git`
* `jq`

## Example Usage

This GitLab example should give you an idea of how to use the image.
Expand All @@ -22,27 +33,27 @@ RUN echo "Hello, my CPU architecture is $(uname -m)"
.gitlab-ci.yml
```yaml
variables:
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_CERT_PATH: "/certs/client"
DOCKER_TLS: 'true'
DOCKER_HOST: tcp://docker:2376/
BUILDKIT_INLINE_CACHE: '1'
DOCKER_DRIVER: overlay2
CI_BUILD_ARCHS: "linux/arm/v7,linux/arm64,linux/amd64"
CI_BUILD_IMAGE: "ixdotai/docker-buildx-qemu:latest"

build:
image: $CI_BUILD_IMAGE
stage: build
services:
- name: docker:dind
entrypoint: ["env", "-u", "DOCKER_HOST"]
command: ["dockerd-entrypoint.sh"]
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
# See https://github.com/docker-library/docker/pull/166
DOCKER_TLS_CERTDIR: ""
- docker:dind
retry: 2
before_script:
- echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY
# Use docker-container driver to allow useful features (push/multi-platform)
- update-binfmts --enable # Important: Ensures execution of other binary formats is enabled in the kernel
- docker buildx create --driver docker-container --use
# Use docker-container driver to allow useful features (push/multi-platform)
- docker context create MyContext
- docker buildx create --driver docker-container --name MyContext --use MyContext
- docker buildx inspect --bootstrap
script:
- docker buildx ls
Expand Down

0 comments on commit 19c69cf

Please sign in to comment.