Compare commits
8 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
96ad505d48 | ||
|
|
ccb514c7cc | ||
|
|
6fb48f606f | ||
| 4b3ecfb122 | |||
| 6ab09eb94e | |||
| c993b3e048 | |||
|
|
69c4d520a3 | ||
| 1515ee0589 |
7 changed files with 139 additions and 141 deletions
101
.github/workflows/build-and-deploy-fallback.yml
vendored
Normal file
101
.github/workflows/build-and-deploy-fallback.yml
vendored
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
# .github/workflows/build-and-deploy-fallback.yml
|
||||
|
||||
name: Build and Deploy Fallback
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["gemini"]
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
name: Build Images and Deploy to Server
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set repo name to lowercase
|
||||
id: repo_name
|
||||
run: echo "name=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Log in to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Create web-app .env file
|
||||
run: echo 'GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }}' > web-app/.env
|
||||
|
||||
- name: Build and push web-app image 🚀
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: ./web-app
|
||||
push: true
|
||||
tags: ghcr.io/${{ steps.repo_name.outputs.name }}/web-app:${{ github.sha }}
|
||||
cache-from: type=gha,scope=web-app
|
||||
cache-to: type=gha,mode=max,scope=web-app
|
||||
|
||||
- name: Ensure remote deploy directory exists
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.SERVER_HOST }}
|
||||
username: ${{ secrets.SERVER_USERNAME }}
|
||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
script: |
|
||||
mkdir -p /home/github-actions/codered-astra
|
||||
|
||||
- name: Upload compose files to server
|
||||
uses: appleboy/scp-action@v0.1.7
|
||||
with:
|
||||
host: ${{ secrets.SERVER_HOST }}
|
||||
username: ${{ secrets.SERVER_USERNAME }}
|
||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
source: "docker-compose.yml,docker-compose.prod.yml"
|
||||
target: "/home/github-actions/codered-astra/"
|
||||
|
||||
- name: Deploy to server via SSH ☁️
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
env:
|
||||
RUNNER_GH_ACTOR: ${{ github.actor }}
|
||||
RUNNER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
host: ${{ secrets.SERVER_HOST }}
|
||||
username: ${{ secrets.SERVER_USERNAME }}
|
||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
# pass selected env vars to the remote shell so docker login works
|
||||
envs: RUNNER_GITHUB_TOKEN,RUNNER_GH_ACTOR
|
||||
debug: true
|
||||
script: |
|
||||
cd /home/github-actions/codered-astra
|
||||
chmod -R o+rX rust-engine/demo-data
|
||||
# wrapper to support both Docker Compose v2 and legacy v1
|
||||
compose() { docker compose "$@" || docker-compose "$@"; }
|
||||
# Log in to GHCR using the run's GITHUB_TOKEN so compose can pull images.
|
||||
if [ -n "$RUNNER_GITHUB_TOKEN" ] && [ -n "$RUNNER_GH_ACTOR" ]; then
|
||||
echo "$RUNNER_GITHUB_TOKEN" | docker login ghcr.io -u "$RUNNER_GH_ACTOR" --password-stdin || true
|
||||
fi
|
||||
export REPO_NAME_LOWER='${{ steps.repo_name.outputs.name }}'
|
||||
export GEMINI_API_KEY='${{ secrets.GEMINI_API_KEY }}'
|
||||
export MYSQL_DATABASE='${{ secrets.MYSQL_DATABASE }}'
|
||||
export MYSQL_USER='${{ secrets.MYSQL_USER }}'
|
||||
export MYSQL_PASSWORD='${{ secrets.MYSQL_PASSWORD }}'
|
||||
export MYSQL_ROOT_PASSWORD='${{ secrets.MYSQL_ROOT_PASSWORD }}'
|
||||
export IMAGE_TAG=${{ github.sha }}
|
||||
# Stop and remove old containers before pulling new images
|
||||
compose -f docker-compose.prod.yml down
|
||||
# Clear previous logs for a clean deployment log
|
||||
: > ~/astra-logs/astra-errors.log || true
|
||||
compose -f docker-compose.prod.yml pull
|
||||
compose -f docker-compose.prod.yml up -d
|
||||
# Security hygiene: remove GHCR credentials after pulling
|
||||
docker logout ghcr.io || true
|
||||
|
|
@ -1,70 +1,8 @@
|
|||
services:
|
||||
web-app:
|
||||
fallback-web-app:
|
||||
image: ghcr.io/${REPO_NAME_LOWER}/web-app:${IMAGE_TAG}
|
||||
restart: always
|
||||
ports:
|
||||
- "127.0.0.1:3033:3000"
|
||||
- "127.0.0.1:3034:3000"
|
||||
environment:
|
||||
- DATABASE_URL=mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@mysql:3306/${MYSQL_DATABASE}
|
||||
- RUST_ENGINE_URL=http://rust-engine:8000
|
||||
- GEMINI_API_KEY=${GEMINI_API_KEY}
|
||||
depends_on:
|
||||
- mysql
|
||||
- rust-engine
|
||||
|
||||
rust-engine:
|
||||
image: ghcr.io/${REPO_NAME_LOWER}/rust-engine:${IMAGE_TAG}
|
||||
restart: always
|
||||
environment:
|
||||
- DATABASE_URL=mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@mysql:3306/${MYSQL_DATABASE}
|
||||
- ASTRA_STORAGE=/app/storage
|
||||
- DEMO_DATA_DIR=/app/demo-data
|
||||
- QDRANT_URL=http://qdrant:6333
|
||||
- GEMINI_API_KEY=${GEMINI_API_KEY}
|
||||
depends_on:
|
||||
- mysql
|
||||
- qdrant
|
||||
user: "1004"
|
||||
volumes:
|
||||
- ~/astra-logs:/var/log
|
||||
- rust-storage:/app/storage
|
||||
- /var/www/codered-astra/rust-engine/demo-data:/app/demo-data:ro
|
||||
|
||||
mysql:
|
||||
image: mysql:8.0
|
||||
restart: always
|
||||
ports:
|
||||
- "45.43.2.25:3306:3306"
|
||||
environment:
|
||||
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
|
||||
- MYSQL_DATABASE=${MYSQL_DATABASE}
|
||||
- MYSQL_USER=${MYSQL_USER}
|
||||
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
|
||||
volumes:
|
||||
- mysql-data:/var/lib/mysql
|
||||
|
||||
phpmyadmin:
|
||||
image: phpmyadmin/phpmyadmin
|
||||
restart: always
|
||||
ports:
|
||||
- "127.0.0.1:8080:80"
|
||||
environment:
|
||||
- PMA_HOST=mysql
|
||||
depends_on:
|
||||
- mysql
|
||||
|
||||
qdrant:
|
||||
image: qdrant/qdrant:latest
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "127.0.0.1:6333:6333"
|
||||
volumes:
|
||||
- qdrant-data:/qdrant/storage
|
||||
environment:
|
||||
- QDRANT__SERVICE__GRPC_PORT=6334
|
||||
# expose to rust-engine via service name 'qdrant'
|
||||
|
||||
volumes:
|
||||
mysql-data:
|
||||
qdrant-data:
|
||||
rust-storage:
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ function App() {
|
|||
return (
|
||||
<div className="dark min-h-screen bg-gray-950 text-white flex justify-center pt-12">
|
||||
<ChatLayout />
|
||||
<div></div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,20 @@ import React, { useState } from "react";
|
|||
import ChatHeader from "src/components/ui/chat/chat-header";
|
||||
import ChatWindow from "src/components/ui/chat/chat-window";
|
||||
import MessageInput from "src/components/ui/chat/message-input";
|
||||
import { GoogleGenAI } from "@google/genai";
|
||||
|
||||
let userInput = [];
|
||||
|
||||
const ai = new GoogleGenAI({ apiKey: import.meta.env.GEMINI_API_KEY });
|
||||
|
||||
async function AIResponse(userInputArray) {
|
||||
const response = await ai.models.generateContent({
|
||||
model: "gemini-2.5-flash",
|
||||
contents: userInputArray,
|
||||
});
|
||||
|
||||
return response.text;
|
||||
}
|
||||
|
||||
export default function ChatLayout() {
|
||||
const [messages, setMessages] = useState([
|
||||
|
|
@ -11,21 +25,13 @@ export default function ChatLayout() {
|
|||
},
|
||||
]);
|
||||
|
||||
function addMessage(role, content) {
|
||||
const msg = { role, content };
|
||||
setMessages((s) => [...s, msg]);
|
||||
}
|
||||
|
||||
function handleSend(text) {
|
||||
async function handleSend(text) {
|
||||
const userMsg = { role: "user", content: text };
|
||||
userInput.push(text);
|
||||
const res = await AIResponse(userInput);
|
||||
setMessages((s) => [...s, userMsg]);
|
||||
|
||||
// fake assistant reply after short delay
|
||||
setTimeout(() => {
|
||||
setMessages((s) => [
|
||||
...s,
|
||||
{ role: "assistant", content: `You said: ${text}` },
|
||||
]);
|
||||
setMessages((s) => [...s, { role: "assistant", content: res }]);
|
||||
}, 600);
|
||||
}
|
||||
|
||||
|
|
@ -38,11 +44,7 @@ export default function ChatLayout() {
|
|||
<div className="flex flex-col flex-start w-full max-w-3xl gap-4 p-4">
|
||||
<ChatHeader onDeleteAll={handleDeleteAll} />
|
||||
<ChatWindow messages={messages} />
|
||||
<MessageInput
|
||||
onSend={handleSend}
|
||||
onMessage={addMessage}
|
||||
onDeleteAll={handleDeleteAll}
|
||||
/>
|
||||
<MessageInput onSend={handleSend} onDeleteAll={handleDeleteAll} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import DeleteButton from "src/components/ui/button/delete-button";
|
|||
import FileList from "src/components/ui/file/file-list";
|
||||
|
||||
export default function ChatHeader({
|
||||
title = "Schematic Spelunker",
|
||||
title = "Schematic Spelunker",
|
||||
onDeleteAll,
|
||||
}) {
|
||||
const isDebug = useMemo(() => {
|
||||
|
|
@ -20,10 +20,9 @@ export default function ChatHeader({
|
|||
setIngesting(true);
|
||||
const res = await fetch("/api/files/import-demo", { method: "POST" });
|
||||
const json = await res.json().catch(() => ({}));
|
||||
const imported = json.imported ?? "?";
|
||||
const skipped = json.skipped ?? "?";
|
||||
const summary = `Imported: ${imported}, Skipped: ${skipped}`;
|
||||
setToast(json.error ? `${summary} - ${json.error}` : summary);
|
||||
setToast(
|
||||
`Imported: ${json.imported ?? "?"}, Skipped: ${json.skipped ?? "?"}`
|
||||
);
|
||||
setTimeout(() => setToast(""), 4000);
|
||||
} catch (e) {
|
||||
setToast("Import failed");
|
||||
|
|
|
|||
|
|
@ -3,7 +3,11 @@ import DownButton from "src/components/ui/button/down-button";
|
|||
import { motion } from "motion/react";
|
||||
import { BotMessageSquare } from "lucide-react";
|
||||
|
||||
export default function MessageInput({ onSend, onMessage }) {
|
||||
import { GoogleGenAI } from "@google/genai";
|
||||
|
||||
const ai = new GoogleGenAI({ apiKey: import.meta.env.GEMINI_API_KEY });
|
||||
|
||||
export default function MessageInput({ onSend }) {
|
||||
const [text, setText] = useState("");
|
||||
const textareaRef = useRef(null);
|
||||
|
||||
|
|
@ -13,53 +17,10 @@ export default function MessageInput({ onSend, onMessage }) {
|
|||
}, []);
|
||||
|
||||
async function handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
if (!text.trim()) return;
|
||||
|
||||
// send user message locally
|
||||
e.preventDefault();
|
||||
if (text.trim() === "") return;
|
||||
onSend(text.trim());
|
||||
|
||||
// create query on backend
|
||||
try {
|
||||
if (onMessage)
|
||||
onMessage("assistant", "Queued: sending request to server...");
|
||||
const createRes = await fetch(`/api/query/create`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ q: text, top_k: 5 }),
|
||||
});
|
||||
const createJson = await createRes.json();
|
||||
const id = createJson.id;
|
||||
if (!id) throw new Error("no id returned");
|
||||
|
||||
// poll status
|
||||
let status = "Queued";
|
||||
if (onMessage) onMessage("assistant", `Status: ${status}`);
|
||||
while (status !== "Completed" && status !== "Failed") {
|
||||
await new Promise((r) => setTimeout(r, 1000));
|
||||
const sRes = await fetch(`/api/query/status?id=${id}`);
|
||||
const sJson = await sRes.json();
|
||||
status = sJson.status;
|
||||
if (onMessage) onMessage("assistant", `Status: ${status}`);
|
||||
if (status === "Cancelled") break;
|
||||
}
|
||||
|
||||
if (status === "Completed") {
|
||||
const resultRes = await fetch(`/api/query/result?id=${id}`);
|
||||
const resultJson = await resultRes.json();
|
||||
const final =
|
||||
resultJson?.result?.final_answer ||
|
||||
JSON.stringify(resultJson?.result || {});
|
||||
if (onMessage) onMessage("assistant", final);
|
||||
} else {
|
||||
if (onMessage)
|
||||
onMessage("assistant", `Query status ended as: ${status}`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
if (onMessage) onMessage("assistant", `Error: ${err.message}`);
|
||||
}
|
||||
|
||||
setText("");
|
||||
}
|
||||
|
||||
|
|
@ -67,9 +28,12 @@ export default function MessageInput({ onSend, onMessage }) {
|
|||
<div className="w-full flex justify-center">
|
||||
<footer className="fixed bottom-6 max-w-3xl w-full px-4">
|
||||
<div className="flex flex-col gap-4">
|
||||
<div>
|
||||
<DownButton></DownButton>
|
||||
<div className="flex justify-between items-center">
|
||||
<div className="flex items-center gap-2">
|
||||
<DownButton />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form
|
||||
onSubmit={handleSubmit}
|
||||
className="bg-gray-900 rounded-2xl border-2 border-gray-800 shadow-lg shadow-indigo-600"
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
import { StrictMode } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import "./index.css";
|
||||
import App from "./app/index.jsx";
|
||||
|
||||
createRoot(document.getElementById("root")).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>
|
||||
);
|
||||
createRoot(document.getElementById("root")).render(<App />);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue