[feature] use buildx to produce multi arch image kubesphere#3683
Signed-off-by: lxm <lxm.xupt@gmail.com>
This commit is contained in:
13
hack/build-scripts/get-etcd.sh
Normal file
13
hack/build-scripts/get-etcd.sh
Normal 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
|
||||
17
hack/build-scripts/get-helm.sh
Normal file
17
hack/build-scripts/get-helm.sh
Normal 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
|
||||
14
hack/build-scripts/get-kubernetes.sh
Normal file
14
hack/build-scripts/get-kubernetes.sh
Normal 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
|
||||
15
hack/build-scripts/get-kustomize.sh
Normal file
15
hack/build-scripts/get-kustomize.sh
Normal 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
|
||||
51
hack/docker_build_multiarch.sh
Normal file
51
hack/docker_build_multiarch.sh
Normal 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
5
hack/init_env.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
ARCH=`uname -m`
|
||||
if [ "$ARCH" == "aarch64" ]; then
|
||||
export ETCD_UNSUPPORTED_ARCH=arm64
|
||||
fi
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user