Skip to content

Commit a8d1a3d

Browse files
committed
Adds Dashboard
1 parent b635994 commit a8d1a3d

Some content is hidden

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

59 files changed

+14139
-74
lines changed

Diff for: .github/workflows/fly-deploy.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/
2+
3+
name: Fly Deploy
4+
on:
5+
push:
6+
branches:
7+
- main
8+
jobs:
9+
deploy:
10+
name: Deploy app
11+
runs-on: ubuntu-latest
12+
concurrency: deploy-group # optional: ensure only one action runs at a time
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: superfly/flyctl-actions/setup-flyctl@master
16+
- run: flyctl deploy --remote-only
17+
env:
18+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

Diff for: Dockerfile.fly

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Use a single base image with Python 3.11
2+
FROM python:3.11-slim
3+
4+
# Install required packages
5+
RUN apt-get update && \
6+
apt-get install -y --no-install-recommends \
7+
curl \
8+
ca-certificates \
9+
unzip && \
10+
rm -rf /var/lib/apt/lists/*
11+
12+
# Install Deno
13+
RUN curl -fsSL https://deno.land/install.sh | DENO_INSTALL=/usr/local sh
14+
15+
# Install Poetry
16+
RUN curl -sSL https://install.python-poetry.org | python3 - && \
17+
ln -s /root/.local/bin/poetry /usr/local/bin/poetry
18+
19+
# Set environment variables
20+
ENV POETRY_VERSION=1.4.0
21+
ENV POETRY_VIRTUALENVS_CREATE=false
22+
ENV PYTHONUNBUFFERED=1
23+
ENV DENO_INSTALL="/usr/local"
24+
ENV PATH="${DENO_INSTALL}/bin:${PATH}"
25+
26+
# Copy placer-service code and install dependencies
27+
WORKDIR /app/placer-service
28+
COPY placer-service/ ./
29+
RUN poetry install --no-dev --no-interaction --no-ansi
30+
31+
# Copy placer-dashboard code
32+
WORKDIR /app/placer-dashboard
33+
COPY placer-dashboard/ ./
34+
RUN deno install --allow-scripts
35+
RUN deno task build
36+
37+
# Copy the entrypoint script and make it executable
38+
COPY entrypoint.fly.sh /entrypoint.fly.sh
39+
RUN chmod +x /entrypoint.fly.sh
40+
41+
# Set the entrypoint
42+
ENTRYPOINT ["/bin/sh", "/entrypoint.fly.sh"]

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ You can run this multiple times to see the **adaptive thresholds** in action.
3030

3131
- [Fly Auto-Placer](#fly-auto-placer)
3232
- [How to use this service](#how-to-use-this-service)
33-
- [In another terminal](#in-another-terminal)
33+
- [In another terminal](#in-another-terminal)
3434
- [Table of Contents](#table-of-contents)
3535
- [Placement Logic](#placement-logic)
3636
- [Run in Docker](#run-in-docker)
@@ -196,7 +196,7 @@ Currently only works in dry-run mode. Won't make any changes to your Fly.io appl
196196

197197
2. **Monitor Logs**:
198198

199-
Logs are stored in the `logs/auto_placer.log` file for detailed information.
199+
Logs are stored in the `data/logs/auto_placer.log` file for detailed information.
200200

201201
3. **View Current Deployments**:
202202

Diff for: biome.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"linter": {
3-
"ignore": ["dashboard/**"]
3+
"ignore": ["placer-dashboard/**"]
44
}
55
}

Diff for: docker-compose.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
services:
2+
dashboard:
3+
build:
4+
context: ./placer-dashboard
5+
dockerfile: Dockerfile
6+
ports:
7+
- "8080:8080"
8+
env_file:
9+
- ./placer-dashboard/.env
10+
depends_on:
11+
- placer-service
12+
13+
placer-service:
14+
build:
15+
context: ./placer-service
16+
dockerfile: Dockerfile
17+
ports:
18+
- "8000:8000"
19+
env_file:
20+
- ./placer-service/.env
21+
volumes:
22+
- ./placer-service/data:/app/data
23+
24+
volumes:
25+
placer-service-data:
26+
placer-service-logs:
27+

Diff for: entrypoint.fly.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
#!/bin/bash
3+
4+
if [ "$1" = "dashboard" ]; then
5+
echo "Starting Dashboard..."
6+
cd /app/placer-dashboard
7+
deno task start
8+
9+
elif [ "$1" = "placer" ]; then
10+
echo "Starting Placer Service..."
11+
# Create logs directory if it doesn't exist
12+
mkdir -p /app/placer-service/data/logs
13+
14+
cd /app/placer-service
15+
poetry run python3 main.py
16+
17+
else
18+
echo "Unknown process group: $1"
19+
exit 1
20+
fi

Diff for: fly.toml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
app = "fly-auto-placer"
2+
primary_region = "sea"
3+
4+
[build]
5+
dockerfile = "Dockerfile.fly"
6+
7+
[env]
8+
PLACER_SERVICE_URL = "http://placer.internal:8080"
9+
10+
[processes]
11+
dashboard = "dashboard"
12+
placer = "placer"
13+
14+
[http_service]
15+
processes = ["dashboard"]
16+
internal_port = 8080
17+
force_https = true
18+
auto_stop_machines = "stop"
19+
auto_start_machines = true
20+
min_machines_running = 0
21+
[http_service.concurrency]
22+
type = "requests"
23+
soft_limit = 200
24+
hard_limit = 250
25+
26+
# VM configurations for each process
27+
[process_groups.dashboard]
28+
cpu_kind = "shared"
29+
cpus = 1
30+
31+
[process_groups.placer]
32+
cpu_kind = "shared"
33+
cpus = 1
34+
35+
[[mounts]]
36+
source = "placer_service_data"
37+
destination = "/app/placer-service/data"
38+
processes = ["placer"]

Diff for: placer-dashboard/.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fly.toml
File renamed without changes.

Diff for: placer-dashboard/Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM denoland/deno:2.0.0
2+
3+
WORKDIR /app
4+
5+
COPY . .
6+
7+
RUN deno install --allow-scripts
8+
RUN deno task build
9+
10+
EXPOSE 8080
11+
12+
USER deno
13+
CMD ["deno", "task", "start"]
14+
15+
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: dashboard/app/root.tsx renamed to placer-dashboard/app/root.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import type { LinksFunction } from "@remix-run/node";
12
import {
23
Links,
34
Meta,
45
Outlet,
56
Scripts,
67
ScrollRestoration,
78
} from "@remix-run/react";
8-
import type { LinksFunction } from "@remix-run/node";
99

1010
import "./tailwind.css";
1111

Diff for: dashboard/app/routes/_index.tsx renamed to placer-dashboard/app/routes/_index.tsx

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import type { MetaFunction } from "@remix-run/node";
1+
import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
2+
import { json } from "@remix-run/node";
3+
import { useLoaderData } from "@remix-run/react";
24

35
export const meta: MetaFunction = () => {
46
return [
@@ -7,7 +9,16 @@ export const meta: MetaFunction = () => {
79
];
810
};
911

12+
export async function loader({}: LoaderFunctionArgs) {
13+
const placerServiceUrl = "http://fly-auto-placer.internal:8000";
14+
const response = await fetch(placerServiceUrl);
15+
const data = await response.json();
16+
17+
return json(data);
18+
}
19+
1020
export default function Index() {
21+
const data = useLoaderData<typeof loader>();
1122
return (
1223
<div className="flex h-screen items-center justify-center">
1324
<div className="flex flex-col items-center gap-16">
@@ -30,7 +41,7 @@ export default function Index() {
3041
</header>
3142
<nav className="flex flex-col items-center justify-center gap-4 rounded-3xl border border-gray-200 p-6 dark:border-gray-700">
3243
<p className="leading-6 text-gray-700 dark:text-gray-200">
33-
What&apos;s next?
44+
{JSON.stringify(data)}
3445
</p>
3546
<ul>
3647
{resources.map(({ href, text, icon }) => (
File renamed without changes.

Diff for: dashboard/deno.json renamed to placer-dashboard/deno.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"build": "deno run -A npm:@remix-run/dev vite:build",
44
"dev": "deno run -A npm:@remix-run/dev vite:dev",
55
"lint": "deno lint",
6-
"start": "deno serve -A --port 8080 --parallel ./server.ts",
6+
"start": "deno serve -A --port 8080 ./server.ts",
77
"typecheck": "deno check '**/*'",
88
"typegen": "deno types > ./app/deno.d.ts"
99
},

Diff for: placer-dashboard/fly.toml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# fly.toml app configuration file generated for placer-dashboard on 2024-10-14T11:42:37-07:00
2+
#
3+
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
4+
#
5+
app = 'placer-dashboard'
6+
primary_region = 'sea'
7+
8+
[http_service]
9+
internal_port = 8080
10+
force_https = true
11+
auto_stop_machines = 'stop'
12+
auto_start_machines = true
13+
min_machines_running = 0
14+
processes = ['app']
15+
16+
[[vm]]
17+
memory = '1gb'
18+
cpu_kind = 'shared'
19+
cpus = 1
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: dashboard/server.ts renamed to placer-dashboard/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { createRequestHandler } from "@remix-run/server-runtime";
21
import type { ServerBuild } from "@remix-run/server-runtime";
2+
import { createRequestHandler } from "@remix-run/server-runtime";
33
import { serveFile } from "@std/http/file-server";
44
import { join } from "@std/path/join";
55

File renamed without changes.
File renamed without changes.

Diff for: Dockerfile renamed to placer-service/Dockerfile

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ COPY config/ config/
3333
# Copy other files we need
3434
COPY scripts/ scripts/
3535
COPY data/ data/
36-
COPY README.md .
3736

3837
# Copy the main entry point
3938
COPY main.py .

Diff for: automation/auto_placer.py renamed to placer-service/automation/auto_placer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
# Create file handler
3737
file_handler = RotatingFileHandler(
38-
'logs/auto_placer.log',
38+
'data/logs/auto_placer.log',
3939
maxBytes=1024 * 1024, # 1 MB
4040
backupCount=5
4141
)
File renamed without changes.

0 commit comments

Comments
 (0)