Skip to content

Commit

Permalink
Providing demo deployment (#17)
Browse files Browse the repository at this point in the history
* Providing demo deployment

* Add tini and role

* Use tini in sidecar

* Fix config load and requsts

* Add sa on bridge
  • Loading branch information
Wh1isper committed Jul 10, 2024
1 parent 92818cd commit 7888d8e
Show file tree
Hide file tree
Showing 17 changed files with 550 additions and 4 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ repos:
- id: check-case-conflict
- id: check-toml
- id: check-yaml
args: [--allow-multiple-documents]
- id: debug-statements
- id: forbid-new-submodules
- id: trailing-whitespace
Expand Down
6 changes: 6 additions & 0 deletions docker/Dockerfile.matrix
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ RUN hatch build

FROM python:3.10.12-slim-bookworm

RUN apt-get update && apt-get install -y --no-install-recommends \
tini \
&& rm -rf /var/lib/apt/lists/*

COPY --from=builder /source/dist/*.whl /tmp/

RUN pip install --no-cache-dir $(echo /tmp/*.whl)[service]

ENV MORIARTY_LOG_LEVEL=INFO

ENTRYPOINT [ "tini", "--" ]
9 changes: 7 additions & 2 deletions docker/Dockerfile.sidecar
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ RUN hatch build

FROM python:3.10.12-slim-bookworm

RUN apt-get update && apt-get install -y --no-install-recommends \
tini \
&& rm -rf /var/lib/apt/lists/*

COPY --from=builder /source/dist/*.whl /tmp/

RUN pip install --no-cache-dir $(echo /tmp/*.whl)

ENV MORIARTY_LOG_LEVEL=INFO

ENTRYPOINT [ "moriarty-sidecar" ]
CMD [ "start" ]

ENTRYPOINT [ "tini", "--" ]
CMD [ "moriarty-sidecar", "start" ]
10 changes: 10 additions & 0 deletions example/deploy-on-k8s/configs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: kubespawner
namespace: moriarty
data:
MORIARTY_KUBE_NAMESPACE_ENV: "moriarty"
# INIT_IMAGE:
# SIDECAR_IMAGE:
# IMAGE_PULL_SECRETS:
78 changes: 78 additions & 0 deletions example/deploy-on-k8s/infra/pgsql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
apiVersion: v1
kind: Service
metadata:
name: postgres-node
namespace: moriarty
spec:
selector:
app: postgres
ports:
- name: postgres
protocol: TCP
port: 5432
targetPort: 5432
nodePort: 31432
type: NodePort
---
apiVersion: v1
kind: Service
metadata:
name: postgres
namespace: moriarty
spec:
selector:
app: postgres
clusterIP: None
ports:
- name: postgres
port: 5432
---
apiVersion: v1
kind: Secret
metadata:
name: database
namespace: moriarty
type: Opaque
data:
POSTGRES_USER: cG9zdGdyZXM=
POSTGRES_PASSWORD: VGgxczFzTXlQYXNzdzByZA==
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
namespace: moriarty
labels:
app: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres

template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:14
env:
- name: POSTGRES_DB
value: moriarty-matrix
envFrom:
- secretRef:
name: database
ports:
- containerPort: 5432
imagePullPolicy: IfNotPresent
lifecycle:
postStart:
exec:
command:
[
"sh",
"-c",
"while ! pg_isready -U postgres; do sleep 1; done",
]
63 changes: 63 additions & 0 deletions example/deploy-on-k8s/infra/redis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
apiVersion: v1
kind: Service
metadata:
name: redis-node
namespace: moriarty
spec:
selector:
app: redis
ports:
- name: redis
protocol: TCP
port: 6379
targetPort: 6379
nodePort: 31379
type: NodePort
---
apiVersion: v1
kind: Service
metadata:
name: redis
namespace: moriarty
spec:
selector:
app: redis
clusterIP: None
ports:
- name: redis
port: 6379
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
namespace: moriarty
labels:
app: redis
spec:
replicas: 1

selector:
matchLabels:
app: redis

template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis
ports:
- containerPort: 6379
imagePullPolicy: IfNotPresent
livenessProbe:
tcpSocket:
port: 6379
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 3
restartPolicy: Always
58 changes: 58 additions & 0 deletions example/deploy-on-k8s/matrix-connector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
apiVersion: v1
kind: Service
metadata:
name: moriarty-connector
namespace: moriarty
spec:
selector:
app: moriarty-connector
ports:
- name: moriarty-connector
port: 8901
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: moriarty-connector
namespace: moriarty
labels:
app: moriarty-connector
spec:
replicas: 3
strategy:
type: RollingUpdate
selector:
matchLabels:
app: moriarty-connector
template:
metadata:
labels:
app: moriarty-connector
spec:
containers:
- name: moriarty-connector
image: wh1isper/moriarty
command: ["moriarty-connector"]
args: ["start"]
envFrom:
- secretRef:
name: sqs-bridge
ports:
- containerPort: 8901
imagePullPolicy: Always
resources:
requests:
cpu: 100m
memory: 256Mi
limits:
cpu: 1000m
memory: 1024Mi
readinessProbe:
httpGet:
path: /
port: 8901
initialDelaySeconds: 3
periodSeconds: 10
timeoutSeconds: 2
failureThreshold: 20
restartPolicy: Always
19 changes: 19 additions & 0 deletions example/deploy-on-k8s/operator/init.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: batch/v1
kind: Job
metadata:
name: moriarty-operator-init
namespace: moriarty
spec:
template:
spec:
containers:
- name: moriarty-operator
image: wh1isper/moriarty
command: ["moriarty-operator"]
args: ["init"]
envFrom:
- secretRef:
name: database
imagePullPolicy: Always
restartPolicy: Never
backoffLimit: 0
67 changes: 67 additions & 0 deletions example/deploy-on-k8s/operator/matrix-operator-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
apiVersion: v1
kind: Service
metadata:
name: moriarty-operator
namespace: moriarty
spec:
selector:
app: moriarty-operator
ports:
- name: moriarty-operator
port: 8999
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: moriarty-operator-callback
namespace: moriarty
labels:
app: moriarty-operator-callback
spec:
replicas: 1
strategy:
type: RollingUpdate
selector:
matchLabels:
app: moriarty-operator-callback
template:
metadata:
labels:
app: moriarty-operator-callback
spec:
serviceAccountName: moriarty-operator
containers:
- name: moriarty-operator-callback
image: wh1isper/moriarty
command: ["moriarty-operator"]
args: ["callback"]
envFrom:
- secretRef:
name: sqs-bridge
- secretRef:
name: redis
- secretRef:
name: database
- secretRef:
name: model
- configMapRef:
name: kubespawner
ports:
- containerPort: 8999
imagePullPolicy: Always
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 1000m
memory: 1024Mi
readinessProbe:
httpGet:
path: /
port: 8999
initialDelaySeconds: 3
periodSeconds: 10
timeoutSeconds: 2
failureThreshold: 20
restartPolicy: Always
45 changes: 45 additions & 0 deletions example/deploy-on-k8s/operator/matrix-operator-autoscaler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: moriarty-operator-autoscaler
namespace: moriarty
labels:
app: moriarty-operator-autoscaler
spec:
replicas: 1
strategy:
type: RollingUpdate
selector:
matchLabels:
app: moriarty-operator-autoscaler
template:
metadata:
labels:
app: moriarty-operator-autoscaler
spec:
serviceAccountName: moriarty-operator
containers:
- name: moriarty-operator-autoscaler
image: wh1isper/moriarty
command: ["moriarty-operator"]
args: ["autoscale"]
envFrom:
- secretRef:
name: sqs-bridge
- secretRef:
name: redis
- secretRef:
name: database
- secretRef:
name: model
- configMapRef:
name: kubespawner
imagePullPolicy: Always
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 1000m
memory: 1024Mi
restartPolicy: Always
Loading

0 comments on commit 7888d8e

Please sign in to comment.