Skip to content

Commit

Permalink
Adds Dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
10thfloor committed Oct 15, 2024
1 parent b635994 commit a8d1a3d
Show file tree
Hide file tree
Showing 59 changed files with 14,139 additions and 74 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/

name: Fly Deploy
on:
push:
branches:
- main
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
concurrency: deploy-group # optional: ensure only one action runs at a time
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
42 changes: 42 additions & 0 deletions Dockerfile.fly
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Use a single base image with Python 3.11
FROM python:3.11-slim

# Install required packages
RUN apt-get update && \
apt-get install -y --no-install-recommends \
curl \
ca-certificates \
unzip && \
rm -rf /var/lib/apt/lists/*

# Install Deno
RUN curl -fsSL https://deno.land/install.sh | DENO_INSTALL=/usr/local sh

# Install Poetry
RUN curl -sSL https://install.python-poetry.org | python3 - && \
ln -s /root/.local/bin/poetry /usr/local/bin/poetry

# Set environment variables
ENV POETRY_VERSION=1.4.0
ENV POETRY_VIRTUALENVS_CREATE=false
ENV PYTHONUNBUFFERED=1
ENV DENO_INSTALL="/usr/local"
ENV PATH="${DENO_INSTALL}/bin:${PATH}"

# Copy placer-service code and install dependencies
WORKDIR /app/placer-service
COPY placer-service/ ./
RUN poetry install --no-dev --no-interaction --no-ansi

# Copy placer-dashboard code
WORKDIR /app/placer-dashboard
COPY placer-dashboard/ ./
RUN deno install --allow-scripts
RUN deno task build

# Copy the entrypoint script and make it executable
COPY entrypoint.fly.sh /entrypoint.fly.sh
RUN chmod +x /entrypoint.fly.sh

# Set the entrypoint
ENTRYPOINT ["/bin/sh", "/entrypoint.fly.sh"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ You can run this multiple times to see the **adaptive thresholds** in action.

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

2. **Monitor Logs**:

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

3. **View Current Deployments**:

Expand Down
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"linter": {
"ignore": ["dashboard/**"]
"ignore": ["placer-dashboard/**"]
}
}
27 changes: 27 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
services:
dashboard:
build:
context: ./placer-dashboard
dockerfile: Dockerfile
ports:
- "8080:8080"
env_file:
- ./placer-dashboard/.env
depends_on:
- placer-service

placer-service:
build:
context: ./placer-service
dockerfile: Dockerfile
ports:
- "8000:8000"
env_file:
- ./placer-service/.env
volumes:
- ./placer-service/data:/app/data

volumes:
placer-service-data:
placer-service-logs:

20 changes: 20 additions & 0 deletions entrypoint.fly.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

#!/bin/bash

if [ "$1" = "dashboard" ]; then
echo "Starting Dashboard..."
cd /app/placer-dashboard
deno task start

elif [ "$1" = "placer" ]; then
echo "Starting Placer Service..."
# Create logs directory if it doesn't exist
mkdir -p /app/placer-service/data/logs

cd /app/placer-service
poetry run python3 main.py

else
echo "Unknown process group: $1"
exit 1
fi
38 changes: 38 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
app = "fly-auto-placer"
primary_region = "sea"

[build]
dockerfile = "Dockerfile.fly"

[env]
PLACER_SERVICE_URL = "http://placer.internal:8080"

[processes]
dashboard = "dashboard"
placer = "placer"

[http_service]
processes = ["dashboard"]
internal_port = 8080
force_https = true
auto_stop_machines = "stop"
auto_start_machines = true
min_machines_running = 0
[http_service.concurrency]
type = "requests"
soft_limit = 200
hard_limit = 250

# VM configurations for each process
[process_groups.dashboard]
cpu_kind = "shared"
cpus = 1

[process_groups.placer]
cpu_kind = "shared"
cpus = 1

[[mounts]]
source = "placer_service_data"
destination = "/app/placer-service/data"
processes = ["placer"]
1 change: 1 addition & 0 deletions placer-dashboard/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fly.toml
File renamed without changes.
15 changes: 15 additions & 0 deletions placer-dashboard/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM denoland/deno:2.0.0

WORKDIR /app

COPY . .

RUN deno install --allow-scripts
RUN deno task build

EXPOSE 8080

USER deno
CMD ["deno", "task", "start"]


File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion dashboard/app/root.tsx → placer-dashboard/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { LinksFunction } from "@remix-run/node";
import {
Links,
Meta,
Outlet,
Scripts,
ScrollRestoration,
} from "@remix-run/react";
import type { LinksFunction } from "@remix-run/node";

import "./tailwind.css";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { MetaFunction } from "@remix-run/node";
import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
import { json } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";

export const meta: MetaFunction = () => {
return [
Expand All @@ -7,7 +9,16 @@ export const meta: MetaFunction = () => {
];
};

export async function loader({}: LoaderFunctionArgs) {
const placerServiceUrl = "http://fly-auto-placer.internal:8000";
const response = await fetch(placerServiceUrl);
const data = await response.json();

return json(data);
}

export default function Index() {
const data = useLoaderData<typeof loader>();
return (
<div className="flex h-screen items-center justify-center">
<div className="flex flex-col items-center gap-16">
Expand All @@ -30,7 +41,7 @@ export default function Index() {
</header>
<nav className="flex flex-col items-center justify-center gap-4 rounded-3xl border border-gray-200 p-6 dark:border-gray-700">
<p className="leading-6 text-gray-700 dark:text-gray-200">
What&apos;s next?
{JSON.stringify(data)}
</p>
<ul>
{resources.map(({ href, text, icon }) => (
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion dashboard/deno.json → placer-dashboard/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"build": "deno run -A npm:@remix-run/dev vite:build",
"dev": "deno run -A npm:@remix-run/dev vite:dev",
"lint": "deno lint",
"start": "deno serve -A --port 8080 --parallel ./server.ts",
"start": "deno serve -A --port 8080 ./server.ts",
"typecheck": "deno check '**/*'",
"typegen": "deno types > ./app/deno.d.ts"
},
Expand Down
19 changes: 19 additions & 0 deletions placer-dashboard/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# fly.toml app configuration file generated for placer-dashboard on 2024-10-14T11:42:37-07:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
app = 'placer-dashboard'
primary_region = 'sea'

[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
processes = ['app']

[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion dashboard/server.ts → placer-dashboard/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createRequestHandler } from "@remix-run/server-runtime";
import type { ServerBuild } from "@remix-run/server-runtime";
import { createRequestHandler } from "@remix-run/server-runtime";
import { serveFile } from "@std/http/file-server";
import { join } from "@std/path/join";

Expand Down
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion Dockerfile → placer-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ COPY config/ config/
# Copy other files we need
COPY scripts/ scripts/
COPY data/ data/
COPY README.md .

# Copy the main entry point
COPY main.py .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

# Create file handler
file_handler = RotatingFileHandler(
'logs/auto_placer.log',
'data/logs/auto_placer.log',
maxBytes=1024 * 1024, # 1 MB
backupCount=5
)
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit a8d1a3d

Please sign in to comment.