Skip to content

Commit cc9647c

Browse files
authored
feat: deploy on kubernetes (#2594)
1 parent 970ee70 commit cc9647c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+259
-630
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,5 @@ Build the images first with
7676
# start docker compose for `deploy/compose.yml`
7777
./scripts/docker-deploy-test.sh
7878
```
79+
80+
https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/do-more-with-tunnels/local-management/create-local-tunnel/

ai-bot.Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
1616

1717
RUN pnpm packages:build
1818

19+
WORKDIR /home/node/services/ai-bot
20+
21+
CMD ["pnpm", "docker:dev"]
22+
1923
FROM ghcr.io/lies-exposed/liexp-base:24-latest AS deps
2024

2125
WORKDIR /home/node
@@ -34,7 +38,7 @@ WORKDIR /home/node
3438

3539
RUN mkdir build scripts
3640

37-
COPY ./services/ai-bot/build/run-esbuild.js build/run-esbuild.js
41+
COPY ./services/ai-bot/build/run-esbuild.cjs build/run-esbuild.cjs
3842

3943
COPY --from=deps /home/node/node_modules ./node_modules
4044

@@ -49,8 +53,6 @@ RUN strip ./ai-bot
4953
RUN npx postject ai-bot NODE_SEA_BLOB ./build/ai-bot.blob \
5054
--sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2
5155

52-
53-
5456
FROM ghcr.io/lies-exposed/liexp-base:24-latest AS production
5557

5658
WORKDIR /home/node

compose.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ services:
22
db.liexp.dev:
33
image: postgres:17
44
ports:
5-
- "127.0.0.1:8432:5432"
5+
- "8432:5432"
66
environment:
77
POSTGRES_USER: liexp
88
POSTGRES_PASSWORD: liexp-password
99
POSTGRES_DB: liexp
10-
VIRTUAL_HOST: db.liexp.dev
11-
VIRTUAL_PORT: 5432
1210
restart: unless-stopped
1311
volumes:
1412
- ./services/api/db/dump:/docker-entrypoint-initdb.d
@@ -20,7 +18,7 @@ services:
2018
image: minio/minio:RELEASE.2024-08-03T04-33-23Z
2119
command: server --console-address ":9001" /data
2220
ports:
23-
- "127.0.0.1:9000:9000"
21+
- "9000:9000"
2422
- "127.0.0.1:9001:9001"
2523
environment:
2624
MINIO_ROOT_USER: space-access-key-id
@@ -122,16 +120,17 @@ services:
122120
ai-bot:
123121
build:
124122
context: .
125-
target: dev
123+
target: production
126124
dockerfile: ai-bot.Dockerfile
127-
command: "node --watch build/run-esbuild.js"
128125
env_file:
129126
- ./services/ai-bot/.env.local
130127
- ./services/ai-bot/.env
131128
volumes:
132-
- ./services/ai-bot/temp:/home/node/temp:rw
133-
- ./services/ai-bot/build:/home/node/build:cached
134-
- ./services/ai-bot/config/ai-bot.config.json:/home/node/config/ai-bot.config.json:rw
129+
- ./packages/@liexp:/home/node/packages/@liexp:ro
130+
- ./services/ai-bot/package.json:/home/node/services/ai-bot/package.json:cached
131+
- ./services/ai-bot/temp:/home/node/services/ai-bot/temp:rw
132+
- ./services/ai-bot/build:/home/node/services/ai-bot/build:cached
133+
- ./services/ai-bot/config/ai-bot.config.json:/home/node/services/ai-bot/config/ai-bot.config.json:rw
135134
restart: always
136135
mem_limit: 512M
137136
depends_on:
@@ -157,7 +156,6 @@ services:
157156
- ./packages/@liexp:/usr/src/app/packages/@liexp:ro
158157
- ./services/web:/usr/src/app/services/web:cached
159158
working_dir: /usr/src/app/services/web
160-
command: pnpm docker:dev
161159
mem_limit: 2G
162160
tty: true
163161
stdin_open: true
@@ -218,7 +216,7 @@ services:
218216
environment:
219217
DEBUG: true
220218
# REBUILD: true
221-
VIRTUAL_HOST: localai.liexp.dev,localai.lies.exposed
219+
VIRTUAL_HOST: localai.liexp.dev,ai.lies.exposed
222220
VIRTUAL_PORT: 8080
223221
OPENAI_API_KEY: no-key-is-a-good-key
224222
LOCALAI_CORS: 0

helm/config/nginx/telegram-bot-api.conf renamed to helm/config/nginx/telegram.conf

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,4 @@ server {
5757
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
5858
proxy_set_header X-Forwarded-Host $server_name;
5959
}
60-
}
61-
62-
# server {
63-
# # Enable HTTP/2
64-
# listen 443 ssl http2;
65-
# listen [::]:443 ssl http2;
66-
# server_name tg.lies.exposed;
67-
68-
# # Use the Let’s Encrypt certificates
69-
# ssl_certificate /etc/letsencrypt/live/alpha.api.lies.exposed/fullchain.pem; # managed by Certbot
70-
# ssl_certificate_key /etc/letsencrypt/live/alpha.api.lies.exposed/privkey.pem; # managed by Certbot
71-
72-
# # Include the SSL configuration from cipherli.st
73-
# include /etc/nginx/snippets/ssl-params.conf;
74-
75-
# client_max_body_size 3G;
76-
77-
# location / {
78-
# proxy_set_header X-Real-IP $remote_addr;
79-
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
80-
# proxy_pass http://127.0.0.1:8081/;
81-
# proxy_ssl_session_reuse off;
82-
# proxy_set_header Host $http_host;
83-
# proxy_cache_bypass $http_upgrade;
84-
# proxy_redirect off;
85-
# }
86-
87-
# }
60+
}

helm/templates/services/ai-bot/ai-bot.configmap.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ data:
88
},
99
"localAi": {
1010
"url": "http://localai.prod.svc.cluster.local/",
11-
"apiKey": "no-key-is-a-good-key",
11+
"apiKey": "{{ .Values.localai.openAIApiKey }}",
1212
"models": {
1313
"summarize": "gpt-4o",
1414
"chat": "qwen3-8b",

helm/templates/services/ai-bot/deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ spec:
3535
resources:
3636
limits:
3737
memory: 2Gi
38-
cpu: "500m"
38+
cpu: 400m
3939
requests:
4040
memory: 512Mi
41-
cpu: "200m"
41+
cpu: 200m
4242
volumeMounts:
4343
- name: ai-bot-config-storage
4444
mountPath: /home/node/config/

helm/templates/services/db/deployment.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ spec:
3131
name: db-initial-data
3232
resources:
3333
limits:
34-
cpu: 400m
35-
memory: 2Gi
36-
requests:
3734
cpu: 200m
3835
memory: 1Gi
36+
requests:
37+
cpu: 100m
38+
memory: 500Mi
3939
restartPolicy: Always
4040
volumes:
4141
- name: db-data
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{{/*
2+
Usage: {{ tuple . "$name" | include "localai.labels" | indent 2 }}
3+
*/}}
4+
5+
{{- define "localai.labels" -}}
6+
{{- $scope := index . 0 -}}
7+
{{- $lies_exposed_name := index . 1 -}}
8+
9+
{{- tuple $scope $lies_exposed_name "ai" | include "common.labels" -}}
10+
11+
{{- end -}}
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
apiVersion: v1
22
data:
33
LOCALAI_LOG_LEVEL: debug
4-
# LOCALAI_F16: "true"
5-
LOCALAI_API_KEY: {{ .Values.localai.openAIApiKey }}
4+
LOCALAI_THREADS: "6"
5+
LOCALAI_API_KEY: {{ .Values.localai.openAIApiKey | quote }}
66
kind: ConfigMap
77
metadata:
88
name: localai-env
9-
labels:
10-
lies.exposed/name: localai-env
11-
app.kubernetes.io/instance: {{ .Release.Name | quote }}
12-
app.kubernetes.io/namespace: {{ .Release.Namespace | quote }}
13-
app.kubernetes.io/component: ai
14-
app.kubernetes.io/managed-by: Helm
9+
namespace: {{ .Release.Namespace }}
10+
{{ tuple . "localai-env" | include "localai.labels" | indent 2 }}

helm/templates/services/localai/localai-models.volume.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ kind: PersistentVolume
33
metadata:
44
name: localai-models-volume
55
namespace: {{ .Release.Namespace }}
6-
labels:
7-
lies.exposed/name: localai-models-volume
8-
app.kubernetes.io/instance: {{ .Release.Name | quote }}
9-
app.kubernetes.io/namespace: {{ .Release.Namespace | quote }}
10-
app.kubernetes.io/managed-by: Helm
6+
{{ tuple . "localai-models-volume" | include "localai.labels" | indent 2 }}
117
spec:
12-
storageClassName: manual
8+
storageClassName: microk8s-hostpath
139
capacity:
1410
storage: 40Gi
1511
accessModes:

0 commit comments

Comments
 (0)