Skip to content

Commit 3088dee

Browse files
committed
Created GCP deployment
1 parent 857a5ac commit 3088dee

23 files changed

+756
-1
lines changed

.gcp.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SENTRIUS_VERSION=1.0.9
2+
SENTRIUS_SSH_VERSION=1.0.2
3+
SENTRIUS_KEYCLOAK_VERSION=1.0.2
4+
SENTRIUS_AGENT_VERSION=1.0.10

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ api/node_modules/*
5050

5151
.settings/*
5252
.env.bak
53+
.gcp.env.bak

analyagents/src/main/java/io/sentrius/agent/analysis/agents/sessions/SessionAnalyticsAgent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private void saveToTracking(Long sessionId, String status) {
104104
trackingRepository.save(tracking);
105105
}
106106

107-
public List<TerminalCommand> parseAndSaveCommands(
107+
public List<TerminalCommand> parseAndSaveCommands(
108108
TerminalLogs previousLog,
109109
TerminalLogs terminalLog, TerminalSessionMetadata sessionMetadata) {
110110
SessionAnalyticsAgent.log.info("Parsing and saving commands from terminal log: {}", terminalLog.getOutput());

build-images-gcp.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
3+
# Load environment variables
4+
source .gcp.env
5+
6+
cp .gcp.env .gcp.env.bak
7+
8+
# Update the specific variables in the .gcp.env file
9+
update_env_var() {
10+
local key=$1
11+
local value=$2
12+
if grep -q "^$key=" .gcp.env; then
13+
# Replace the existing variable
14+
sed -i "s/^$key=.*/$key=$value/" .gcp.env
15+
else
16+
# Append the new variable if it doesn't exist
17+
echo "$key=$value" >> .gcp.env
18+
fi
19+
}
20+
21+
increment_patch_version() {
22+
version=$1
23+
major=$(echo "$version" | cut -d. -f1)
24+
minor=$(echo "$version" | cut -d. -f2)
25+
patch=$(echo "$version" | cut -d. -f3)
26+
new_patch=$((patch + 1))
27+
echo "$major.$minor.$new_patch"
28+
}
29+
30+
# Function to build, tag, and push a Docker image
31+
build_and_push_image() {
32+
local name=$1
33+
local version=$2
34+
local context_dir=$3
35+
36+
local repo="us-central1-docker.pkg.dev/sentrius-project/sentrius-repo"
37+
38+
echo "Building $name:$version..."
39+
docker build -t "$name:$version" "$context_dir" || { echo "Failed to build $name"; exit 1; }
40+
41+
echo "Tagging and pushing $name:$version to $repo..."
42+
docker tag "$name:$version" "$repo/$name:$version"
43+
docker push "$repo/$name:$version" || { echo "Failed to push $name:$version"; exit 1; }
44+
45+
echo "Successfully pushed $repo/$name:$version"
46+
}
47+
48+
# Parse flags
49+
update_sentrius=false
50+
update_sentrius_ssh=false
51+
update_sentrius_keycloak=false
52+
update_sentrius_agent=false
53+
54+
while [[ "$#" -gt 0 ]]; do
55+
case $1 in
56+
--sentrius) update_sentrius=true ;;
57+
--sentrius-ssh) update_sentrius_ssh=true ;;
58+
--sentrius-keycloak) update_sentrius_keycloak=true ;;
59+
--sentrius-agent) update_sentrius_agent=true ;;
60+
--all) update_sentrius=true; update_sentrius_ssh=true; update_sentrius_keycloak=true; update_sentrius_agent=true ;;
61+
*) echo "Unknown flag: $1"; exit 1 ;;
62+
esac
63+
shift
64+
done
65+
66+
# Authenticate with Google Artifact Registry
67+
echo "Authenticating with Google Cloud..."
68+
gcloud auth configure-docker us-central1-docker.pkg.dev || { echo "Failed to authenticate with Artifact Registry"; exit 1; }
69+
70+
# Build and push selected images
71+
if $update_sentrius; then
72+
SENTRIUS_VERSION=$(increment_patch_version $SENTRIUS_VERSION)
73+
build_and_push_image "sentrius" "$SENTRIUS_VERSION" "."
74+
update_env_var "SENTRIUS_VERSION" "$SENTRIUS_VERSION"
75+
fi
76+
77+
if $update_sentrius_ssh; then
78+
SENTRIUS_SSH_VERSION=$(increment_patch_version $SENTRIUS_SSH_VERSION)
79+
build_and_push_image "sentrius-ssh" "$SENTRIUS_SSH_VERSION" "./docker/fake-ssh"
80+
update_env_var "SENTRIUS_SSH_VERSION" "$SENTRIUS_SSH_VERSION"
81+
fi
82+
83+
if $update_sentrius_keycloak; then
84+
SENTRIUS_KEYCLOAK_VERSION=$(increment_patch_version $SENTRIUS_KEYCLOAK_VERSION)
85+
build_and_push_image "sentrius-keycloak" "$SENTRIUS_KEYCLOAK_VERSION" "./docker/keycloak"
86+
update_env_var "SENTRIUS_KEYCLOAK_VERSION" "$SENTRIUS_KEYCLOAK_VERSION"
87+
fi
88+
89+
if $update_sentrius_agent; then
90+
cp analyagents/target/analyagents-*.jar docker/sentrius-agent/agent.jar
91+
SENTRIUS_AGENT_VERSION=$(increment_patch_version $SENTRIUS_AGENT_VERSION)
92+
build_and_push_image "sentrius-agent" "$SENTRIUS_AGENT_VERSION" "./docker/sentrius-agent"
93+
rm docker/sentrius-agent/agent.jar
94+
update_env_var "SENTRIUS_AGENT_VERSION" "$SENTRIUS_AGENT_VERSION"
95+
fi

deploy-k8s-gcp.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# Step 1: Build images
4+
./build-images-gcp.sh "$@"
5+
6+
source .gcp.env
7+
8+
# Step 3: Deploy with Helm
9+
10+
# Deploy to GKE using Helm
11+
echo "Deploying to GKE using Helm..."
12+
13+
echo helm upgrade --install sentrius ./sentrius-gcp-chart \
14+
--namespace sentrius \
15+
--set sentrius.image.repository=us-central1-docker.pkg.dev/sentrius-project/sentrius-repo/sentrius \
16+
--set sentrius.image.tag=$SENTRIUS_VERSION \
17+
--set ssh.image.repository=us-central1-docker.pkg.dev/sentrius-project/sentrius-repo/sentrius-ssh \
18+
--set ssh.image.tag=${SENTRIUS_SSH_VERSION} \
19+
--set keycloak.image.repository=us-central1-docker.pkg.dev/sentrius-project/sentrius-repo/sentrius-keycloak \
20+
--set keycloak.image.tag=${SENTRIUS_KEYCLOAK_VERSION} \
21+
--set sentriusagent.image.repository=us-central1-docker.pkg.dev/sentrius-project/sentrius-repo/sentrius-agent \
22+
--set sentriusagent.image.tag=${SENTRIUS_AGENT_VERSION} || { echo "Failed to deploy Sentrius with Helm"; exit 1; }
23+
24+
helm upgrade --install sentrius ./sentrius-gcp-chart \
25+
--namespace sentrius \
26+
--set sentrius.image.repository=us-central1-docker.pkg.dev/sentrius-project/sentrius-repo/sentrius \
27+
--set sentrius.image.tag=$SENTRIUS_VERSION \
28+
--set ssh.image.repository=us-central1-docker.pkg.dev/sentrius-project/sentrius-repo/sentrius-ssh \
29+
--set ssh.image.tag=${SENTRIUS_SSH_VERSION} \
30+
--set keycloak.image.repository=us-central1-docker.pkg.dev/sentrius-project/sentrius-repo/sentrius-keycloak \
31+
--set keycloak.image.tag=${SENTRIUS_KEYCLOAK_VERSION} \
32+
--set sentriusagent.image.repository=us-central1-docker.pkg.dev/sentrius-project/sentrius-repo/sentrius-agent \
33+
--set sentriusagent.image.tag=${SENTRIUS_AGENT_VERSION} || { echo "Failed to deploy Sentrius with Helm"; exit 1; }
34+
35+
echo "Deployment completed successfully."

sentrius-gcp-chart/Chart.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v2
2+
name: sentrius-chart
3+
description: A Helm chart for Sentrius and PostgreSQL deployments
4+
version: 0.1.0
5+
appVersion: 1.0.0
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{{- define "sentrius.labels" -}}
2+
app.kubernetes.io/name: sentrius
3+
app.kubernetes.io/instance: {{ .Release.Name }}
4+
app.kubernetes.io/managed-by: {{ .Release.Service }}
5+
{{- end -}}
6+
{{- define "sentriusagent.labels" -}}
7+
app.kubernetes.io/name: sentrius-agent
8+
app.kubernetes.io/instance: {{ .Release.Name }}
9+
app.kubernetes.io/managed-by: {{ .Release.Service }}
10+
{{- end -}}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ .Release.Name }}-sentriusagent
5+
labels:
6+
{{- include "sentriusagent.labels" . | nindent 4 }}
7+
spec:
8+
replicas: {{ .Values.replicaCount }}
9+
selector:
10+
matchLabels:
11+
app: sentriusagent
12+
template:
13+
metadata:
14+
labels:
15+
app: sentriusagent
16+
spec:
17+
initContainers:
18+
- name: wait-for-postgres
19+
image: busybox
20+
command: [ 'sh', '-c', 'until nc -z {{ .Release.Name }}-postgres.{{ .Release.Namespace }}.svc.cluster.local 5432; do echo waiting for postgres; sleep 2; done;' ]
21+
- name: wait-for-keycloak
22+
image: busybox
23+
command: [ 'sh', '-c', 'until nc -z {{ .Release.Name }}-keycloak.{{ .Release.Namespace }}.svc.cluster.local
24+
30081; do echo waiting for postgres; sleep 2; done;' ]
25+
containers:
26+
- name: sentrius-agent
27+
image: "{{ .Values.sentriusagent.image.repository }}:{{ .Values.sentriusagent.image.tag }}"
28+
imagePullPolicy: {{ .Values.sentriusagent.image.pullPolicy }}
29+
ports:
30+
- containerPort: {{ .Values.sentriusagent.port }}
31+
volumeMounts:
32+
- name: config-volume
33+
mountPath: /config
34+
env:
35+
- name: SPRING_DATASOURCE_USERNAME
36+
valueFrom:
37+
secretKeyRef:
38+
name: {{ .Release.Name }}-db-secret
39+
key: db-username
40+
- name: SPRING_DATASOURCE_PASSWORD
41+
valueFrom:
42+
secretKeyRef:
43+
name: {{ .Release.Name }}-db-secret
44+
key: db-password
45+
- name: KEYSTORE_PASSWORD
46+
valueFrom:
47+
secretKeyRef:
48+
name: {{ .Release.Name }}-db-secret
49+
key: keystore-password
50+
volumes:
51+
- name: config-volume
52+
configMap:
53+
name: {{ .Release.Name }}-sentriusagent-config
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ .Release.Name }}-sentriusagent
5+
spec:
6+
type: NodePort
7+
selector:
8+
app: sentriusagent
9+
ports:
10+
- protocol: TCP
11+
port: 80 # Port exposed to the outside world
12+
targetPort: {{ .Values.sentriusagent.port }} # Port used inside the container
13+
nodePort: {{ .Values.sentriusagent.service.nodePort | default 30083 }} # NodePort range: 30000-32767
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ .Release.Name }}-sentriusagent-config
5+
labels:
6+
{{- include "sentriusagent.labels" . | nindent 4 }}
7+
data:
8+
application.properties: |
9+
{{ .Values.sentriusagent.config.application | nindent 4 }}

0 commit comments

Comments
 (0)