This repository has been archived by the owner on Nov 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeploy.sh
executable file
·92 lines (79 loc) · 2.62 KB
/
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
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
84
85
86
87
88
89
90
91
92
#!/bin/sh
#
# This script does the initial setup for the secops environment.
# You should only run this once to get it going, then just use terraform apply
# after that.
#
set -e
if [ -z "$1" ]; then
echo "usage: $0 <cluster_name> [<cluster_type>]"
echo "example: ./deploy.sh secops-dev"
echo "example: ./deploy.sh secops-dev dev"
exit 1
else
if [ -n "$2" ] ; then
if [ ! -d "$2" ] ; then
echo "cluster type not found: $2"
exit 1
fi
fi
export TF_VAR_cluster_name="$1"
fi
checkbinary() {
if which "$1" >/dev/null ; then
return 0
else
echo no "$1" found: exiting
exit 1
fi
}
REQUIREDBINARIES="
terraform
aws
kubectl
jq
"
for i in ${REQUIREDBINARIES} ; do
checkbinary "$i"
done
# some config
ACCOUNT=$(aws sts get-caller-identity | jq -r .Account)
REGION="us-west-2"
BUCKET="login-dot-gov-secops.${ACCOUNT}-${REGION}"
SCRIPT_BASE=$(dirname "$0")
RUN_BASE=$(pwd)
# clean up tfstate files so that we get them from the backend
find . -name terraform.tfstate -print0 | xargs -0 rm
# set it up with the s3 backend, push into the directory.
pushd "$SCRIPT_BASE/terraform"
terraform init -backend-config="bucket=$BUCKET" \
-backend-config="key=tf-state/$TF_VAR_cluster_name" \
-backend-config="dynamodb_table=secops_terraform_locks" \
-backend-config="region=$REGION" \
-upgrade
terraform apply
# This updates the kubeconfig so that the nodes can talk with the masters
# and also maps IAM roles to users.
aws eks update-kubeconfig --name "$TF_VAR_cluster_name"
# update the kubernetes services/configmap using terraform data.
terraform output config_map_aws_auth | kubectl apply -f -
terraform output idp_redis_service | kubectl apply -f - -n idp
terraform output idp_db_configmap | kubectl apply -f - -n idp
popd
# this turns on the EBS persistent volume stuff and make it the default
if kubectl describe sc ebs >/dev/null ; then
echo ebs persistant storage already set up
else
kubectl apply -k "github.com/kubernetes-sigs/aws-ebs-csi-driver/deploy/kubernetes/overlays/stable/?ref=master"
kubectl apply -f "$RUN_BASE/install/ebs_storage_class.yml"
fi
if kubectl get sc | grep -E '^gp2.*default' >/dev/null ; then
kubectl patch storageclass gp2 -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'
kubectl patch storageclass ebs -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
fi
# apply k8s config for this cluster
if [ -z "$2" ] ; then
kubectl apply -k "$RUN_BASE/install"
else
kubectl apply -k "$RUN_BASE/install-$2"
fi