-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy
executable file
·47 lines (35 loc) · 1.63 KB
/
deploy
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
#!/usr/bin/env bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
export DEPLOY_ROOT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
source "$DEPLOY_ROOT_DIR/src/common.bash"
ensure_environment_url
ensure_deploy_variables
create_kubeconfig
track="${1-stable}"
name="${CI_PROJECT_NAME,,}"
if [[ "$track" != "stable" ]]; then
name="$name-$track"
fi
replicas="1"
env_track="${track^^}"
env_slug="${CI_ENVIRONMENT_SLUG//-/_}"
env_slug="${env_slug^^}"
echo "Deploying $CI_ENVIRONMENT_SLUG (track: $track, replicas: $replicas) with $CI_REGISTRY_IMAGE:$CI_REGISTRY_TAG..."
sed -i -e s/CI_PIPELINE_ID/$CI_PIPELINE_ID/g -e s/CI_ENVIRONMENT_SLUG/$CI_ENVIRONMENT_SLUG/g -e s/FQDN/$FQDN/g ${CI_PROJECT_DIR}/.k8s/*.yaml
kubectl apply -n $KUBE_NAMESPACE -f ${CI_PROJECT_DIR}/.k8s/ -o json > /tmp/out.json
echo "Waiting for deployment..."
DEPLOYMENTS=$(cat /tmp/out.json | jq 'if .kind == "List" then .["items"][] else . end' | jq '. | select(."kind" == "Deployment")' | jq -r '.metadata.name')
for DEPLOYMENT in $DEPLOYMENTS; do
kubectl rollout status -n "$KUBE_NAMESPACE" -w "deploy/${DEPLOYMENT}"
done
if [[ "$track" == "stable" ]]; then
echo "Removing canary deployments (if found)..."
kubectl delete all,ing -l "app=$CI_ENVIRONMENT_SLUG" -l "track=canary" -n "$KUBE_NAMESPACE"
fi
echo "Application is accessible at: ${CI_ENVIRONMENT_URL}"
echo ""