Spaces:
Runtime error
Runtime error
root commited on
Commit ·
f74625a
1
Parent(s): c57ecd0
chore(deploy): add Hugging Face Docker configuration and CI/CD pipeline
Browse files- .github/workflows/deploy.yml +20 -0
- Dockerfile +51 -0
- apps/frontend/utils/socket.ts +1 -1
- hf_entrypoint.sh +21 -0
.github/workflows/deploy.yml
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Deploy to Hugging Face Spaces
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches: [ main ]
|
| 6 |
+
|
| 7 |
+
jobs:
|
| 8 |
+
deploy:
|
| 9 |
+
runs-on: ubuntu-latest
|
| 10 |
+
steps:
|
| 11 |
+
- name: Checkout Code
|
| 12 |
+
uses: actions/checkout@v4
|
| 13 |
+
|
| 14 |
+
- name: Build and Push to HF
|
| 15 |
+
env:
|
| 16 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 17 |
+
HF_SPACE: ${{ secrets.HF_SPACE }}
|
| 18 |
+
run: |
|
| 19 |
+
git remote add hf https://root:$HF_TOKEN@huggingface.co/spaces/$HF_SPACE
|
| 20 |
+
git push --force hf main
|
Dockerfile
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# --- 1. ROS 2 HUMBLE BASE ---
|
| 2 |
+
FROM ros:humble-ros-base
|
| 3 |
+
|
| 4 |
+
# Change to root to install dependencies
|
| 5 |
+
USER root
|
| 6 |
+
|
| 7 |
+
# --- 2. INSTALL SYSTEM DEPENDENCIES ---
|
| 8 |
+
# Install Node.js, Bun, and other necessary tools
|
| 9 |
+
RUN apt-get update && apt-get install -y \
|
| 10 |
+
curl \
|
| 11 |
+
gnupg \
|
| 12 |
+
python3-pip \
|
| 13 |
+
unzip \
|
| 14 |
+
&& curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
|
| 15 |
+
&& apt-get install -y nodejs \
|
| 16 |
+
&& curl -fsSL https://bun.sh/install | bash \
|
| 17 |
+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 18 |
+
|
| 19 |
+
# Add Bun to PATH
|
| 20 |
+
ENV PATH="/root/.bun/bin:${PATH}"
|
| 21 |
+
|
| 22 |
+
# --- 3. WORKSPACE SETUP ---
|
| 23 |
+
WORKDIR /app
|
| 24 |
+
|
| 25 |
+
# Copy the entire monorepo
|
| 26 |
+
COPY . .
|
| 27 |
+
|
| 28 |
+
# --- 4. BUILD SHARED PACKAGES ---
|
| 29 |
+
WORKDIR /app/packages/shared-types
|
| 30 |
+
RUN npm install && npm run build
|
| 31 |
+
|
| 32 |
+
# --- 5. BUILD BACKEND ---
|
| 33 |
+
WORKDIR /app/apps/backend
|
| 34 |
+
RUN npm install
|
| 35 |
+
# Fastify needs to listen on port 7860 for Hugging Face Spaces
|
| 36 |
+
RUN sed -i 's/port: 4000/port: 7860/g' src/index.ts
|
| 37 |
+
|
| 38 |
+
# --- 6. BUILD ROS 2 WORKSPACE ---
|
| 39 |
+
WORKDIR /app/robotics/ros2_ws
|
| 40 |
+
RUN /bin/bash -c "source /opt/ros/humble/setup.bash && colcon build --packages-select simulation_manager amr_navigation"
|
| 41 |
+
|
| 42 |
+
# --- 7. FINAL ENTRYPOINT SCRIPT ---
|
| 43 |
+
WORKDIR /app
|
| 44 |
+
COPY hf_entrypoint.sh .
|
| 45 |
+
RUN chmod +x hf_entrypoint.sh
|
| 46 |
+
|
| 47 |
+
# Hugging Face Spaces Port
|
| 48 |
+
EXPOSE 7860
|
| 49 |
+
|
| 50 |
+
# Run the entrypoint
|
| 51 |
+
CMD ["./hf_entrypoint.sh"]
|
apps/frontend/utils/socket.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { io, Socket } from "socket.io-client";
|
|
| 4 |
|
| 5 |
// Singleton Socket Instance
|
| 6 |
// Prevent multiple connections in React Strict Mode or Fast Refresh
|
| 7 |
-
const SOCKET_URL = "http://localhost:4000";
|
| 8 |
|
| 9 |
export const socket: Socket = io(SOCKET_URL, {
|
| 10 |
transports: ["websocket"],
|
|
|
|
| 4 |
|
| 5 |
// Singleton Socket Instance
|
| 6 |
// Prevent multiple connections in React Strict Mode or Fast Refresh
|
| 7 |
+
const SOCKET_URL = process.env.NEXT_PUBLIC_SOCKET_URL || "http://localhost:4000";
|
| 8 |
|
| 9 |
export const socket: Socket = io(SOCKET_URL, {
|
| 10 |
transports: ["websocket"],
|
hf_entrypoint.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
|
| 4 |
+
# 1. Source ROS 2 environments
|
| 5 |
+
source /opt/ros/humble/setup.bash
|
| 6 |
+
source /app/robotics/ros2_ws/install/setup.bash
|
| 7 |
+
|
| 8 |
+
# 2. Start the Mock Robot Simulation in the background
|
| 9 |
+
echo "--- [DEPLOY] Starting Mock Robot Simulation ---"
|
| 10 |
+
ros2 run simulation_manager mock_robot --ros-args -p robot_id:=robot_1 &
|
| 11 |
+
|
| 12 |
+
# 3. Start the Nav2 Stack (Minimal) in the background
|
| 13 |
+
# We run Nav2 in a lighter mode for the free tier
|
| 14 |
+
echo "--- [DEPLOY] Starting Nav2 Stack ---"
|
| 15 |
+
ros2 launch amr_navigation amr_nav.launch.py use_sim_time:=False &
|
| 16 |
+
|
| 17 |
+
# 4. Start the Fastify Gateway (Main Process)
|
| 18 |
+
# This process stays in the foreground to keep the container alive
|
| 19 |
+
echo "--- [DEPLOY] Starting Telemetry Gateway on Port 7860 ---"
|
| 20 |
+
cd /app/apps/backend
|
| 21 |
+
npm run dev
|