Skip to content

Commit 604fd6d

Browse files
authored
Add Docker image build workflow (#3)
* improvement: add Docker image build workflow - Build multi-arch (amd64 + arm64) images on tag push or manual dispatch - Push to ghcr.io/primeintellect-ai/router with multi-arch manifest - Fix Dockerfile to build from local source instead of cloning a fork * bugfix: add missing contents:read permission to manifest job * bugfix: bind to 0.0.0.0 by default, only tag latest on releases - Add CMD with --host 0.0.0.0 --port 8080 so the container is reachable - Only apply the latest Docker tag on version tag pushes, not manual dispatches * bugfix: use nightly Rust toolchain for is_multiple_of support
1 parent 556604a commit 604fd6d

2 files changed

Lines changed: 116 additions & 49 deletions

File tree

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
workflow_dispatch:
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: primeintellect-ai/router
12+
13+
jobs:
14+
build:
15+
strategy:
16+
fail-fast: true
17+
matrix:
18+
include:
19+
- runner: ubuntu-latest
20+
platform: linux/amd64
21+
suffix: amd64
22+
- runner: image-builder-arm-2204
23+
platform: linux/arm64
24+
suffix: arm64
25+
runs-on: ${{ matrix.runner }}
26+
permissions:
27+
contents: read
28+
packages: write
29+
30+
steps:
31+
- name: Checkout repository
32+
uses: actions/checkout@v4
33+
34+
- name: Log in to GitHub Container Registry
35+
uses: docker/login-action@v3
36+
with:
37+
registry: ${{ env.REGISTRY }}
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Set up Docker Buildx
42+
uses: docker/setup-buildx-action@v3
43+
44+
- name: Extract version
45+
id: vars
46+
run: |
47+
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
48+
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
49+
else
50+
echo "version=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
51+
fi
52+
53+
- name: Build and push Docker image
54+
uses: docker/build-push-action@v5
55+
with:
56+
context: .
57+
file: ./Dockerfile.router
58+
push: true
59+
platforms: ${{ matrix.platform }}
60+
tags: |
61+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.version }}-${{ matrix.suffix }}
62+
63+
manifest:
64+
needs: build
65+
runs-on: ubuntu-latest
66+
permissions:
67+
contents: read
68+
packages: write
69+
70+
steps:
71+
- name: Checkout repository
72+
uses: actions/checkout@v4
73+
74+
- name: Log in to GitHub Container Registry
75+
uses: docker/login-action@v3
76+
with:
77+
registry: ${{ env.REGISTRY }}
78+
username: ${{ github.actor }}
79+
password: ${{ secrets.GITHUB_TOKEN }}
80+
81+
- name: Extract version
82+
id: vars
83+
run: |
84+
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
85+
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
86+
else
87+
echo "version=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
88+
fi
89+
90+
- name: Create and push multi-arch manifest
91+
run: |
92+
IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
93+
VERSION="${{ steps.vars.outputs.version }}"
94+
95+
TAGS="-t ${IMAGE}:${VERSION}"
96+
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
97+
TAGS="$TAGS -t ${IMAGE}:latest"
98+
fi
99+
100+
docker buildx imagetools create \
101+
$TAGS \
102+
${IMAGE}:${VERSION}-amd64 \
103+
${IMAGE}:${VERSION}-arm64

Dockerfile.router

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,21 @@
1-
# Dockerfile for vllm-router
2-
FROM rustlang/rust:nightly-bullseye as rust-builder
1+
# Stage 1: Build the vllm-router binary
2+
FROM rust:1.86-bookworm AS builder
33

4-
# Install system dependencies
5-
RUN apt-get update && apt-get install -y \
6-
build-essential \
7-
pkg-config \
8-
libssl-dev \
9-
protobuf-compiler \
10-
&& rm -rf /var/lib/apt/lists/*
4+
RUN apt-get update && apt-get install -y protobuf-compiler && rm -rf /var/lib/apt/lists/*
5+
RUN rustup toolchain install nightly && rustup default nightly
116

12-
# Set working directory
13-
WORKDIR /app
14-
15-
# Copy Rust source files
16-
COPY Cargo.toml Cargo.lock ./
7+
WORKDIR /build
8+
COPY Cargo.toml Cargo.lock build.rs ./
179
COPY src ./src
18-
COPY build.rs ./
19-
20-
# Build the Rust binary
21-
RUN cargo build --release
22-
23-
# Python stage with Rust binary
24-
FROM python:3.12-slim-bullseye
25-
26-
# Install system dependencies
27-
RUN apt-get update && apt upgrade -y && apt-get install -y \
28-
curl \
29-
&& rm -rf /var/lib/apt/lists/*
30-
31-
RUN pip3 install --upgrade pip
32-
33-
# Create app directory
34-
WORKDIR /app
35-
36-
# Copy the Rust binary from builder stage
37-
COPY --from=rust-builder /app/target/release/vllm-router /usr/local/bin/vllm-router
38-
39-
# Make it executable
40-
RUN chmod +x /usr/local/bin/vllm-router
4110

42-
# Copy Python source files for Python launcher (optional)
43-
COPY py_src ./py_src
44-
COPY pyproject.toml ./
45-
COPY README.md ./
11+
RUN cargo build --release --bin vllm-router
4612

47-
# Install Python dependencies if using Python launcher
48-
RUN pip install setuptools-rust wheel build requests
13+
# Stage 2: Minimal runtime image
14+
FROM debian:bookworm-slim
4915

50-
# Expose default router port
51-
EXPOSE 8080
16+
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
5217

53-
# Expose default metrics port
54-
EXPOSE 29000
18+
COPY --from=builder /build/target/release/vllm-router /usr/local/bin/vllm-router
5519

56-
# Default command to run the router using Rust binary directly
57-
CMD ["vllm-router", "--host", "0.0.0.0", "--port", "8080"]
20+
ENTRYPOINT ["vllm-router"]
21+
CMD ["--host", "0.0.0.0", "--port", "8080"]

0 commit comments

Comments
 (0)