[feature] use buildx to produce multi arch image kubesphere#3683

Signed-off-by: lxm <lxm.xupt@gmail.com>
This commit is contained in:
lxm
2021-04-10 00:06:07 +08:00
parent 6a58572167
commit af536c0c96
11 changed files with 242 additions and 2 deletions

View File

@@ -0,0 +1,13 @@
#!/bin/bash
ARCH=`uname -m`
if [ "$ARCH" == "x86_64" ]; then
echo "x86_64"
wget https://storage.googleapis.com/etcd/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-amd64.tar.gz
tar xvf etcd-${ETCD_VERSION}-linux-amd64.tar.gz && \
mv etcd-${ETCD_VERSION}-linux-amd64/etcd /usr/local/bin/etcd
elif [ "$ARCH" == "aarch64" ]; then
echo "arm arch"
wget https://storage.googleapis.com/etcd/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-arm64.tar.gz
tar xvf etcd-${ETCD_VERSION}-linux-arm64.tar.gz && \
mv etcd-${ETCD_VERSION}-linux-arm64/etcd /usr/local/bin/etcd
fi

View File

@@ -0,0 +1,17 @@
#!/bin/bash
ARCH=`uname -m`
if [ "$ARCH" == "x86_64" ]; then
echo "x86_64"
wget https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz && \
tar xvf helm-${HELM_VERSION}-linux-amd64.tar.gz && \
rm helm-${HELM_VERSION}-linux-amd64.tar.gz && \
mv linux-amd64/helm /usr/bin/ && \
rm -rf linux-amd64
elif [ "$ARCH" == "aarch64" ]; then
echo "arm arch"
wget https://get.helm.sh/helm-${HELM_VERSION}-linux-arm64.tar.gz && \
tar xvf helm-${HELM_VERSION}-linux-arm64.tar.gz && \
rm helm-${HELM_VERSION}-linux-arm64.tar.gz && \
mv linux-arm64/helm /usr/bin/ && \
rm -rf linux-arm64
fi

View File

@@ -0,0 +1,14 @@
#!/bin/bash
ARCH=`uname -m`
if [ "$ARCH" == "x86_64" ]; then
echo "x86_64"
wget https://dl.k8s.io/${KUBE_VERSION}/kubernetes-server-linux-amd64.tar.gz && \
tar xvf kubernetes-server-linux-amd64.tar.gz &&
mv kubernetes /usr/local/
elif [ "$ARCH" == "aarch64" ]; then
echo "arm arch"
wget https://dl.k8s.io/${KUBE_VERSION}/kubernetes-server-linux-arm64.tar.gz && \
tar xvf kubernetes-server-linux-arm64.tar.gz &&
mv kubernetes /usr/local/
fi

View File

@@ -0,0 +1,15 @@
#!/bin/bash
ARCH=`uname -m`
if [ "$ARCH" == "x86_64" ]; then
echo "x86_64"
wget https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2F${KUSTOMIZE_VERSION}/kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz && \
tar xvf kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz && \
rm kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz && \
mv kustomize /usr/bin
elif [ "$ARCH" == "aarch64" ]; then
echo "arm arch"
wget https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2F${KUSTOMIZE_VERSION}/kustomize_${KUSTOMIZE_VERSION}_linux_arm64.tar.gz && \
tar xvf kustomize_${KUSTOMIZE_VERSION}_linux_arm64.tar.gz && \
rm kustomize_${KUSTOMIZE_VERSION}_linux_arm64.tar.gz && \
mv kustomize /usr/bin
fi

View File

@@ -0,0 +1,51 @@
#!/usr/bin/env bash
set -ex
set -o pipefail
BUILDPLATFORM="linux/amd64,linux/arm64"
tag_for_branch() {
local tag=$1
if [[ "${tag}" == "" ]]; then
tag=$(git branch --show-current)
tag=${tag/\//-}
fi
if [[ "${tag}" == "master" ]]; then
tag="latest"
fi
echo ${tag}
}
get_repo() {
local repo=${REPO} # read from env
repo=${repo:-kubespheredev}
if [[ "$1" != "" ]]; then
repo="$1"
fi
# set the default value if there's no user defined
if [[ "${repo}" == "" ]]; then
repo="kubespheredev"
fi
echo "$repo"
}
# push to kubespheredev with default latest tag
TAG=$(tag_for_branch "$1")
REPO=$(get_repo "$2")
# Push image to dockerhub, need to support multiple push
cat ~/.docker/config.json | grep index.docker.io
if [[ $? != 0 ]]; then
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
fi
docker buildx build --platform=${BUILDPLATFORM} \
-f build/Dockerfile \
-t $REPO/ks-apiserver-multiarch:$TAG . \
--target=ks-apiserver --push
docker buildx build --platform=${BUILDPLATFORM} \
-f build/Dockerfile \
-t $REPO/ks-controller-manager-multiarch:$TAG . \
--target=ks-controller-manager --push

5
hack/init_env.sh Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
ARCH=`uname -m`
if [ "$ARCH" == "aarch64" ]; then
export ETCD_UNSUPPORTED_ARCH=arm64
fi

View File

@@ -35,8 +35,10 @@ HW=$(uname -m)
case $HW in
x86_64)
ARCH=amd64 ;;
aarch64)
ARCH=arm64 ;;
*)
echo "Only x86_64 machines are supported !"
echo "Only x86_64/arm64 machines are supported !"
exit 1
;;
esac