Skip to content
This repository has been archived by the owner on Jan 20, 2023. It is now read-only.

Added buildx support in cico scripts #108

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .cico/cico_build_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export SCRIPT_DIR

load_jenkins_vars
install_deps

check_buildx_support
build ./build/CI/Dockerfile

build_and_push ./build/metadata che-plugin-metadata-broker
build_and_push ./build/artifacts che-plugin-artifacts-broker

6 changes: 4 additions & 2 deletions .cico/cico_build_nightly.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ export SCRIPT_DIR
load_jenkins_vars
install_deps

build ./build/CI/Dockerfile

set_nightly_tag

check_buildx_support
build ./build/CI/Dockerfile
build_and_push ./build/metadata che-plugin-metadata-broker
build_and_push ./build/artifacts che-plugin-artifacts-broker

7 changes: 5 additions & 2 deletions .cico/cico_build_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ export SCRIPT_DIR
load_jenkins_vars
install_deps

build ./build/CI/Dockerfile

set_release_tag

check_buildx_support
build ./build/CI/Dockerfile
build_and_push ./build/metadata che-plugin-metadata-broker
build_and_push ./build/artifacts che-plugin-artifacts-broker


55 changes: 42 additions & 13 deletions .cico/cico_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ function load_jenkins_vars() {
fi
}

function check_version() {
local query=$1
local target=$2
echo "$target" "$query" | tr ' ' '\n' | sort -V | head -n1 2> /dev/null
}

function check_buildx_support() {
docker_version="$(docker --version | cut -d' ' -f3 | tr -cd '0-9.')"
if [[ $(check_version "$docker_version" "19.03") != 19.03 ]]; then
echo "CICO: Docker $docker_version greater than or equal to 19.03 is required."
exit 1
else
# Kernel
kernel_version="$(uname -r)"
if [[ $(check_version "$kernel_version" "4.8") != "4.8" ]]; then
echo "Kernel $kernel_version too old - need >= 4.8." \
" Install a newer kernel."
exit 1
else
echo "kernel $kernel_version has binfmt_misc fix-binary (F) support."
fi
fi
}

function install_deps() {
# We need to disable selinux for now, XXX
/usr/sbin/setenforce 0 || true
Expand All @@ -45,6 +69,15 @@ function install_deps() {
git

service docker start

#set buildx env
export DOCKER_BUILD_KIT=1
export DOCKER_CLI_EXPERIMENTAL=enabled

#Enable qemu and binfmt support
docker run --rm --privileged docker/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d
docker run --rm --privileged multiarch/qemu-user-static:4.2.0-7 --reset -p yes

echo 'CICO: Dependencies installed'
}

Expand All @@ -67,14 +100,11 @@ function set_git_commit_tag() {
export GIT_COMMIT_TAG
}

function tag_push() {
local TARGET=$1
docker tag "${IMAGE}" "$TARGET"
docker push "$TARGET"
}

function build() {
docker build -f $1 .
# Create a new builder instance using buildx
docker buildx create --use --name builder
docker buildx inspect --bootstrap
docker buildx build --platform linux/amd64,linux/s390x -f $1 .
}

function build_and_push() {
Expand Down Expand Up @@ -102,16 +132,15 @@ function build_and_push() {
echo "Could not login, missing credentials for pushing to the '${ORGANIZATION}' organization"
fi

# Let's build and push image to 'quay.io' using git commit hash as tag first
# Let's build and push image using buildx to 'quay.io' using git commit hash as tag first
set_git_commit_tag
docker build -t ${IMAGE} -f ${DOCKERFILE_FOLDER}/${DOCKERFILE} .

tag_push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${GIT_COMMIT_TAG}"

docker buildx build --platform linux/amd64,linux/s390x -t ${REGISTRY}/${ORGANIZATION}/${IMAGE}:${GIT_COMMIT_TAG} -f ${DOCKERFILE_FOLDER}/${DOCKERFILE} --push --progress plain --no-cache .
echo "CICO: '${GIT_COMMIT_TAG}' version of image pushed to '${REGISTRY}/${ORGANIZATION}/${IMAGE}' repo"

# If additional tag is set (e.g. "nightly"), let's tag the image accordingly and also push to 'quay.io'
# If additional tag is set (e.g. "nightly"), let's build the image accordingly and also push to 'quay.io'
if [ -n "${TAG}" ]; then
tag_push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}"
docker buildx build --platform linux/amd64,linux/s390x -t ${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG} -f ${DOCKERFILE_FOLDER}/${DOCKERFILE} --push --progress plain --no-cache .
echo "CICO: '${TAG}' version of image pushed to '${REGISTRY}/${ORGANIZATION}/${IMAGE}' repo"
fi
}
8 changes: 5 additions & 3 deletions build/CI/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
#

FROM golang:1.12
RUN wget -O - -q https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.15.0
RUN export ARCH="$(uname -m)" && export RACE="-race" && if [ ${ARCH} = "x86_64" ]; then export ARCH="amd64"; elif [ ${ARCH} = "s390x" ];then export RACE=""; fi \
&& wget https://github.com/golangci/golangci-lint/releases/download/v1.20.0/golangci-lint-1.20.0-linux-${ARCH}.tar.gz \
&& tar xf golangci-lint-1.20.0-linux-${ARCH}.tar.gz -C /usr/local/bin --strip-components 1
RUN adduser --disabled-password --gecos '' appuser
USER appuser
COPY . /go/src/github.com/eclipse/che-plugin-broker/
WORKDIR /go/src/github.com/eclipse/che-plugin-broker/
RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -s' -a -installsuffix cgo ./...
RUN golangci-lint run -v
RUN go test -v -race ./...
RUN golangci-lint run -v --timeout=5m
RUN go test -v $RACE ./...