feat(build): support for multi arch container image (#233)

* support for multi arch container image via github actions
* suffix amd64 arch tag in zfs driver image

Signed-off-by: prateekpandey14 <prateek.pandey@mayadata.io>
This commit is contained in:
Prateek Pandey 2020-11-11 14:16:33 +05:30 committed by GitHub
parent 64bc7cb1c9
commit e52d6c7067
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 389 additions and 29 deletions

View file

@ -33,21 +33,21 @@ else
fi
# Set BUILDMETA based on travis tag
if [[ -n "$TRAVIS_TAG" ]] && [[ $TRAVIS_TAG != *"RC"* ]]; then
if [[ -n "$RELEASE_TAG" ]] && [[ $RELEASE_TAG != *"RC"* ]]; then
echo "released" > BUILDMETA
fi
CURRENT_BRANCH=""
if [ -z ${TRAVIS_BRANCH} ];
if [ -z ${BRANCH} ];
then
CURRENT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2)
else
CURRENT_BRANCH=${TRAVIS_BRANCH}
CURRENT_BRANCH=${BRANCH}
fi
# Get the version details
if [ -n "$TRAVIS_TAG" ]; then
VERSION="$TRAVIS_TAG"
if [ -n "$RELEASE_TAG" ]; then
VERSION="$RELEASE_TAG"
else
BUILDDATE=`date +%m-%d-%Y`
SHORT_COMMIT="$(git rev-parse --short HEAD)"
@ -72,15 +72,6 @@ elif [ "$UNAME" = "Linux" ] ; then
XC_OS="linux"
fi
if [ "${ARCH}" = "i686" ] ; then
XC_ARCH='386'
elif [ "${ARCH}" = "x86_64" ] ; then
XC_ARCH='amd64'
else
echo "Unusable architecture: ${ARCH}"
exit 1
fi
if [ -z "${PNAME}" ];
then
@ -146,19 +137,6 @@ for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f); do
cp ${F} ${MAIN_GOPATH}/bin/
done
if [[ "x${DEV}" == "x" ]]; then
# Zip and copy to the dist dir
echo "==> Packaging..."
for PLATFORM in $(find ./bin/${PNAME} -mindepth 1 -maxdepth 1 -type d); do
OSARCH=$(basename ${PLATFORM})
echo "--> ${OSARCH}"
pushd "$PLATFORM" >/dev/null 2>&1
zip ../${PNAME}-${OSARCH}.zip ./*
popd >/dev/null 2>&1
done
fi
# Done!
echo
echo "==> Results:"

View file

@ -22,7 +22,33 @@ then
exit 1
fi
function pushBuildx() {
BUILD_TAG="latest"
TARGET_IMG=${DIMAGE}
# TODO Currently ci builds with commit tag will not be generated,
# since buildx does not support multiple repo
# if not a release build set the tag and ci image
if [ -z "${RELEASE_TAG}" ]; then
return
# BUILD_ID=$(git describe --tags --always)
# BUILD_TAG="${BRANCH}-${BUILD_ID}"
# TARGET_IMG="${DIMAGE}-ci"
fi
echo "Tagging and pushing ${DIMAGE}:${TAG} as ${TARGET_IMG}:${BUILD_TAG}"
docker buildx imagetools create "${DIMAGE}:${TAG}" -t "${TARGET_IMG}:${BUILD_TAG}"
}
# if the push is for a buildx build
if [[ ${BUILDX} ]]; then
pushBuildx
exit 0
fi
IMAGEID=$( sudo docker images -q ${DIMAGE}:ci )
DIMAGE="${DIMAGE}-${XC_ARCH}"
echo "${DIMAGE}:ci -> $IMAGEID"
if [ -z ${IMAGEID} ];
then

View file

@ -18,7 +18,6 @@ RUN apt-get update; exit 0
RUN apt-get -y install rsyslog libssl-dev xfsprogs ca-certificates
RUN apt-get -y install btrfs-progs netcat
ARG ARCH
ARG DBUILD_DATE
ARG DBUILD_REPO_URL
ARG DBUILD_SITE_URL

View file

@ -0,0 +1,61 @@
# Copyright 2019-2020 The OpenEBS Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM golang:1.14.7 as build
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT=""
ENV GO111MODULE=on \
GOOS=${TARGETOS} \
GOARCH=${TARGETARCH} \
GOARM=${TARGETVARIANT} \
DEBIAN_FRONTEND=noninteractive \
PATH="/root/go/bin:${PATH}"
WORKDIR /go/src/github.com/openebs/zfs-localpv/
RUN apt-get update && apt-get install -y make git
COPY go.mod go.sum ./
# Get dependancies - will also be cached if we won't change mod/sum
RUN go mod download
COPY . .
RUN make buildx.csi-driver
FROM ubuntu:19.10
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
RUN apt-get update; exit 0
RUN apt-get -y install rsyslog libssl-dev xfsprogs ca-certificates
RUN apt-get -y install btrfs-progs netcat
ARG DBUILD_DATE
ARG DBUILD_REPO_URL
ARG DBUILD_SITE_URL
COPY --from=build /go/src/github.com/openebs/zfs-localpv/bin/zfs-driver/zfs-driver /usr/local/bin/zfs-driver
LABEL org.label-schema.name="zfs-driver"
LABEL org.label-schema.description="OpenEBS ZFS LocalPV Driver"
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.build-date=$DBUILD_DATE
LABEL org.label-schema.vcs-url=$DBUILD_REPO_URL
LABEL org.label-schema.url=$DBUILD_SITE_URL
ENTRYPOINT ["/usr/local/bin/zfs-driver"]
EXPOSE 7676 7777