Skip to content

Commit

Permalink
feat: add kubernetes manifests for feature based
Browse files Browse the repository at this point in the history
  • Loading branch information
omidasadpour committed Nov 16, 2023
1 parent d352c62 commit 77fec1a
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 0 deletions.
107 changes: 107 additions & 0 deletions deployment/feature-based/all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
apiVersion: v1
kind: Service
metadata:
labels:
app: aggregation-<BRANCH>
name: aggregation-<BRANCH>
namespace: sub-id
spec:
ports:
- port: 3000
protocol: TCP
targetPort: 3000
selector:
app: aggregation-<BRANCH>
type: ClusterIP

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: aggregation-<BRANCH>
namespace: sub-id
annotations:
ingress.kubernetes.io/from-to-www-redirect: "true"
nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
nginx.org/client-max-body-size: "10m"
nginx.ingress.kubernetes.io/proxy-body-size: "10m"
nginx.ingress.kubernetes.io/client-max-body-size: "10m"

spec:
ingressClassName: nginx
rules:
- host: <BRANCH>-aggregation.subsocial.network
http:
paths:
- backend:
service:
name: aggregation-<BRANCH>
port:
number: 3000
path: /
pathType: Prefix

tls:
- hosts:
- <BRANCH>-aggregation.subsocial.network
secretName: subsocial-ssl

---
apiVersion: v1
kind: ConfigMap
metadata:
name: aggregation-<BRANCH>-env
namespace: sub-id
data:
AGGREGATOR_DB_DATABASE: "aggregator_<BRANCH>-env"
AGGREGATOR_REDIS_HOST: "redis-aggregation-<BRANCH>-master.default"
AGGREGATOR_REDIS_PREFIX: "aggregator_queue_<BRANCH>"
AGGREGATOR_REDIS_PORT: "6379"
AGGREGATOR_REDIS_ENABLE_SSL: "false"
AGGREGATOR_HISTORY_RENEW_INTERVAL_MS: "10000"
DATA_SOURCE_GSQUID_MAIN_POLKADOT: "https://squid.subsquid.io/gs-main-polkadot/graphql"
DATA_SOURCE_GSQUID_MAIN_KUSAMA: "https://squid.subsquid.io/gs-main-kusama/graphql"
DATA_SOURCE_GSQUID_MAIN_MOONBEAM: "https://squid.subsquid.io/gs-main-moonbeam/graphql"
DATA_SOURCE_GSQUID_MAIN_MOONRIVER: "https://squid.subsquid.io/gs-main-moonriver/graphql"
DATA_SOURCE_GSQUID_MAIN_ASTAR: "https://squid.subsquid.io/gs-main-astar/graphql"
NODE_ENV: "development"
APP_PORT: "3000"

---
apiVersion: v1
kind: ConfigMap
metadata:
name: db-<BRANCH>-env
namespace: sub-id
data:
db-creation.sh: |
#!/bin/bash
set -e
# Check if the database already exists
if PGPASSWORD=$AGGREGATOR_DB_PASSWORD psql -U $AGGREGATOR_DB_USERNAME -h $AGGREGATOR_DB_HOST -p $AGGREGATOR_DB_PORT -lqt | cut -d \| -f 1 | grep "$AGGREGATOR_DB_DATABASE"; then
echo "Database '$AGGREGATOR_DB_DATABASE' already exists."
else
# Create the database
PGPASSWORD=$AGGREGATOR_DB_PASSWORD psql -U $AGGREGATOR_DB_USERNAME -h $AGGREGATOR_DB_HOST -p $AGGREGATOR_DB_PORT -c "create database \"$AGGREGATOR_DB_DATABASE\";"
echo "Database '$AGGREGATOR_DB_DATABASE' created."
fi
db-drop.sh: |
#!/bin/bash
set -e
# Check if the database exists
if PGPASSWORD=$AGGREGATOR_DB_PASSWORD psql -U $AGGREGATOR_DB_USERNAME -h $AGGREGATOR_DB_HOST -p $AGGREGATOR_DB_PORT -lqt | cut -d \| -f 1 | grep "$AGGREGATOR_DB_DATABASE"; then
# Remove the database
PGPASSWORD=$AGGREGATOR_DB_PASSWORD psql -U $AGGREGATOR_DB_USERNAME -h $AGGREGATOR_DB_HOST -p $AGGREGATOR_DB_PORT -c "DROP DATABASE \"$AGGREGATOR_DB_DATABASE\";"
echo "Database '$AGGREGATOR_DB_DATABASE' removed."
else
# Database doesn't exist
echo "Database '$AGGREGATOR_DB_DATABASE' doesn't exist."
fi
50 changes: 50 additions & 0 deletions deployment/feature-based/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: aggregation-<BRANCH>
name: aggregation-<BRANCH>
namespace: sub-id
spec:
replicas: 1
selector:
matchLabels:
app: aggregation-<BRANCH>
template:
metadata:
labels:
app: aggregation-<BRANCH>
name: aggregation-<BRANCH>
spec:
initContainers:
- name: db-deployer
image: postgres:14.1-alpine
command: ["/bin/bash"]
args: ["/opt/subscial/db-scripts/db-creation.sh"]
envFrom:
- configMapRef:
name: aggregation-<BRANCH>-env
- secretRef:
name: aggregation-service-secret
volumeMounts:
- name: db-creation-script
mountPath: /opt/subscial/db-scripts
readOnly: false
containers:
- image: <IMAGE>
imagePullPolicy: IfNotPresent
name: aggregation-service
ports:
- containerPort: 3000
envFrom:
- configMapRef:
name: aggregation-<BRANCH>-env
- secretRef:
name: aggregation-service-secret
imagePullSecrets:
- name: dockerhub
restartPolicy: Always
volumes:
- name: db-creation-script
configMap:
name: db-<BRANCH>-env
33 changes: 33 additions & 0 deletions deployment/feature-based/remove-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
apiVersion: batch/v1
kind: Job
metadata:
name: data-hub-<BRANCH>-job
spec:
backoffLimit: 6
activeDeadlineSeconds: 5000
template:
metadata:
name: data-hub-<BRANCH>-job
spec:
imagePullSecrets:
- name: dockerhub
restartPolicy: OnFailure
containers:
- name: db-destroyer
image: postgres:14.1-alpine
command: ["/bin/bash"]
args: ["/opt/subscial/db-scripts/db-drop.sh"]
envFrom:
- configMapRef:
name: data-hub-<BRANCH>-env
- secretRef:
name: data-hub-service-secret
volumeMounts:
- name: db-remove-script
mountPath: /var/opt/subscial/db-scripts
readOnly: false
volumes:
- name: db-remove-script
configMap:
name: db-<BRANCH>-env

0 comments on commit 77fec1a

Please sign in to comment.