Skip to content

Commit 16810bf

Browse files
authored
Merge pull request #61 from ThreaditApp/dev
Updated main branch (GSM integration)
2 parents 0401a37 + 916910f commit 16810bf

File tree

7 files changed

+67
-66
lines changed

7 files changed

+67
-66
lines changed

code/kubernetes/mongo/deployment.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ spec:
2626
- name: MONGO_INITDB_ROOT_USERNAME
2727
valueFrom:
2828
secretKeyRef:
29-
name: mongodb-credentials
29+
name: mongo-secret
3030
key: MONGO_INITDB_ROOT_USERNAME
3131
- name: MONGO_INITDB_ROOT_PASSWORD
3232
valueFrom:
3333
secretKeyRef:
34-
name: mongodb-credentials
34+
name: mongo-secret
3535
key: MONGO_INITDB_ROOT_PASSWORD
3636
volumeMounts:
3737
- name: mongodb-data
@@ -40,3 +40,14 @@ spec:
4040
- name: mongodb-data
4141
persistentVolumeClaim:
4242
claimName: mongo-pvc
43+
---
44+
apiVersion: v1
45+
kind: PersistentVolumeClaim
46+
metadata:
47+
name: mongo-pvc
48+
spec:
49+
accessModes:
50+
- ReadWriteOnce
51+
resources:
52+
requests:
53+
storage: 2Gi

code/kubernetes/mongo/mongo-pv.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.

code/kubernetes/mongo/mongo-secret.yaml

Lines changed: 0 additions & 8 deletions
This file was deleted.

code/kubernetes/scripts/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ $ ./create-cluster.sh
1313
```
1414
### 2. Deployment
1515

16-
Builds and pushes Docker images to **Google Container Registry (GCR)**, and deploys all services to the cluster using `kubectl`
16+
Deploys all services and components to the cluster using `kubectl`.
1717

1818
```bash
1919
$ ./deploy.sh
2020
```
2121

22-
#### Optional: Skip Image Build & Push
22+
This will deploy using the latest available Docker images in **Google Container Registry (GCR)**.
2323

24-
If you've already built and pushed your Docker images, you can skip that step to speed up re-deployments:
24+
#### Optional: Build & Push
25+
26+
If you want to build and push the Docker images before deploying, use the --build flag:
2527

2628
```bash
27-
$ ./deploy.sh --skip-build
29+
$ ./deploy.sh --build
2830
```
2931

3032
### 3. View Cluster Info

code/kubernetes/scripts/deploy.sh

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,75 @@
11
#!/bin/bash
22
set -e
33

4+
BUILD=false
5+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
46
PROJECT_ID="threadit-api"
57
CLUSTER_NAME="threadit-cluster"
68
ZONE="europe-west1-b"
9+
SERVICES=(db community thread comment vote search popular)
710

8-
SKIP_BUILD=false
9-
10-
# Check for --skip-build flag
11-
if [[ "$1" == "--skip-build" ]]; then
12-
SKIP_BUILD=true
13-
echo "Skipping image build and push..."
14-
fi
15-
11+
# Set project and set up cluster context
1612
gcloud config set project $PROJECT_ID
13+
gcloud container clusters get-credentials $CLUSTER_NAME --zone=$ZONE
1714

18-
# Auth Docker with GCR
19-
gcloud auth configure-docker
15+
GCS_KEY="gcs-key"
16+
BUCKET_SECRET=$(gcloud secrets versions access latest --secret=$GCS_KEY)
17+
MONGO_USER=$(gcloud secrets versions access latest --secret="mongo-user")
18+
MONGO_PASS=$(gcloud secrets versions access latest --secret="mongo-pass")
2019

21-
# Move to repo code root (Threadit/code/)
22-
cd "$(dirname "$0")/../../"
20+
# Check for --build flag
21+
if [[ "$1" == "--build" ]]; then
22+
BUILD=true
23+
echo "Building and pushing images..."
24+
fi
25+
26+
# Build and push docker images
27+
build_and_push_images() {
28+
cd "$SCRIPT_DIR/../../" || exit 1
2329

24-
# Services list
25-
SERVICES=(db-service community-service thread-service comment-service vote-service search-service popular-service)
30+
gcloud auth configure-docker
2631

27-
if [ "$SKIP_BUILD" = false ]; then
28-
# Build and push all service images
2932
for SERVICE in "${SERVICES[@]}"; do
30-
docker build -t gcr.io/$PROJECT_ID/$SERVICE:latest -f services/$SERVICE/Dockerfile .
31-
docker push gcr.io/$PROJECT_ID/$SERVICE:latest
33+
docker build -t gcr.io/$PROJECT_ID/"$SERVICE-service":latest -f services/"$SERVICE-service"/Dockerfile .
34+
docker push gcr.io/$PROJECT_ID/"$SERVICE-service":latest
3235
done
3336

34-
# gRPC Gateway
3537
docker build -t gcr.io/$PROJECT_ID/grpc-gateway:latest -f grpc-gateway/Dockerfile .
3638
docker push gcr.io/$PROJECT_ID/grpc-gateway:latest
37-
fi
3839

39-
# Move to Kubernetes directory
40-
cd kubernetes
40+
cd "$SCRIPT_DIR" || exit 1
41+
}
4142

42-
# Authenticate and set up cluster context
43-
gcloud container clusters get-credentials $CLUSTER_NAME --zone=$ZONE
43+
# Build and push images if --build is passed
44+
if [ "$BUILD" = true ]; then
45+
build_and_push_images
46+
fi
4447

45-
# Apply general config
46-
kubectl apply -n $CLUSTER_NAME -f config.yaml
48+
cd "$SCRIPT_DIR/.." || exit 1
4749

48-
# Traefik
50+
# Deploy traefik
51+
helm repo add traefik https://traefik.github.io/charts
52+
helm repo update
4953
helm upgrade --install traefik traefik/traefik -n $CLUSTER_NAME -f traefik/values.yaml
54+
5055
kubectl apply -n $CLUSTER_NAME -f traefik/cors.yaml
5156
kubectl apply -n $CLUSTER_NAME -f traefik/strip-prefix.yaml
5257

53-
# MongoDB
58+
# Deploy threadit application
59+
kubectl create secret generic "bucket-secret" \
60+
--from-literal="$GCS_KEY.json=$BUCKET_SECRET" \
61+
-n $CLUSTER_NAME --dry-run=client -o yaml | kubectl apply -f -
62+
63+
kubectl create secret generic "mongo-secret" \
64+
--from-literal="MONGO_INITDB_ROOT_USERNAME=$MONGO_USER" \
65+
--from-literal="MONGO_INITDB_ROOT_PASSWORD=$MONGO_PASS" \
66+
-n $CLUSTER_NAME --dry-run=client -o yaml | kubectl apply -f -
67+
68+
kubectl apply -n $CLUSTER_NAME -f config.yaml
5469
kubectl apply -n $CLUSTER_NAME -f mongo/
5570

56-
# Services
5771
for SERVICE in "${SERVICES[@]}"; do
58-
kubectl apply -n $CLUSTER_NAME -f services/$SERVICE/
72+
kubectl apply -n $CLUSTER_NAME -f services/"$SERVICE-service"/
5973
done
6074

61-
# gRPC Gateway
6275
kubectl apply -n $CLUSTER_NAME -f grpc-gateway/

code/kubernetes/services/db-service/db-secret.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.

code/kubernetes/services/db-service/deployment.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ spec:
2828
value: "mongodb://$(MONGO_INITDB_ROOT_USERNAME):$(MONGO_INITDB_ROOT_PASSWORD)@mongodb:27017/$(MONGO_INITDB_DATABASE)?authSource=admin"
2929
envFrom:
3030
- secretRef:
31-
name: mongodb-credentials
31+
name: mongo-secret
3232
- configMapRef:
3333
name: threadit-config
3434
volumeMounts:
3535
- mountPath: /var/secret/gcp/
36-
name: gcs-credentials
36+
name: bucket-credentials
3737
readOnly: true
3838
volumes:
39-
- name: gcs-credentials
39+
- name: bucket-credentials
4040
secret:
41-
secretName: db-secret
41+
secretName: bucket-secret
4242
items:
4343
- key: gcs-key.json
4444
path: gcs-key.json

0 commit comments

Comments
 (0)