Skip to content

Commit

Permalink
feat: [WIP] add deployment script for minikube
Browse files Browse the repository at this point in the history
  • Loading branch information
DiCanio committed Mar 15, 2024
1 parent fc3c2b0 commit e1e24c7
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ db.sqlite
.env
cache
.swc

k8s/tmp**
7 changes: 4 additions & 3 deletions k8s/broker-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ spec:
restartPolicy: "Always"
containers:
- name: node-message-broker
image: docker.io/flame/node-message-broker:test
image: docker.io/flame/node-message-broker:latest
imagePullPolicy: "IfNotPresent"
securityContext:
runAsNonRoot: true
runAsUser: 1000
Expand All @@ -34,7 +35,7 @@ spec:
- name: SERVER_PORT
value: "8080"
- name: AUTH_JWKS_URL
value: ${AUTH_JWKS_URL}
value: <AUTH_JWKS_URL>
- name: MONGO_DB_URL
value: "mongodb://node-message-broker-db:27017"
- name: MONGO_DB_NAME
Expand All @@ -44,7 +45,7 @@ spec:
- name: HUB_AUTH_BASE_URL
value: "https://auth.privateaim.net/"
- name: HUB_AUTH_ROBOT_ID
value: ${HUB_AUTH_ROBOT_ID}
value: <HUB_AUTH_ROBOT_ID>
- name: HUB_AUTH_ROBOT_SECRET
valueFrom:
secretKeyRef:
Expand Down
110 changes: 110 additions & 0 deletions k8s/deploy-to-minikube.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env bash

# Mandatory environment variables:
#
# - AUTH_JWKS_URL
# - HUB_AUTH_ROBOT_ID
# - ROBOT_SECRET
# - NODE_MESSAGE_BROKER_HOST

BASE_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit 1 ; pwd -P )"

echo "${AUTH_JWKS_URL}"
echo "${HUB_AUTH_ROBOT_ID}"
echo "${ROBOT_SECRET}"
echo "${NODE_MESSAGE_BROKER_HOST}"

if [[ -z "${AUTH_JWKS_URL}" || -z "${HUB_AUTH_ROBOT_ID}" || -z "${ROBOT_SECRET}" || -z "${NODE_MESSAGE_BROKER_HOST}" ]]; then
echo "One or more mandatory environment variables are not set!"
echo "Mandatory environment variables are:"
echo ""
echo " - AUTH_JWKS_URL"
echo " - HUB_AUTH_ROBOT_ID"
echo " - ROBOT_SECRET"
echo " - NODE_MESSAGE_BROKER_HOST"
exit 1
fi

echo -n "Creating working directory..."
WORK_DIR=`mktemp -d -p "${BASE_DIR}"`
if [ $? -ne 0 ]; then
echo "FAILED"
exit 2
else
echo "OK"
fi

echo -n "Copying k8s manifest files..."
for f in "${BASE_DIR}"/*.yml; do
cp "${f}" "${WORK_DIR}"
done
if [ $? -ne 0 ]; then
echo "FAILED"
exit 3
else
echo "OK"
fi

echo -n "Preparing broker deployment..."
sed -i -e "s#<AUTH_JWKS_URL>#${AUTH_JWKS_URL}#" \
-e "s#<HUB_AUTH_ROBOT_ID>#${HUB_AUTH_ROBOT_ID}#" \
"${WORK_DIR}/broker-deployment.yml"
if [ $? -ne 0 ]; then
echo "FAILED"
exit 4
else
echo "OK"
fi

echo -n "Preparing hub auth secret..."
sed -i -e "s#<ROBOT_SECRET>#${ROBOT_SECRET}#" \
"${WORK_DIR}/hub-auth-secret.yml"
if [ $? -ne 0 ]; then
echo "FAILED"
exit 5
else
echo "OK"
fi

echo -n "Preparing ingress..."
sed -i -e "s#<NODE_MESSAGE_BROKER_HOST>#${NODE_MESSAGE_BROKER_HOST}#" \
"${WORK_DIR}/ingress.yml"
if [ $? -ne 0 ]; then
echo "FAILED"
exit 6
else
echo "OK"
fi


echo -n "Deleting previous image..."
minikube image rm docker.io/flame/node-message-broker:latest
if [ $? -ne 0 ]; then
echo "FAILED"
exit 7
else
echo "OK"
fi

echo -n "Creating Docker image..."
minikube image build -t docker.io/flame/node-message-broker:latest "${BASE_DIR}/.."
if [ $? -ne 0 ]; then
echo "FAILED"
exit 8
else
echo "OK"
fi

echo -n "Applying manifest files..."
kubectl --namespace=flame apply -f "${WORK_DIR}/hub-auth-secret.yml" \
-f "${WORK_DIR}/broker-db-service.yml" \
-f "${WORK_DIR}/broker-db-statefulset.yml" \
-f "${WORK_DIR}/broker-service.yml" \
-f "${WORK_DIR}/broker-deployment.yml" \
-f "${WORK_DIR}/ingress.yml"
if [ $? -ne 0 ]; then
echo "FAILED"
exit 9
else
echo "OK"
fi
2 changes: 1 addition & 1 deletion k8s/hub-auth-secret.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ kind: Secret
metadata:
name: hub-auth
data:
robot-secret: ${ROBOT_SECRET}
robot-secret: <ROBOT_SECRET>
20 changes: 10 additions & 10 deletions k8s/ingress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ metadata:
app.kubernetes.io/part-of: flame
spec:
rules:
- host: ${NODE_MESSAGE_BROKER_HOST}
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: node-message-broker
port:
number: 80
- host: message-broker.<NODE_MESSAGE_BROKER_HOST>.nip.io
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: node-message-broker
port:
number: 80

0 comments on commit e1e24c7

Please sign in to comment.