mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-01 09:29:38 +02:00
Merge commit 'a8390532f7' as 'ai-context/workbench-ui'
This commit is contained in:
commit
1a72bfdec0
310 changed files with 56430 additions and 0 deletions
14
ai-context/workbench-ui/pulumi/Pulumi.dev.yaml
Normal file
14
ai-context/workbench-ui/pulumi/Pulumi.dev.yaml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
encryptionsalt: v1:vQGk98eEeYI=:v1:tHg+f1b66tEydgA9:J1RGVNI0FssyjSXVhcKU7bfBofNFTg==
|
||||
config:
|
||||
config-ui:artifact-name: config-ui-dev
|
||||
config-ui:artifact-repo: us-central1-docker.pkg.dev/trustgraph-demo/config-ui-dev
|
||||
config-ui:artifact-repo-region: us-central1
|
||||
config-ui:cloud-run-region: us-central1
|
||||
config-ui:domain: demo.trustgraph.ai
|
||||
config-ui:environment: dev
|
||||
config-ui:gcp-project: trustgraph-demo
|
||||
config-ui:gcp-region: us-central1
|
||||
config-ui:hostname: dev.config-ui.demo.trustgraph.ai
|
||||
config-ui:managed-zone: demo
|
||||
config-ui:max-scale: "2"
|
||||
config-ui:min-scale: "0"
|
||||
14
ai-context/workbench-ui/pulumi/Pulumi.prod.yaml
Normal file
14
ai-context/workbench-ui/pulumi/Pulumi.prod.yaml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
encryptionsalt: v1:vQGk98eEeYI=:v1:tHg+f1b66tEydgA9:J1RGVNI0FssyjSXVhcKU7bfBofNFTg==
|
||||
config:
|
||||
config-ui:artifact-name: config-ui-prod
|
||||
config-ui:artifact-repo: us-central1-docker.pkg.dev/trustgraph-demo/config-ui-prod
|
||||
config-ui:artifact-repo-region: us-central1
|
||||
config-ui:cloud-run-region: us-central1
|
||||
config-ui:domain: demo.trustgraph.ai
|
||||
config-ui:environment: prod
|
||||
config-ui:gcp-project: trustgraph-demo
|
||||
config-ui:gcp-region: us-central1
|
||||
config-ui:hostname: config-ui.demo.trustgraph.ai
|
||||
config-ui:managed-zone: demo
|
||||
config-ui:max-scale: "2"
|
||||
config-ui:min-scale: "0"
|
||||
3
ai-context/workbench-ui/pulumi/Pulumi.yaml
Normal file
3
ai-context/workbench-ui/pulumi/Pulumi.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
name: config-ui
|
||||
runtime: nodejs
|
||||
description: Config UI
|
||||
348
ai-context/workbench-ui/pulumi/index.ts
Normal file
348
ai-context/workbench-ui/pulumi/index.ts
Normal file
|
|
@ -0,0 +1,348 @@
|
|||
|
||||
import * as pulumi from "@pulumi/pulumi";
|
||||
import * as gcp from "@pulumi/gcp";
|
||||
import { local } from "@pulumi/command";
|
||||
//import * as fs from 'fs';
|
||||
|
||||
const cfg = new pulumi.Config();
|
||||
|
||||
function get(tag : string) {
|
||||
|
||||
const val = cfg.get(tag);
|
||||
|
||||
if (!val) {
|
||||
console.log("ERROR: The '" + tag + "' config is mandatory");
|
||||
throw "The '" + tag + "' config is mandatory";
|
||||
}
|
||||
|
||||
return val;
|
||||
|
||||
}
|
||||
|
||||
const imageVersion = process.env.IMAGE_VERSION;
|
||||
if (!imageVersion)
|
||||
throw Error("IMAGE_VERSION not defined");
|
||||
|
||||
const repo = get("artifact-repo");
|
||||
const artifactRepoRegion = get("artifact-repo-region");
|
||||
const artifactName = get("artifact-name");
|
||||
const hostname = get("hostname");
|
||||
const managedZone = get("managed-zone");
|
||||
const project = get("gcp-project");
|
||||
const region = get("gcp-region");
|
||||
const cloudRunRegion = get("cloud-run-region");
|
||||
const environment = get("environment");
|
||||
//const domain = get("domain");
|
||||
const minScale = get("min-scale");
|
||||
const maxScale = get("max-scale");
|
||||
|
||||
const provider = new gcp.Provider(
|
||||
"gcp",
|
||||
{
|
||||
project: project,
|
||||
region: region,
|
||||
}
|
||||
);
|
||||
|
||||
const artifactRepo = new gcp.artifactregistry.Repository(
|
||||
"artifact-repo",
|
||||
{
|
||||
description: "repository for " + environment,
|
||||
format: "DOCKER",
|
||||
location: artifactRepoRegion,
|
||||
repositoryId: artifactName,
|
||||
cleanupPolicies: [
|
||||
{
|
||||
id: "keep-minimum-versions",
|
||||
action: "KEEP",
|
||||
mostRecentVersions: {
|
||||
keepCount: 5,
|
||||
},
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
provider: provider,
|
||||
}
|
||||
);
|
||||
|
||||
const localImageName = "localhost/config-ui:" + imageVersion;
|
||||
|
||||
const imageName = repo + "/config-ui:" + imageVersion;
|
||||
|
||||
const taggedImage = new local.Command(
|
||||
"podman-tag-command",
|
||||
{
|
||||
create: "podman tag " + localImageName + " " + imageName,
|
||||
}
|
||||
);
|
||||
|
||||
const image = new local.Command(
|
||||
"podman-push-command",
|
||||
{
|
||||
create: "podman push " + imageName,
|
||||
},
|
||||
{
|
||||
dependsOn: [taggedImage, artifactRepo],
|
||||
}
|
||||
);
|
||||
|
||||
const svcAccount = new gcp.serviceaccount.Account(
|
||||
"service-account",
|
||||
{
|
||||
accountId: "config-ui-" + environment,
|
||||
displayName: "Config UI",
|
||||
description: "Config UI",
|
||||
},
|
||||
{
|
||||
provider: provider,
|
||||
}
|
||||
);
|
||||
|
||||
/*
|
||||
|
||||
const vertexAiUserMember = new gcp.projects.IAMMember(
|
||||
"vertexai-user-role",
|
||||
{
|
||||
member: svcAccount.email.apply(x => "serviceAccount:" + x),
|
||||
project: project,
|
||||
role: "roles/aiplatform.admin",
|
||||
},
|
||||
{
|
||||
provider: provider,
|
||||
}
|
||||
);
|
||||
|
||||
*/
|
||||
|
||||
const service = new gcp.cloudrun.Service(
|
||||
"service",
|
||||
{
|
||||
name: "config-ui-" + environment,
|
||||
location: cloudRunRegion,
|
||||
template: {
|
||||
metadata: {
|
||||
labels: {
|
||||
version: "v" + imageVersion.replace(/\./g, "-"),
|
||||
},
|
||||
annotations: {
|
||||
|
||||
// Scale attributes
|
||||
"autoscaling.knative.dev/minScale": minScale,
|
||||
"autoscaling.knative.dev/maxScale": maxScale,
|
||||
|
||||
// 2nd generation. Need to specify at least 512MB RAM.
|
||||
// Going back to gen1 because faster cold starts
|
||||
"run.googleapis.com/execution-environment": "gen1",
|
||||
|
||||
}
|
||||
},
|
||||
spec: {
|
||||
containerConcurrency: 100,
|
||||
timeoutSeconds: 300,
|
||||
serviceAccountName: svcAccount.email,
|
||||
containers: [
|
||||
{
|
||||
image: imageName,
|
||||
// commands: [
|
||||
// "config-ui"
|
||||
// ],
|
||||
ports: [
|
||||
{
|
||||
"name": "http1", // Must be http1 or h2c.
|
||||
"containerPort": 8080,
|
||||
}
|
||||
],
|
||||
resources: {
|
||||
limits: {
|
||||
cpu: "1000m",
|
||||
memory: "512Mi",
|
||||
}
|
||||
},
|
||||
}
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
provider: provider,
|
||||
dependsOn: [image],
|
||||
}
|
||||
);
|
||||
|
||||
const allUsersPolicy = gcp.organizations.getIAMPolicy(
|
||||
{
|
||||
bindings: [{
|
||||
role: "roles/run.invoker",
|
||||
members: ["allUsers"],
|
||||
}],
|
||||
},
|
||||
{
|
||||
provider: provider,
|
||||
}
|
||||
);
|
||||
|
||||
/*const _noAuthPolicy =*/ new gcp.cloudrun.IamPolicy(
|
||||
"no-auth-policy",
|
||||
{
|
||||
location: service.location,
|
||||
project: service.project,
|
||||
service: service.name,
|
||||
policyData: allUsersPolicy.then(pol => pol.policyData),
|
||||
},
|
||||
{
|
||||
provider: provider,
|
||||
}
|
||||
);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const domainMapping = new gcp.cloudrun.DomainMapping(
|
||||
"domain-mapping",
|
||||
{
|
||||
name: hostname,
|
||||
location: cloudRunRegion,
|
||||
metadata: {
|
||||
namespace: project,
|
||||
},
|
||||
spec: {
|
||||
routeName: service.name,
|
||||
}
|
||||
},
|
||||
{
|
||||
provider: provider
|
||||
}
|
||||
);
|
||||
|
||||
const zone = gcp.dns.getManagedZoneOutput(
|
||||
{
|
||||
name: managedZone,
|
||||
},
|
||||
{
|
||||
provider: provider,
|
||||
}
|
||||
);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
domainMapping.statuses.apply(
|
||||
ss => ss[0].resourceRecords
|
||||
).apply(
|
||||
rrs => {
|
||||
if (rrs) {
|
||||
|
||||
let mapping : { [k : string] : string[] } = {};
|
||||
|
||||
for(let i = 0; i < rrs.length; i++) {
|
||||
if (rrs[i].rrdata) {
|
||||
|
||||
const rr = rrs[i].rrdata;
|
||||
const tp = rrs[i].type;
|
||||
|
||||
if (!rr || !tp) continue;
|
||||
|
||||
if (mapping[tp])
|
||||
mapping = {
|
||||
...mapping,
|
||||
[tp]: [...mapping[tp], rr],
|
||||
};
|
||||
else
|
||||
mapping = {
|
||||
...mapping,
|
||||
[tp]: [rr],
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for (const tp in mapping) {
|
||||
|
||||
new gcp.dns.RecordSet(
|
||||
"resource-record-" + tp,
|
||||
{
|
||||
name: hostname + ".",
|
||||
managedZone: zone.name,
|
||||
type: tp,
|
||||
ttl: 300,
|
||||
rrdatas: mapping[tp],
|
||||
},
|
||||
{
|
||||
provider: provider,
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const serviceMon = new gcp.monitoring.GenericService(
|
||||
"service-monitoring",
|
||||
{
|
||||
basicService: {
|
||||
serviceLabels: {
|
||||
service_name: service.name,
|
||||
location: cloudRunRegion,
|
||||
},
|
||||
serviceType: "CLOUD_RUN",
|
||||
},
|
||||
displayName: "Config UI service (" + environment + ")",
|
||||
serviceId: "config-ui-service-" + environment + "-mon",
|
||||
userLabels: {
|
||||
"service": service.name,
|
||||
"application": "config-ui",
|
||||
"environment": environment,
|
||||
},
|
||||
},
|
||||
{
|
||||
provider: provider,
|
||||
}
|
||||
);
|
||||
|
||||
new gcp.monitoring.Slo(
|
||||
"latency-slo",
|
||||
{
|
||||
service: serviceMon.serviceId,
|
||||
sloId: "config-ui-service-" + environment + "-latency-slo",
|
||||
displayName: "Config UI latency (" + environment + ")",
|
||||
goal: 0.95,
|
||||
rollingPeriodDays: 5,
|
||||
basicSli: {
|
||||
latency: {
|
||||
threshold: "2s"
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
provider: provider,
|
||||
}
|
||||
);
|
||||
|
||||
new gcp.monitoring.Slo(
|
||||
"availability-slo",
|
||||
{
|
||||
service: serviceMon.serviceId,
|
||||
sloId: "config-ui-service-" + environment + "-availability-slo",
|
||||
displayName: "Config UI availability (" + environment + ")",
|
||||
goal: 0.95,
|
||||
rollingPeriodDays: 5,
|
||||
windowsBasedSli: {
|
||||
windowPeriod: "3600s",
|
||||
goodTotalRatioThreshold: {
|
||||
basicSliPerformance: {
|
||||
availability: {
|
||||
}
|
||||
},
|
||||
threshold: 0.9,
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
provider: provider,
|
||||
}
|
||||
);
|
||||
|
||||
3625
ai-context/workbench-ui/pulumi/package-lock.json
generated
Normal file
3625
ai-context/workbench-ui/pulumi/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
12
ai-context/workbench-ui/pulumi/package.json
Normal file
12
ai-context/workbench-ui/pulumi/package.json
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "safety-ai",
|
||||
"main": "index.ts",
|
||||
"devDependencies": {
|
||||
"@types/node": "^16"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pulumi/command": "^0.7.2",
|
||||
"@pulumi/gcp": "^6.58.0",
|
||||
"@pulumi/pulumi": "^3.0.0"
|
||||
}
|
||||
}
|
||||
18
ai-context/workbench-ui/pulumi/tsconfig.json
Normal file
18
ai-context/workbench-ui/pulumi/tsconfig.json
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"outDir": "bin",
|
||||
"target": "es2016",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"sourceMap": true,
|
||||
"experimentalDecorators": true,
|
||||
"pretty": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noImplicitReturns": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.ts"
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue