-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
75 lines (57 loc) · 2.28 KB
/
deploy.sh
File metadata and controls
75 lines (57 loc) · 2.28 KB
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
#!/bin/bash
set -e
BUILD=false
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ID="threadit-api"
CLUSTER_NAME="threadit-cluster"
ZONE="europe-west1-b"
SERVICES=(db community thread comment vote search popular)
# Set project and set up cluster context
gcloud config set project $PROJECT_ID
gcloud container clusters get-credentials $CLUSTER_NAME --zone=$ZONE
GCS_KEY="gcs-key"
BUCKET_SECRET=$(gcloud secrets versions access latest --secret=$GCS_KEY)
MONGO_USER=$(gcloud secrets versions access latest --secret="mongo-user")
MONGO_PASS=$(gcloud secrets versions access latest --secret="mongo-pass")
# Check for --build flag
if [[ "$1" == "--build" ]]; then
BUILD=true
echo "Building and pushing images..."
fi
# Build and push docker images
build_and_push_images() {
cd "$SCRIPT_DIR/../../" || exit 1
gcloud auth configure-docker
for SERVICE in "${SERVICES[@]}"; do
docker build -t gcr.io/$PROJECT_ID/"$SERVICE-service":latest -f services/"$SERVICE-service"/Dockerfile .
docker push gcr.io/$PROJECT_ID/"$SERVICE-service":latest
done
docker build -t gcr.io/$PROJECT_ID/grpc-gateway:latest -f grpc-gateway/Dockerfile .
docker push gcr.io/$PROJECT_ID/grpc-gateway:latest
cd "$SCRIPT_DIR" || exit 1
}
# Build and push images if --build is passed
if [ "$BUILD" = true ]; then
build_and_push_images
fi
cd "$SCRIPT_DIR/.." || exit 1
# Deploy traefik
helm repo add traefik https://traefik.github.io/charts
helm repo update
helm upgrade --install traefik traefik/traefik -n $CLUSTER_NAME -f traefik/resources.yaml
kubectl apply -n $CLUSTER_NAME -f traefik/ingress.yaml
kubectl apply -n $CLUSTER_NAME -f traefik/hpa-config.yaml
# Deploy threadit application
kubectl create secret generic "bucket-secret" \
--from-literal="$GCS_KEY.json=$BUCKET_SECRET" \
-n $CLUSTER_NAME --dry-run=client -o yaml | kubectl apply -f -
kubectl create secret generic "mongo-secret" \
--from-literal="MONGO_INITDB_ROOT_USERNAME=$MONGO_USER" \
--from-literal="MONGO_INITDB_ROOT_PASSWORD=$MONGO_PASS" \
-n $CLUSTER_NAME --dry-run=client -o yaml | kubectl apply -f -
kubectl apply -n $CLUSTER_NAME -f config.yaml
kubectl apply -n $CLUSTER_NAME -f mongo/
for SERVICE in "${SERVICES[@]}"; do
kubectl apply -n $CLUSTER_NAME -f services/"$SERVICE-service"/
done
kubectl apply -n $CLUSTER_NAME -f grpc-gateway/