/
gcloud-deploy.sh
executable file
·56 lines (44 loc) · 1.7 KB
/
gcloud-deploy.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env bash
set -o pipefail
set -o errexit
set -o nounset
# set -o xtrace
# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__kube="${__dir}"
__companion="$(dirname "$(dirname "${__kube}")")"
# Install kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.18.1/bin/linux/amd64/kubectl
chmod +x ./kubectl
mkdir -p ${HOME}/.local/bin/
export PATH="${HOME}/.local/bin/:$PATH"
mv ./kubectl ${HOME}/.local/bin/
# Store the new image in docker hub
docker build -t transloadit/companion:latest -t transloadit/companion:$TRAVIS_COMMIT .;
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD";
# Push the commit tagged docker image.
docker push transloadit/companion:$TRAVIS_COMMIT;
# If this build includes a git tag, tag the image with the git version tag and push the version.
if [[ ! -z "${TRAVIS_TAG}" ]]; then
docker tag transloadit/companion:$TRAVIS_COMMIT transloadit/companion:$TRAVIS_TAG;
docker push transloadit/companion:$TRAVIS_TAG;
fi
# Lastly, update the pointer to latest.
docker push transloadit/companion:latest;
echo "Create directory..."
mkdir ${HOME}/.kube
echo "Writing KUBECONFIG to file..."
echo $KUBECONFIGVAR | python -m base64 -d > ${HOME}/.kube/config
echo "KUBECONFIG file written"
sleep 10s # This cost me some precious debugging time.
kubectl set image statefulset companion --namespace=companion companion=docker.io/transloadit/companion:$TRAVIS_COMMIT
sleep 10s
kubectl get pods --namespace=companion
kubectl get service --namespace=companion
kubectl get deployment --namespace=companion
function cleanup {
printf "Cleaning up...\n"
rm -vf ${HOME}/.kube/config
printf "Cleaning done."
}
trap cleanup EXIT