Skip to content

Commit

Permalink
fix(env): add deploy env
Browse files Browse the repository at this point in the history
fix(k8s): fix liveness
  • Loading branch information
sd0xdev committed Aug 27, 2023
1 parent 28ab0f8 commit c99ab6c
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 5 deletions.
7 changes: 4 additions & 3 deletions apps/yggdrasil-core-engine/src/app/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Controller, Get } from '@nestjs/common';

import { AppService } from './app.service';

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get('/health')
getData() {
return 'OK';
}
}
154 changes: 153 additions & 1 deletion tools/cdk8s/yggdrasil-core-engine/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
KubeDeployment,
KubeNamespace,
KubeRoleBinding,
KubeService,
KubeServiceAccount,
Quantity,
} from './imports/k8s';
Expand All @@ -17,6 +18,116 @@ require('dotenv').config({
: path.resolve(__dirname, './env', `.env.${process.env.NODE_ENV}`),
});

const env = [
{
name: 'NODE_ENV',
value: `${process.env.SERVICE_TAGS ?? 'development'}`,
},
{
name: 'PACKAGE_NAME',
value: `${process.env.PACKAGE_NAME ?? 'Yggdrasil Core Engine'}`,
},
{
name: 'SERVICE_NAME',
value: `${process.env.SERVICE_NAME ?? 'yggdrasil-core-engine'}`,
},
{
name: 'LOGGER_LEVEL',
value: `${process.env.LOGGER_LEVEL ?? 'info'}`,
},
{
name: 'A_AZURE_OPENAI_ENABLE',
value: `${process.env.A_AZURE_OPENAI_ENABLE ?? 'true'}`,
},
{
name: 'A_AZURE_OPENAI_DEPLOYMENT_NAME',
value: `${process.env.A_AZURE_OPENAI_DEPLOYMENT_NAME ?? 'gpt-3_5'}`,
},
{
name: 'A_AZURE_OPENAI_MODEL_NAME',
value: `${process.env.A_AZURE_OPENAI_MODEL_NAME ?? 'gpt-35-turbo'}`,
},
{
name: 'A_AZURE_OPENAI_API_VERSION',
value: `${process.env.A_AZURE_OPENAI_API_VERSION ?? '2023-07-01-preview'}`,
},
];

const secretRef = [
{
name: 'CORE_ENGINE_API_KEY',
valueFrom: {
secretKeyRef: {
name: 'yggdrasil-core-engine',
key: 'core-engine-api-key',
},
},
},
{
name: 'OPENAI_API_KEY',
valueFrom: {
secretKeyRef: {
name: 'yggdrasil-core-engine',
key: 'openai-api-key',
},
},
},
{
name: 'CHATGPT_ORG',
valueFrom: {
secretKeyRef: {
name: 'yggdrasil-core-engine',
key: 'chatgpt-org',
},
},
},
{
name: 'A_AZURE_OPENAI_API_KEY',
valueFrom: {
secretKeyRef: {
name: 'yggdrasil-core-engine',
key: 'a-azure-openai-api-key',
},
},
},
{
name: 'A_AZURE_OPENAI_ENDPOINT',
valueFrom: {
secretKeyRef: {
name: 'yggdrasil-core-engine',
key: 'a-azure-openai-endpoint',
},
},
},
{
name: 'A_AZURE_OPENAI_INSTANCE_NAME',
valueFrom: {
secretKeyRef: {
name: 'yggdrasil-core-engine',
key: 'a-azure-openai-instance-name',
},
},
},
{
name: 'RPC_API_KEY',
valueFrom: {
secretKeyRef: {
name: 'yggdrasil-core-engine',
key: 'rpc-api-key',
},
},
},
{
name: 'MONGO_DB_URI',
valueFrom: {
secretKeyRef: {
name: 'yggdrasil-core-engine',
key: 'mongo-db-uri',
},
},
},
];

export class MyChart extends Chart {
appContainerName = process.env.CONTAINERNAME ?? 'yggdrasil-core-engine';

Expand All @@ -35,6 +146,7 @@ export class MyChart extends Chart {
});

this.setupApp();
this.setupService();

// setup cronjob service account
new KubeServiceAccount(this, 'service-account', {
Expand Down Expand Up @@ -118,10 +230,12 @@ export class MyChart extends Chart {
name: 'SERVICE_TAGS',
value: `${process.env.SERVICE_TAGS ?? 'development'}`,
},
...env,
...secretRef,
],
livenessProbe: {
httpGet: {
path: '/',
path: '/api/health',
port: IntOrString.fromNumber(3000),
},
initialDelaySeconds: 10,
Expand All @@ -133,6 +247,44 @@ export class MyChart extends Chart {
},
});
}

private setupService() {
new KubeService(this, 'service', {
metadata: {
name: this.labels.service,
namespace: this.namespace,
},
spec: {
type: 'ClusterIP',
selector: {
app: this.labels.app,
},
ports: [
{
port: 80,
targetPort: IntOrString.fromNumber(
Number(process.env.APP_CLUSTER_PORT ?? 3001)
),
name: 'http',
},
{
port: Number(process.env.APP_CLUSTER_GRPC_PORT ?? 5000),
targetPort: IntOrString.fromNumber(
Number(process.env.APP_CLUSTER_GRPC_PORT ?? 5000)
),
name: 'grpc',
},
{
port: Number(process.env.APP_CLUSTER_GRPC2_PORT ?? 5001),
targetPort: IntOrString.fromNumber(
Number(process.env.APP_CLUSTER_GRPC2_PORT ?? 5001)
),
name: 'grpc2',
},
],
},
});
}
}

const app = new App();
Expand Down
2 changes: 2 additions & 0 deletions tools/cdk8s/yggdrasil-discord-client/env/.env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ IMAGE_PATH=registry.gitlab.com/welfree-studio/asgard-hub/yggdrasil-core-engine-i
APP_CLUSTER_PORT=80
IMAGE_PULL_POLICY=IfNotPresent
IMAGE_PULL_SECRETS=gitlab-registry
CORE_ENGINE_URL=yggdrasil-core-engine.yggdrasil-core-engine.svc.cluster.local:5000
CORE_ENGINE_LLM_AI_URL=yggdrasil-core-engine.yggdrasil-core-engine.svc.cluster.local:5001
93 changes: 92 additions & 1 deletion tools/cdk8s/yggdrasil-discord-client/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,95 @@ require('dotenv').config({
: path.resolve(__dirname, './env', `.env.${process.env.NODE_ENV}`),
});

const env = [
{
name: 'PACKAGE_NAME',
value: 'yggdrasil-discord-client',
},
{
name: 'CORE_ENGINE_PACKAGE',
value: 'chatgpt',
},
{
name: 'CORE_ENGINE_LLM_AI_PACKAGE',
value: 'llmai',
},
{
name: 'CORE_ENGINE_URL',
value: process.env.CORE_ENGINE_URL ?? 'localhost:5000',
},
{
name: 'CORE_ENGINE_LLM_AI_URL',
value: process.env.CORE_ENGINE_LLM_AI_URL ?? 'localhost:5001',
},
];

const secretRef = [
{
name: 'CORE_ENGINE_API_KEY',
valueFrom: {
secretKeyRef: {
name: 'yggdrasil-discord-client',
key: 'core-engine-api-key',
},
},
},
{
name: 'DISCORD_TOKEN',
valueFrom: {
secretKeyRef: {
name: 'yggdrasil-discord-client',
key: 'discord-token',
},
},
},
{
name: 'DISCORD_BOT_CLIENT_ID',
valueFrom: {
secretKeyRef: {
name: 'yggdrasil-discord-client',
key: 'discord-bot-client-id',
},
},
},
{
name: 'DISCORD_DEVELOP_CHANNEL_ID',
valueFrom: {
secretKeyRef: {
name: 'yggdrasil-discord-client',
key: 'discord-develop-channel-id',
},
},
},
{
name: 'DISCORD_DISABLE_BOT_CHANNEL_IDS',
valueFrom: {
secretKeyRef: {
name: 'yggdrasil-discord-client',
key: 'discord-disable-bot-channel-ids',
},
},
},
{
name: 'DISCORD_PERMANENT_CHANNEL_ID',
valueFrom: {
secretKeyRef: {
name: 'yggdrasil-discord-client',
key: 'discord-permanent-channel-id',
},
},
},
{
name: 'DISCORD_PERMANENT_CHANNEL_IDS',
valueFrom: {
secretKeyRef: {
name: 'yggdrasil-discord-client',
key: 'discord-permanent-channel-ids',
},
},
},
];

export class MyChart extends Chart {
appContainerName = process.env.CONTAINERNAME ?? 'yggdrasil-discord-client';

Expand Down Expand Up @@ -118,10 +207,12 @@ export class MyChart extends Chart {
name: 'SERVICE_TAGS',
value: `${process.env.SERVICE_TAGS ?? 'development'}`,
},
...env,
...secretRef,
],
livenessProbe: {
httpGet: {
path: '/',
path: '/api',
port: IntOrString.fromNumber(3000),
},
initialDelaySeconds: 10,
Expand Down
20 changes: 20 additions & 0 deletions tools/k8s/yggdrasil-core-engine/secret.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
kind: Namespace
metadata:
name: yggdrasil-core-engine-staging
---
apiVersion: v1
kind: Secret
metadata:
name: yggdrasil-core-engine
namespace: yggdrasil-core-engine-staging
type: Opaque
stringData:
core-engine-api-key:
openai-api-key:
chatgpt-org:
a-azure-openai-api-key:
a-azure-openai-endpoint:
a-azure-openai-instance-name:
rpc-api-key:
mongo-db-uri:
19 changes: 19 additions & 0 deletions tools/k8s/yggdrasil-discord-client/secret.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Namespace
metadata:
name: yggdrasil-discord-client-staging
---
apiVersion: v1
kind: Secret
metadata:
name: yggdrasil-discord-client
namespace: yggdrasil-discord-client-staging
type: Opaque
stringData:
core-engine-api-key:
discord-token:
discord-bot-client-id:
discord-develop-channel-id:
discord-disable-bot-channel-ids:
discord-permanent-channel-id:
discord-permanent-channel-ids:

0 comments on commit c99ab6c

Please sign in to comment.