Skip to content

Commit

Permalink
Merge pull request #2 from flanksource/deploy
Browse files Browse the repository at this point in the history
Deploy
  • Loading branch information
moshloop authored Jan 27, 2022
2 parents c8e65d9 + ff42700 commit 0c50f3a
Show file tree
Hide file tree
Showing 37 changed files with 42,433 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
.DS_Store
cover.out
test.test
build/
17 changes: 15 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ else
GOBIN=$(shell go env GOBIN)
endif

test:
test: ui
go test ./... -coverprofile cover.out

fmt:
Expand Down Expand Up @@ -75,7 +75,7 @@ lint:

.PHONY: ui
ui:
# cd ui && npm ci && npm run build
cd ui && npm ci && npm run build

.PHONY: build
build:
Expand Down Expand Up @@ -103,3 +103,16 @@ test-e2e: bin
chmod +x .bin/octopilot

bin: .bin .bin/wait4x .bin/yq .bin/karina .bin/go-junit-report .bin/restic .bin/jmeter telepresence .bin/octopilot .bin/kustomize

.bin/kustomize: .bin
curl -L https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv4.3.0/kustomize_v4.3.0_$(OS)_$(ARCH).tar.gz -o kustomize.tar.gz && \
tar xf kustomize.tar.gz -C .bin/ && \
rm kustomize.tar.gz


.PHONY: stack
stack: .bin/kustomize
kubectl apply -f deploy/namespace.yaml
$(KUSTOMIZE) build deploy/postgres | kubectl apply -f -
kubectl wait --for=condition=ready pod -l app=postgres -n incident-commander --timeout=2m
$(KUSTOMIZE) build deploy | kubectl apply -f -
5 changes: 1 addition & 4 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"fmt"
"net/http"
"net/url"

"github.com/flanksource/commons/logger"
Expand All @@ -19,9 +18,7 @@ var Serve = &cobra.Command{
logger.Errorf("Failed to initialize the db: %v", err)
}
e := echo.New()
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
e.Static("/", "./ui/build")
// PostgREST needs to know how it is exposed to create the correct links
db.HttpEndpoint = publicEndpoint + "/db"
go db.StartPostgrest()
Expand Down
12 changes: 12 additions & 0 deletions deploy/apm-hub/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace: incident-commander
bases:
- "https://github.com/flanksource/apm-hub/deploy/"
patchesStrategicMerge:
- |
apiVersion: v1
kind: Namespace
metadata:
name: apm-hub
labels:
control-plane: apm-hub
$patch: delete
6 changes: 6 additions & 0 deletions deploy/canary-checker/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace: incident-commander
resources:
- "postgres-secret.yaml"
- https://raw.githubusercontent.com/flanksource/canary-checker/v0.38.74/config/deploy/manifests.yaml
patchesStrategicMerge:
- patch.yaml
53 changes: 53 additions & 0 deletions deploy/canary-checker/patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
control-plane: canary-checker
name: canary-checker
namespace: canary-checker
spec:
replicas: 1
selector:
matchLabels:
control-plane: canary-checker
template:
metadata:
labels:
control-plane: canary-checker
spec:
containers:
- name: canary-checker
env:
- name: DOCKER_API_VERSION
value: "1.39"
- name: DB_URL
valueFrom:
secretKeyRef:
name: canary-checker-postgres-connection-string
key: connection-string
---
apiVersion: v1
kind: Namespace
metadata:
name: canary-checker
labels:
control-plane: canary-checker
$patch: delete
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/tls-acme: "true"
name: canary-checker
namespace: canary-checker
$patch: delete
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
control-plane: canary-checker
name: canary-checker-monitor
namespace: canary-checker
$patch: delete
7 changes: 7 additions & 0 deletions deploy/canary-checker/postgres-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
data:
connection-string: cG9zdGdyZXNxbDovL3Bvc3RncmVzOlNvbTNQYXNzd2RAcG9zdGdyZXMtZGIuaW5jaWRlbnQtY29tbWFuZGVyL2NhbmFyeV9jaGVja2Vy
kind: Secret
metadata:
creationTimestamp: null
name: canary-checker-postgres-connection-string
7 changes: 7 additions & 0 deletions deploy/config-db/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace: incident-commander
bases:
- "https://github.com/flanksource/config-db/deploy"
resources:
- postgres-secret.yaml
patchesStrategicMerge:
- patch.yaml
34 changes: 34 additions & 0 deletions deploy/config-db/patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: config-db
labels:
control-plane: config-db
spec:
selector:
matchLabels:
control-plane: config-db
replicas: 1
template:
metadata:
labels:
control-plane: config-db
spec:
serviceAccountName: config-db-sa
containers:
- name: config-db
env:
- name: DB_URL
valueFrom:
secretKeyRef:
name: config-db-postgres-connection-string
key: connection-string
---
apiVersion: v1
kind: Namespace
metadata:
name: config-db
labels:
control-plane: config-db
$patch: delete
6 changes: 6 additions & 0 deletions deploy/config-db/postgres-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
data:
connection-string: cG9zdGdyZXNxbDovL3Bvc3RncmVzOlNvbTNQYXNzd2RAcG9zdGdyZXMtZGIuaW5jaWRlbnQtY29tbWFuZGVyL2NvbmZpZ19kYg==
kind: Secret
metadata:
name: config-db-postgres-connection-string
4 changes: 4 additions & 0 deletions deploy/incident-commander/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace: incident-commander
resources:
- "postgres-secret.yaml"
- "manager.yaml"
56 changes: 56 additions & 0 deletions deploy/incident-commander/manager.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: incident-commander
labels:
control-plane: incident-commander
spec:
selector:
matchLabels:
control-plane: incident-commander
replicas: 1
template:
metadata:
labels:
control-plane: incident-commander
spec:
containers:
- name: incident-commander
image: docker.io/flanksource/incident-commander:latest
env:
- name: DB_URL
valueFrom:
secretKeyRef:
name: incident-commander-postgres-connection-string
key: connection-string
command:
- /app/incident-commander
args:
- serve
- -vvv
- --apm-hub=http://apm-hub.incident-commander.svc:8080
- --canary-checker=http://canary-checker.incident-commander.svc:8080
- --config-db=http://config-db.incident-commander.svc:8080
resources:
requests:
cpu: 200m
memory: 200Mi
limits:
memory: 512Mi
cpu: 500m
---
apiVersion: v1
kind: Service
metadata:
labels:
control-plane: incident-commander
name: incident-commander
namespace: incident-commander
spec:
ports:
- port: 8080
protocol: TCP
targetPort: 8080
selector:
control-plane: incident-commander
7 changes: 7 additions & 0 deletions deploy/incident-commander/postgres-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
data:
connection-string: cG9zdGdyZXNxbDovL3Bvc3RncmVzOlNvbTNQYXNzd2RAcG9zdGdyZXMtZGIuaW5jaWRlbnQtY29tbWFuZGVyL2luY2lkZW50X2NvbW1hbmRlcg==
kind: Secret
metadata:
creationTimestamp: null
name: incident-commander-postgres-connection-string
8 changes: 8 additions & 0 deletions deploy/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resources:
- namespace.yaml
bases:
- postgres
- apm-hub
- config-db
- canary-checker
- incident-commander
6 changes: 6 additions & 0 deletions deploy/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: Namespace
metadata:
name: incident-commander
labels:
control-plane: incident-commander
4 changes: 4 additions & 0 deletions deploy/postgres/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace: incident-commander
resources:
- "postgres-init-script.yaml"
- "postgres.yaml"
19 changes: 19 additions & 0 deletions deploy/postgres/postgres-init-script.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Adding init script to add more databases for the different comonents
## See: https://hub.docker.com/_/postgres #Initialization scripts for more info
apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-init-script
data:
init-user-db.sh: |
#!/bin/bash
set -e
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE DATABASE canary_checker;
CREATE DATABASE config_db;
CREATE DATABASE incident_commander;
GRANT ALL PRIVILEGES ON DATABASE canary_checker TO "$POSTGRES_USER";
GRANT ALL PRIVILEGES ON DATABASE config_db TO "$POSTGRES_USER";
GRANT ALL PRIVILEGES ON DATABASE incident_commander TO "$POSTGRES_USER";
EOSQL
74 changes: 74 additions & 0 deletions deploy/postgres/postgres.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
apiVersion: v1
data:
password: U29tM1Bhc3N3ZA==
kind: Secret
metadata:
name: postgres-secret-config
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-pv-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
type: database
template:
metadata:
labels:
app: postgres
type: database
spec:
volumes:
- name: postgres-pv-storage
persistentVolumeClaim:
claimName: postgres-pv-claim
- name: init-script
configMap:
name: postgres-init-script
containers:
- name: postgres
image: postgres:11
imagePullPolicy: IfNotPresent
ports:
- containerPort: 5432
env:
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-secret-config
key: password
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: postgres-pv-storage
- name: init-script
mountPath: /docker-entrypoint-initdb.d/init-user-db.sh
subPath: init-user-db.sh
---
apiVersion: v1
kind: Service
metadata:
name: postgres-db
spec:
selector:
app: postgres
type: database
ports:
- protocol: TCP
port: 5432
targetPort: 5432
Loading

0 comments on commit 0c50f3a

Please sign in to comment.