zl程序教程

您现在的位置是:首页 >  其他

当前栏目

helm安装kubevela完整Makefile脚本内容

安装 脚本 内容 完整 Makefile Helm
2023-09-14 09:01:48 时间

Makefile

PROJECT ?= kubevela
VERSION ?= v1.4.8
CHART ?= 1.4.8

GIT_ACCESS_TOKEN=BLjk5y9ZwwQho_ETLcCj

IMAGE_PULLER = $(shell pwd)/bin/puller.sh
IMAGE_EXPORTER = $(shell pwd)/bin/exporter.sh

publish: 
	tar -czvf - -C ./releases ${PROJECT}-${VERSION} | ssh root@xxx.xxx "mkdir -p /zxl/kube-installer-plugins/${PROJECT} && cat > /zxl/kube-installer-plugins/${PROJECT}/${PROJECT}-$(shell uname -m)-${VERSION}.tar.gz"

released: clean binary chart image patch
	echo ./releases/${PROJECT}-${VERSION}

binary:
	mkdir -p ./releases/${PROJECT}-${VERSION}/binaries
	curl -L "https://github.com/kubevela/kubevela/releases/download/v1.4.8/kubectl-vela-v1.4.8-linux-`case $$(uname -m) in x86_64|amd64) echo amd64;;armv8*|aarch64*|arm64) echo arm64;;armv*) echo armv7;;esac`.tar.gz" | tar zxf - -C ./releases/${PROJECT}-${VERSION}/binaries

define override_content
image:
  pullPolicy: IfNotPresent
persistence:
  storageClass: "rook-ceph-block"
endef
export override_content

chart:
	mkdir -p ./releases/${PROJECT}-${VERSION}/charts
	helm repo add kubevela https://charts.kubevela.net/core --force-update
	helm repo update kubevela
	helm pull kubevela/vela-core --version ${CHART} --destination ./releases/${PROJECT}-${VERSION}/charts --untar
	rm -fr ./releases/${PROJECT}-${VERSION}/charts/vela-core/templates/tests
	echo "$$override_content" > ./releases/${PROJECT}-${VERSION}/charts/override.yaml

define patch_content
#---------------------------------------------------------------
#   Author: zxl
#   E-mail: xueliang@gmail.com
#   Create: $(shell date "+%Y-%m-%d %H:%M:%S")
#   Describe: Todo
#---------------------------------------------------------------
set -e
helm upgrade --install --create-namespace -n vela-system kubevela ./charts/vela-core -f ./charts/override.yaml
endef
export patch_content

patch:
	echo "$$patch_content" > ./releases/${PROJECT}-${VERSION}/patch.sh

image: image-exporter
	@helm template ./releases/${PROJECT}-${VERSION}/charts/vela-core/  | grep 'image:'| grep 'oamdev' | sed 's/^.*image: //g' | sed "s/^\([\"']\)\(.*\)\1\$$/\2/g" | uniq > ./releases/${PROJECT}-${VERSION}/images.txt
	@mkdir -p ./releases/${PROJECT}-${VERSION}/images
	@$(IMAGE_EXPORTER) -o ./releases/${PROJECT}-${VERSION}/images/${PROJECT}-${VERSION}.tar -f ./releases/${PROJECT}-${VERSION}/images.txt
	@gzip ./releases/${PROJECT}-${VERSION}/images/${PROJECT}-${VERSION}.tar

	# @grep 'repository: ' ./releases/${PROJECT}-${VERSION}/charts/vela-core/values.yaml | sed 's/^.*repository: //g' | sed "s/^\([\"']\)\(.*\)\1\$$/\2/g" | uniq > ./releases/${PROJECT}-${VERSION}/images.txt
	# @mkdir -p ./releases/${PROJECT}-${VERSION}/images
	# @$(IMAGE_EXPORTER) -o ./releases/${PROJECT}-${VERSION}/images/${PROJECT}-${VERSION}.tar -f ./releases/${PROJECT}-${VERSION}/images.txt
	# @gzip ./releases/${PROJECT}-${VERSION}/images/${PROJECT}-${VERSION}.tar

image-exporter:
	@mkdir -p ./bin 
	@curl --header "PRIVATE-TOKEN: ${GIT_ACCESS_TOKEN}" "https://git.xxx.com/api/v4/projects/662/repository/files/bin%2Fpuller.sh?ref=master" | sed -r 's/^.*"content":"([^"]*)".*$$/\1/' | base64 -d > $(IMAGE_PULLER)
	@chmod +x $(IMAGE_PULLER)
	@curl --header "PRIVATE-TOKEN: ${GIT_ACCESS_TOKEN}" "https://git.xxx.com/api/v4/projects/662/repository/files/bin%2Fexporter.sh?ref=master" | sed -r 's/^.*"content":"([^"]*)".*$$/\1/' | base64 -d > $(IMAGE_EXPORTER)
	@chmod +x $(IMAGE_EXPORTER)


clean:
	rm -rvf ./releases/${PROJECT}-${VERSION}

Makefile脚本中使用到的两个shell脚本完整内容如下--

exporter.sh

导出镜像到文件,如果镜像不存在则首先拉取镜像

set -e

POSITIONAL=()

while [[ $# -gt 0 ]]
do
    key="$1"
    case $key in
        -f|--file)
            file="$2"
            shift
            shift
            ;;
        -i|--images)
            images="$2"
            shift
            shift
            ;;
        -o|--output)
            output="$2"
            shift
            shift
            ;;
        -u|--user)
            user="$2"
            shift
            shift
            ;;
        -h|--help)
            echo "Usage: ./exporter.sh [flags [options]]..."
            echo
            echo "Available Flags:"
            echo "  -f, --file: image list file"
            echo "  -i, --images: image list string, separated by comma"
            echo "  -o, --output: output file name"
            echo "  -u, --user: user[:password] Registry user and password, only valid for ctr"
            echo "  -h, --help: print this help message"
            echo
            exit 0
            ;;
        *)
            POSITIONAL+=("$1")
            shift
            ;;
    esac
done

set -- "${POSITIONAL[@]}"

export IFS=$'\n\t, '

if [[ "${user}" != "" ]]; then
    # pull with user
    if [[ "${file}" != "" ]] && [ -f "${file}" ]; then
        files=$(cat "$file")
        for image in $files; do
            "$(dirname "$0")"/puller.sh -i "$image" -u "${user}"
        done
    fi
    if [[ "${images}" != "" ]]; then
        for image in $images; do
            "$(dirname "$0")"/puller.sh -i "$image" -u "${user}"
        done
    fi
else
    # pull without user
    if [[ "${file}" != "" ]] && [ -f "${file}" ]; then
        files=$(cat "$file")
        for image in $files; do
            "$(dirname "$0")"/puller.sh -i "$image"
        done
    fi
    if [[ "${images}" != "" ]]; then
        for image in $images; do
            "$(dirname "$0")"/puller.sh -i "$image"
        done
    fi
fi

if which docker &> /dev/null; then
    echo "export images via docker"
    echo docker save -o "$output" $(echo "$files" "$images" | sed 's/@[^,]*//g' | sed 's/,/ /g') | bash
elif which ctr &> /dev/null; then
    echo "export images via ctr"
    echo ctr images export "$output" $(echo "$files" "$images" | sed 's/@[^,]*//g' | sed 's/,/ /g') | bash
fi

puller.sh

拉取镜像,会自动判断是否走代理

set -e

POSITIONAL=()

while [[ $# -gt 0 ]]
do
    key="$1"
    case $key in
        -i|--image)
            image="$2"
            shift
            shift
            ;;
        -u|--user)
            user="$2"
            shift
            shift
            ;;
        -h|--help)
            echo "Usage: ./puller.sh [flags [options]]..."
            echo
            echo "Available Flags:"
            echo "  -i, --image: fetch and prepare an image for use in containerd"
            echo "  -u, --user: user[:password] Registry user and password"
            echo "  -h, --help: print this help message"
            echo
            exit 0
            ;;
        *)
            POSITIONAL+=("$1")
            shift
            ;;
    esac
done

set -- "${POSITIONAL[@]}"

if [[ "$image" == "" ]]; then
    echo "image is required"
    echo "Use \"-h|--help\" for more information about this command."
    exit 1
fi

function image() {
    for image in "$@"
    do
        if echo "$image" | grep -q '/'; then
            if echo "${image%%/*}" | grep -q '\.'; then
                echo "$image"
            else
                echo "docker.io/$image"
            fi
        else
            echo "docker.io/library/$image"
        fi
    done
}

IMAGE=$(image "$image" | sed 's/"//g')

if which docker &> /dev/null; then
    echo "pull image via docker"
    if [[ "$IMAGE" =~ ^docker\.io\/.* ]] || [[ "$IMAGE" =~ ^harbor\.dameng\.io\/.* ]]; then
        docker pull "$IMAGE"
    else
        repository=$(echo $IMAGE | sed 's/[^\/]*\/\(.*\)/\1/g')
        docker pull "$repository"
        docker tag "$repository" "$IMAGE"
        docker rmi "$repository"
    fi
    exit 0
fi

if which ctr &> /dev/null; then
    echo "pull image via ctr"
    if [ -v user ]; then
        ctr image pull --hosts-dir /etc/containerd/certs.d -u "$user" "$IMAGE" --skip-verify
    else
        ctr image pull --hosts-dir /etc/containerd/certs.d "$IMAGE" --skip-verify
    fi
    exit 0
fi