-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deploy: websocket service in production (#106)
Co-authored-by: Mauro <[email protected]>
- Loading branch information
1 parent
c5d2e67
commit 3586dba
Showing
18 changed files
with
222 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: websocket-event-publisher | ||
name: websocket-event-publisher | ||
namespace: chicmoz-prod | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: websocket-event-publisher | ||
strategy: {} | ||
template: | ||
metadata: | ||
labels: | ||
app: websocket-event-publisher | ||
spec: | ||
containers: | ||
- image: registry.digitalocean.com/aztlan-containers/websocket-event-publisher:latest | ||
name: websocket-event-publisher | ||
resources: | ||
limits: | ||
memory: 2048Mi | ||
cpu: 250m | ||
ports: | ||
- name: websocket-port | ||
containerPort: 3000 | ||
protocol: TCP | ||
env: | ||
- name: PORT | ||
value: "3000" | ||
status: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apiVersion: networking.k8s.io/v1 | ||
kind: Ingress | ||
metadata: | ||
name: ingress-websocket-event-publisher | ||
namespace: chicmoz-prod | ||
annotations: | ||
nginx.ingress.kubernetes.io/proxy-read-timeout: "3600" | ||
nginx.ingress.kubernetes.io/proxy-send-timeout: "3600" | ||
cert-manager.io/cluster-issuer: "chicmoz-issuer-production" | ||
spec: | ||
ingressClassName: nginx | ||
tls: | ||
- hosts: | ||
- ws.chicmoz.info | ||
secretName: chicmoz-ws-tls | ||
rules: | ||
- host: ws.chicmoz.info | ||
http: | ||
paths: | ||
- path: / | ||
pathType: ImplementationSpecific | ||
backend: | ||
service: | ||
name: websocket-event-publisher | ||
port: | ||
name: websocket-port | ||
status: | ||
loadBalancer: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: websocket-event-publisher | ||
namespace: chicmoz-prod | ||
spec: | ||
selector: | ||
app: websocket-event-publisher | ||
ports: | ||
- name: websocket | ||
protocol: TCP | ||
port: 80 | ||
targetPort: websocket-port |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
kubectl scale --replicas 0 -n chicmoz-prod deployment aztec-listener | ||
kubectl scale --replicas 0 -n chicmoz-prod deployment explorer-api | ||
kubectl scale --replicas 0 -n chicmoz-prod deployment auth | ||
kubectl scale --replicas 0 -n chicmoz-prod deployment websocket-event-publisher |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
kubectl scale statefulset --replicas 0 -n chicmoz-prod kafka-controller | ||
kubectl scale statefulset --replicas 0 -n chicmoz-prod redis-master | ||
kubectl scale statefulset --replicas 0 -n chicmoz-prod redis-replicas | ||
kubectl scale statefulset --replicas 0 -n chicmoz-prod postgresql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
kubectl scale --replicas 1 -n chicmoz-prod deployment aztec-listener | ||
kubectl scale --replicas 1 -n chicmoz-prod deployment explorer-api | ||
kubectl scale --replicas 1 -n chicmoz-prod deployment auth | ||
kubectl scale --replicas 1 -n chicmoz-prod deployment websocket-event-publisher |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
kubectl scale statefulset --replicas 1 -n chicmoz-prod kafka-controller | ||
kubectl scale statefulset --replicas 1 -n chicmoz-prod redis-master | ||
kubectl scale statefulset --replicas 1 -n chicmoz-prod redis-replicas | ||
kubectl scale statefulset --replicas 1 -n chicmoz-prod postgresql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/bin/bash | ||
|
||
# NOTE: all this hassle just to *only* use 5 images on the registry... | ||
|
||
set -e | ||
|
||
# List of images to push | ||
IMAGES_TO_PUSH=( | ||
"explorer-ui" | ||
"auth" | ||
"aztec-listener" | ||
"explorer-api" | ||
"websocket-event-publisher" | ||
) | ||
|
||
echo "⚠ Building images - this may take a while..." | ||
# Build images and get the build output | ||
BUILD_OUTPUT=$(skaffold build --filename "k8s/production/skaffold.production.light.yaml" --quiet) | ||
|
||
# Function to extract tag for a specific image | ||
get_tag() { | ||
local image=$1 | ||
echo "$BUILD_OUTPUT" | grep "$image" | sed -E 's/.*:([^}]+)\}.*/\1/' | tr -d '"' | ||
} | ||
|
||
# Function to find the latest image | ||
find_latest_image() { | ||
local image=$1 | ||
docker images --format "{{.Repository}}:{{.Tag}}" | grep "^$image:" | head -n 1 | ||
} | ||
|
||
# Tag and push each image | ||
for image in "${IMAGES_TO_PUSH[@]}" | ||
do | ||
TAG=$(get_tag "$image") | ||
if [ -n "$TAG" ]; then | ||
LATEST_IMAGE=$(find_latest_image "$image") | ||
if [ -n "$LATEST_IMAGE" ]; then | ||
echo "Tagging and pushing $LATEST_IMAGE as registry.digitalocean.com/aztlan-containers/$image:$TAG" | ||
docker tag "$LATEST_IMAGE" "registry.digitalocean.com/aztlan-containers/$image:$TAG" | ||
echo "Tagging and pushing $LATEST_IMAGE as registry.digitalocean.com/aztlan-containers/$image:latest" | ||
docker tag "$LATEST_IMAGE" "registry.digitalocean.com/aztlan-containers/$image:latest" | ||
docker push "registry.digitalocean.com/aztlan-containers/$image:$TAG" | ||
docker push "registry.digitalocean.com/aztlan-containers/$image:latest" | ||
else | ||
echo "Failed to find latest image for $image" | ||
exit 1 | ||
fi | ||
else | ||
echo "Failed to get tag for $image" | ||
exit 1 | ||
fi | ||
done | ||
|
||
# Get the tag for chicmoz-base | ||
CHICMOZ_BASE_TAG=$(get_tag "chicmoz-base") | ||
|
||
# Prepare the --images argument for skaffold deploy | ||
DEPLOY_IMAGES_ARG="chicmoz-base=chicmoz-base:$CHICMOZ_BASE_TAG," | ||
for image in "${IMAGES_TO_PUSH[@]}" | ||
do | ||
TAG=$(get_tag "$image") | ||
if [ -n "$TAG" ]; then | ||
DEPLOY_IMAGES_ARG+="$image=registry.digitalocean.com/aztlan-containers/$image:$TAG," | ||
else | ||
echo "Failed to get tag for $image" | ||
exit 1 | ||
fi | ||
done | ||
DEPLOY_IMAGES_ARG=${DEPLOY_IMAGES_ARG%,} # Remove trailing comma | ||
|
||
# Deploy using Skaffold | ||
echo "Deploying with images: $DEPLOY_IMAGES_ARG" | ||
skaffold deploy --filename "k8s/production/skaffold.production.light.yaml" --images "$DEPLOY_IMAGES_ARG" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
kubectl scale statefulset --replicas 3 -n chicmoz-prod kafka-controller | ||
kubectl scale statefulset --replicas 1 -n chicmoz-prod redis-master | ||
kubectl scale statefulset --replicas 3 -n chicmoz-prod redis-replicas | ||
kubectl scale statefulset --replicas 1 -n chicmoz-prod postgresql |