Spaces:
Runtime error
Runtime error
root commited on
Commit ·
8957d2b
1
Parent(s): 5453043
perf(deploy): full bun-native optimization and multi-stage container refinement
Browse files- .github/workflows/deploy.yml +9 -1
- Dockerfile +27 -21
- hf_entrypoint.sh +14 -11
- vercel.json +7 -0
.github/workflows/deploy.yml
CHANGED
|
@@ -25,6 +25,14 @@ jobs:
|
|
| 25 |
- name: Checkout Code
|
| 26 |
uses: actions/checkout@v4
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
- name: Deploy to Vercel
|
| 29 |
uses: amondnet/vercel-action@v20
|
| 30 |
with:
|
|
@@ -32,4 +40,4 @@ jobs:
|
|
| 32 |
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
|
| 33 |
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
|
| 34 |
vercel-args: '--prod'
|
| 35 |
-
working-directory: ./
|
|
|
|
| 25 |
- name: Checkout Code
|
| 26 |
uses: actions/checkout@v4
|
| 27 |
|
| 28 |
+
- name: Setup Bun
|
| 29 |
+
uses: oven-sh/setup-bun@v1
|
| 30 |
+
with:
|
| 31 |
+
bun-version: latest
|
| 32 |
+
|
| 33 |
+
- name: Install dependencies (Monorepo)
|
| 34 |
+
run: bun install --frozen-lockfile
|
| 35 |
+
|
| 36 |
- name: Deploy to Vercel
|
| 37 |
uses: amondnet/vercel-action@v20
|
| 38 |
with:
|
|
|
|
| 40 |
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
|
| 41 |
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
|
| 42 |
vercel-args: '--prod'
|
| 43 |
+
working-directory: ./
|
Dockerfile
CHANGED
|
@@ -1,51 +1,57 @@
|
|
| 1 |
-
# --- 1
|
| 2 |
FROM ros:humble-ros-base
|
| 3 |
|
| 4 |
-
# Change to root to install dependencies
|
| 5 |
USER root
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 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 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
COPY . .
|
| 27 |
|
| 28 |
-
#
|
| 29 |
WORKDIR /app/packages/shared-types
|
| 30 |
-
RUN
|
| 31 |
|
| 32 |
-
#
|
| 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 |
-
#
|
| 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 |
-
# ---
|
| 43 |
WORKDIR /app
|
| 44 |
COPY hf_entrypoint.sh .
|
| 45 |
RUN chmod +x hf_entrypoint.sh
|
| 46 |
|
| 47 |
-
#
|
| 48 |
EXPOSE 7860
|
| 49 |
|
| 50 |
-
#
|
|
|
|
|
|
|
|
|
|
| 51 |
CMD ["./hf_entrypoint.sh"]
|
|
|
|
| 1 |
+
# --- STAGE 1: SYSTEM SETUP ---
|
| 2 |
FROM ros:humble-ros-base
|
| 3 |
|
|
|
|
| 4 |
USER root
|
| 5 |
+
ENV PATH="/root/.bun/bin:${PATH}"
|
| 6 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 7 |
|
| 8 |
+
# Install core tools in one layer to reduce size
|
|
|
|
| 9 |
RUN apt-get update && apt-get install -y \
|
| 10 |
curl \
|
| 11 |
gnupg \
|
| 12 |
python3-pip \
|
| 13 |
unzip \
|
|
|
|
|
|
|
| 14 |
&& curl -fsSL https://bun.sh/install | bash \
|
| 15 |
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
WORKDIR /app
|
| 18 |
|
| 19 |
+
# --- STAGE 2: DEPENDENCY CACHING ---
|
| 20 |
+
# Copy ONLY lockfiles and package.json to cache the "bun install" layer
|
| 21 |
+
COPY package.json bun.lock ./
|
| 22 |
+
COPY apps/backend/package.json ./apps/backend/
|
| 23 |
+
COPY apps/frontend/package.json ./apps/frontend/
|
| 24 |
+
COPY packages/shared-types/package.json ./packages/shared-types/
|
| 25 |
+
|
| 26 |
+
# Use BUN for ultra-fast multi-workspace installation
|
| 27 |
+
RUN bun install --frozen-lockfile
|
| 28 |
+
|
| 29 |
+
# --- STAGE 3: BUILD ---
|
| 30 |
+
# Now copy the rest of the source
|
| 31 |
COPY . .
|
| 32 |
|
| 33 |
+
# Build Shared Packages using Bun
|
| 34 |
WORKDIR /app/packages/shared-types
|
| 35 |
+
RUN bun run build
|
| 36 |
|
| 37 |
+
# Prepare Backend (Fix port for HF Spaces)
|
| 38 |
WORKDIR /app/apps/backend
|
|
|
|
|
|
|
| 39 |
RUN sed -i 's/port: 4000/port: 7860/g' src/index.ts
|
| 40 |
|
| 41 |
+
# Build ROS 2 Workspaces
|
| 42 |
WORKDIR /app/robotics/ros2_ws
|
| 43 |
+
RUN /bin/bash -c "source /opt/ros/humble/setup.bash && colcon build --symlink-install --packages-select simulation_manager amr_navigation"
|
| 44 |
|
| 45 |
+
# --- STAGE 4: RUNTIME ---
|
| 46 |
WORKDIR /app
|
| 47 |
COPY hf_entrypoint.sh .
|
| 48 |
RUN chmod +x hf_entrypoint.sh
|
| 49 |
|
| 50 |
+
# Expose HF Spaces default port
|
| 51 |
EXPOSE 7860
|
| 52 |
|
| 53 |
+
# Healthcheck to help HF monitor the space
|
| 54 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
| 55 |
+
CMD curl -f http://localhost:7860/api/robots || exit 1
|
| 56 |
+
|
| 57 |
CMD ["./hf_entrypoint.sh"]
|
hf_entrypoint.sh
CHANGED
|
@@ -2,20 +2,23 @@
|
|
| 2 |
set -e
|
| 3 |
|
| 4 |
# 1. Source ROS 2 environments
|
| 5 |
-
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
ros2 run simulation_manager mock_robot --ros-args -p robot_id:=robot_1 &
|
| 11 |
|
| 12 |
-
# 3. Start the Nav2 Stack (Minimal)
|
| 13 |
-
|
| 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 |
-
#
|
| 19 |
-
echo "--- [DEPLOY] Starting Telemetry Gateway
|
| 20 |
cd /app/apps/backend
|
| 21 |
-
|
|
|
|
|
|
| 2 |
set -e
|
| 3 |
|
| 4 |
# 1. Source ROS 2 environments
|
| 5 |
+
# We use -f to check if the file exists to prevent script crashes in edge cases
|
| 6 |
+
[ -f "/opt/ros/humble/setup.bash" ] && source /opt/ros/humble/setup.bash
|
| 7 |
+
[ -f "/app/robotics/ros2_ws/install/setup.bash" ] && source /app/robotics/ros2_ws/install/setup.bash
|
| 8 |
|
| 9 |
+
echo "--- [SYSTEM] ROS 2 Humble Environment Sourced ---"
|
| 10 |
+
|
| 11 |
+
# 2. Start the Mock Robot Simulation
|
| 12 |
+
echo "--- [DEPLOY] Starting Mock Robot Simulation (robot_1) ---"
|
| 13 |
ros2 run simulation_manager mock_robot --ros-args -p robot_id:=robot_1 &
|
| 14 |
|
| 15 |
+
# 3. Start the Nav2 Stack (Minimal)
|
| 16 |
+
echo "--- [DEPLOY] Starting Nav2 Stack (Navigation Brain) ---"
|
|
|
|
| 17 |
ros2 launch amr_navigation amr_nav.launch.py use_sim_time:=False &
|
| 18 |
|
| 19 |
+
# 4. Start the Fastify Gateway using BUN (Main Process)
|
| 20 |
+
# We use 'bun run dev' which is much faster than node/npm
|
| 21 |
+
echo "--- [DEPLOY] Starting Bun-Native Telemetry Gateway (Port: 7860) ---"
|
| 22 |
cd /app/apps/backend
|
| 23 |
+
# Ensure we are using the Production entrypoint
|
| 24 |
+
exec bun run dev
|
vercel.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"framework": "nextjs",
|
| 3 |
+
"rootDirectory": "apps/frontend",
|
| 4 |
+
"installCommand": "bun install",
|
| 5 |
+
"buildCommand": "next build",
|
| 6 |
+
"outputDirectory": ".next"
|
| 7 |
+
}
|