-
Notifications
You must be signed in to change notification settings - Fork 35
/
build.sh
32 lines (24 loc) · 1.11 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
HELM_RELEASE=$1
set -euo pipefail
export DOCKER_REPO=lwolf/helm-kubectl-docker
export K8S_VERSION=$(curl -Ls -o /dev/null -w %{url_effective} https://github.com/kubernetes/kubernetes/releases/latest | cut -d '/' -f 8)
if [ "$HELM_RELEASE" == "helm3" ];then
export HELM_VERSION=$(curl -Ls https://github.com/helm/helm/releases | grep "/helm/helm/releases/tag/v3" | head -n 1 | sed 's/[^"]*"\([^"]*\)"[^"]*/\1/g' | cut -d '/' -f 6)
else
export HELM_VERSION=$(curl -Ls -o /dev/null -w %{url_effective} https://github.com/helm/helm/releases/latest | cut -d '/' -f 8)
fi
export RELEASE=${K8S_VERSION}-${HELM_VERSION}
docker manifest inspect ${DOCKER_REPO}:${RELEASE} > /dev/null && echo "Version ${RELEASE} is already exists" && exit 0
# Build image
docker build -t ${DOCKER_REPO}:${RELEASE} \
--build-arg K8S_VERSION=${K8S_VERSION} \
--build-arg HELM_VERSION=${HELM_VERSION} .
if [ "$HELM_RELEASE" != "helm3" ];then
docker tag ${DOCKER_REPO}:${RELEASE} ${DOCKER_REPO}:latest
fi
# Push image
docker push ${DOCKER_REPO}:${RELEASE}
if [ "$HELM_RELEASE" != "helm3" ];then
docker push ${DOCKER_REPO}:latest
fi