-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwocky-deploy
executable file
·83 lines (69 loc) · 2.69 KB
/
wocky-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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
if [ "${1}" = "help" ]; then
script=$(basename "${0}")
echo "Usage: ${script} <environment> [extra_args]"
echo " environment - the environment name (defaults to testing)"
echo " extra_args - if supplied, this is passed directly to kubernetes-deploy"
exit 0
fi
if echo "${CI_COMMIT_MESSAGE}" | fgrep -qi "[skip deploy]"; then
echo "Skipping deployment."
exit 0
fi
if [ "${CI_COMMIT_MESSAGE}" != "" ]; then
msg="Last commit: ${CI_COMMIT_MESSAGE}"
fi
wocky_env="${1:-"testing"}"
context="${CONTEXT:-"aws"}"
namespace="wocky-${wocky_env}"
template_dir="k8s/${wocky_env}"
cluster_conf=/tmp/cluster.tfstate.json
ssl_conf=/tmp/ssl.tfstate.json
wocky_conf=/tmp/wocky.tfstate.json
wocky_shared_conf=/tmp/wocky_shared.tfstate.json
db_dumper_conf=/tmp/db_dumper.tfstate.json
output_bindings=/tmp/bindings.json
export REVISION="${CI_COMMIT_ID:-"$(git rev-parse HEAD)"}"
export KUBECONFIG="${KUBECONFIG:-"${HOME}/.kube/config"}"
aws s3 cp s3://hippware-terraform-state/cluster/terraform.tfstate ${cluster_conf}
aws s3 cp s3://hippware-terraform-state/ssl/terraform.tfstate ${ssl_conf}
aws s3 cp s3://hippware-terraform-state/wocky-${wocky_env}/terraform.tfstate ${wocky_conf}
aws s3 cp s3://hippware-terraform-state/wocky-shared/terraform.tfstate ${wocky_shared_conf}
aws s3 cp s3://hippware-terraform-state/db-dumper/terraform.tfstate ${db_dumper_conf}
jq -s '[.[].outputs] | add' ${cluster_conf} ${ssl_conf} ${wocky_conf} ${wocky_shared_conf} ${db_dumper_conf} > ${output_bindings}
kubernetes-deploy "${namespace}" "${context}" \
--template-dir="${template_dir}" \
--bindings=@${output_bindings} \
"$@"
result=$?
if [ $result -eq 0 ]; then
# Add a tag to mark the image as the current one deployed on the environment
manifest=$(aws ecr batch-get-image \
--region us-west-2 \
--repository-name hippware/wocky \
--image-ids imageTag=${REVISION} \
--query 'images[].imageManifest' \
--output text)
aws ecr put-image \
--region us-west-2 \
--repository-name hippware/wocky \
--image-tag deployed-${wocky_env} \
--image-manifest "${manifest}"
status="success"
else
status="failed"
fi
# Select the most recent wocky pod to ensure we don't pick an old,
# terminating one
pod=$(kubectl get pods \
-n "${namespace}" \
-l 'app=wocky' \
-o jsonpath="{range .items[*]}{.metadata.creationTimestamp} {.metadata.name}{'\n'}{end}" \
| sort -n \
| tail -n 1 \
| cut -f2 -d ' ')
kubectl exec -it -n "${namespace}" "${pod}" bin/wocky notify_complete "${status}" "${msg}"
# As our last act, print out the deployed version on the last line. This allows
# the calling script to easily pick up the version.
kubectl exec -it -n "${namespace}" "${pod}" bin/wocky version
exit $result