Skip to content

Dev -> Prod #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ FROM alpine:3.20 AS build
RUN apk add --update --no-cache --no-progress make g++ gcc linux-headers

RUN apk add --update --no-cache --no-progress python3 py3-pip py3-wheel \
python3-dev
python3-dev git

RUN mkdir /root/wheels

RUN pip wheel -w /root/wheels --no-deps jsonnet

RUN pip wheel -w /root/wheels --no-deps git+https://github.com/trustgraph-ai/trustgraph-templates

COPY config-ui /root/config-ui/

RUN (cd /root/config-ui && pip wheel -w /root/wheels --no-deps .)
Expand All @@ -23,7 +25,8 @@ COPY --from=build /root/wheels /root/wheels
RUN apk add --update --no-cache --no-progress python3 py3-pip \
py3-aiohttp

RUN pip install /root/wheels/* && \
RUN \
pip install /root/wheels/* && \
pip cache purge && \
rm -rf /root/wheels

Expand Down
18 changes: 5 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,7 @@ ui:
cp public/*.png config-ui/config_ui/ui/
cp public/*.svg config-ui/config_ui/ui/

template-data:
rm -rf config-ui/config_ui/templates
mkdir -p config-ui/config_ui/templates
find templates -name '*.jsonnet' | cpio -pdm config-ui/config_ui/

resources-data:
rm -rf config-ui/config_ui/resources
mkdir -p config-ui/config_ui/resources
cp -r grafana config-ui/config_ui/resources/
cp -r prometheus config-ui/config_ui/resources/

service-package: ui template-data resources-data update-package-versions
service-package: ui update-package-versions
cd config-ui && python3 setup.py sdist --dist-dir ../pkgs/

update-package-versions:
Expand All @@ -31,7 +20,10 @@ update-package-versions:
CONTAINER=localhost/config-ui
DOCKER=podman

container:
container: service-package
${DOCKER} build -f Containerfile -t ${CONTAINER}:${VERSION} \
--format docker

# On port 8081
run-container:
${DOCKER} run -i -t -p 8081:8080 ${CONTAINER}:${VERSION}
182 changes: 62 additions & 120 deletions config-ui/config_ui/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import json

from . generator import Generator
from trustgraph_configurator import Index, Packager

import logging
logger = logging.getLogger("api")
Expand All @@ -18,15 +19,55 @@ def __init__(self, **config):
self.port = int(config.get("port", "8080"))
self.app = web.Application(middlewares=[])

self.app.add_routes([web.post("/api/generate", self.generate)])
self.app.add_routes([
web.post("/api/generate/{platform}/{version}", self.generate)
web.post("/api/generate/{platform}/{template}", self.generate)
])
self.app.add_routes([web.get("/{tail:.*}", self.everything)])

self.ui = importlib.resources.files().joinpath("ui")
self.templates = importlib.resources.files().joinpath("templates")
self.resources = importlib.resources.files().joinpath("resources")

self.app.add_routes([
web.get("/api/latest-stable", self.latest_stable),
web.get("/api/latest", self.latest),
web.get("/api/versions", self.versions),
])

self.app.add_routes([web.get("/{tail:.*}", self.everything)])

def latest(self, request):

latest = Index.get_latest()

return web.json_response(
{
"template": latest.name,
"version": latest.version,
}
)

def latest_stable(self, request):

latest = Index.get_latest_stable()

return web.json_response(
{
"template": latest.name,
"version": latest.version,
}
)

def versions(self, request):

versions = Index.get_templates()

return web.json_response([
{
"template": v.name,
"version": v.version,
"description": v.description,
"status": v.status,
}
for v in versions
])

def open(self, path):

Expand Down Expand Up @@ -104,26 +145,6 @@ async def everything(self, request):
logging.error(f"Exception: {e}")
raise web.HTTPInternalServerError()

def process(
self, config, version="0.0.0", platform="docker-compose",
):

config = config.encode("utf-8")

gen = Generator(
config, templates=self.templates, resources=self.resources,
version=version
)

path = self.templates.joinpath(
f"config-to-{platform}.jsonnet"
)
wrapper = path.read_text()

processed = gen.process(wrapper)

return processed

async def generate(self, request):

logger.info("Generate...")
Expand All @@ -134,11 +155,11 @@ async def generate(self, request):
platform = "docker-compose"

try:
version = request.match_info["version"]
template = request.match_info["template"]
except:
version = "0.0.0"
return web.HTTPBadRequest()

logger.info(f"Generating for platform={platform} version={version}")
logger.info(f"Generating for platform={platform} template={template}")

try:

Expand All @@ -156,103 +177,24 @@ async def generate(self, request):

logger.info(f"Config: {config}")


if platform in set(["docker-compose", "podman-compose"]):
return await self.generate_docker_compose(
"docker-compose", version, config
)
elif platform in set([
"minikube-k8s", "gcp-k8s", "eks-k8s", "aks-k8s",
]):
return await self.generate_k8s(
platform, version, config
)
else:
return web.HTTPBadRequest()

except Exception as e:
logging.error(f"Exception: {e}")
return web.HTTPInternalServerError()

async def generate_docker_compose(self, platform, version, config):

processed = self.process(
config, platform=platform, version=version
)

y = yaml.dump(processed)

mem = BytesIO()

with zipfile.ZipFile(mem, mode='w') as out:

def output(name, content):
logger.info(f"Adding {name}...")
out.writestr(name, content)

fname = "docker-compose.yaml"

output(fname, y)

# Grafana config
path = self.resources.joinpath(
"grafana/dashboards/dashboard.json"
pkg = Packager(
version = None, # Use version from template configuration
template = template,
platform = platform,
latest = False,
latest_stable = False
)
res = path.read_text()
output("grafana/dashboards/dashboard.json", res)

path = self.resources.joinpath(
"grafana/provisioning/dashboard.yml"
)
res = path.read_text()
output("grafana/provisioning/dashboard.yml", res)

path = self.resources.joinpath(
"grafana/provisioning/datasource.yml"
)
res = path.read_text()
output("grafana/provisioning/datasource.yml", res)
data = pkg.generate(config)

# Prometheus config
path = self.resources.joinpath(
"prometheus/prometheus.yml"
return web.Response(
body = data,
content_type = "application/octet-stream"
)
res = path.read_text()
output("prometheus/prometheus.yml", res)

logger.info("Generation complete.")

return web.Response(
body=mem.getvalue(),
content_type = "application/octet-stream"
)

async def generate_k8s(self, platform, version, config):

processed = self.process(
config, platform=platform, version=version
)

y = yaml.dump(processed)

mem = BytesIO()

with zipfile.ZipFile(mem, mode='w') as out:

def output(name, content):
logger.info(f"Adding {name}...")
out.writestr(name, content)

fname = "resources.yaml"

output(fname, y)

logger.info("Generation complete.")

return web.Response(
body=mem.getvalue(),
content_type = "application/octet-stream"
)
except Exception as e:
logging.error(f"Exception: {e}")
return web.HTTPInternalServerError()

def run(self):

Expand Down
2 changes: 2 additions & 0 deletions config-ui/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"jsonnet",
"aiohttp",
"pyyaml",
"trustgraph-configurator",
# "trustgraph-configurator @ git+https://github.com/trustgraph-ai/trustgraph-templates",
],
scripts=[
"scripts/service",
Expand Down
5 changes: 5 additions & 0 deletions src/simple-editor/configuration/Configuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
CONFIGURE_EMBEDDINGS,
} from '../state/Options';
import { useDeploymentStore } from '../state/Deployment';
import { useVersionStateStore } from '../state/Version';

import ConfigurePrompts from '../prompts/ConfigurePrompts';
import ConfigureAgents from '../agents/ConfigureAgents';
Expand Down Expand Up @@ -84,6 +85,10 @@ const Configuration: React.FC = () => {
setConfigUrl("");
});

useVersionStateStore.subscribe(() => {
setConfigUrl("");
});

const handleChange = (_event: React.SyntheticEvent, value: string) => {
setValue(value);
};
Expand Down
10 changes: 1 addition & 9 deletions src/simple-editor/configuration/Parameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,20 @@
import { Typography } from '@mui/material';

import ParamsForm from '../model-params/ParamsForm';
import { useConfigurationStateStore } from '../state/Configuration';

const Parameters = ({
}) => {

const version
= useConfigurationStateStore((state) => state.trustgraphVersion);

return (<>

<Typography variant="h5" component="h2" gutterBottom>
TrustGraph Component Options
</Typography>

<Typography variant="body1" component="p" gutterBottom>
Release version: <code>{version}</code>
</Typography>

<Typography variant="body1" component="p" gutterBottom>
For each category, select one option from the list of
available components.
</Typography>
</Typography>

<ParamsForm/>

Expand Down
11 changes: 10 additions & 1 deletion src/simple-editor/deployment/ConfigGeneration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Close } from '@mui/icons-material';

import { generateConfig } from '../generate-config';
import { useConfigurationStateStore } from '../state/Configuration';
import { useVersionStateStore } from '../state/Version';
import { usePromptsStore } from '../state/Prompts';
import { useAgentsStore } from '../state/Agents';
import { useDeploymentStore } from '../state/Deployment';
Expand All @@ -31,6 +32,8 @@ const ConfigGeneration = () => {

const agents = useAgentsStore((state) => state);

const version = useVersionStateStore((state) => state).version;

const options
= useOptionsStore((state) => state);

Expand All @@ -43,10 +46,16 @@ const ConfigGeneration = () => {

const generate = () => {

// Shouldn't happen.
if (!version) {
console.log("Error: Null template selected?!");
return;
}

setGenerating(true);

generateConfig(
configuration, prompts, agents, options,
configuration, version, prompts, agents, options,
).then(
response => {
if (response.ok) {
Expand Down
Loading