Skip to content

Commit

Permalink
feat: builds for multiple architectures
Browse files Browse the repository at this point in the history
  • Loading branch information
tedostrem committed Nov 6, 2024
1 parent 3dd1afa commit 3f19c09
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ env:
REGISTRY: docker.io
RUSTYGATE_IMAGE: 3loc/rustygate
TESTS_IMAGE: 3loc/rustygate-tests
PLATFORMS: linux/amd64,linux/arm64

jobs:
build:
Expand Down Expand Up @@ -63,6 +64,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ env.PLATFORMS }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-rustygate.outputs.tags }}
labels: ${{ steps.meta-rustygate.outputs.labels }}
Expand All @@ -73,6 +75,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ env.PLATFORMS }}
file: tests/python/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-tests.outputs.tags }}
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.76-alpine AS builder
FROM --platform=$BUILDPLATFORM rust:1.76-alpine AS builder

# Install build dependencies
RUN apk add --no-cache \
Expand All @@ -19,7 +19,7 @@ RUN OPENSSL_STATIC=1 cargo build --release && \
# The binary is named "main" because it's in src/bin/main.rs
RUN mv target/release/main /usr/local/bin/rustygate

FROM alpine:3.19
FROM --platform=$TARGETPLATFORM alpine:3.19

# Install runtime dependencies
RUN apk add --no-cache ca-certificates curl
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- **Request Forwarding**: Asynchronously forwards requests to OpenAI's API.
- **Streaming**: Handles Server-Sent Events (SSE) streaming responses from OpenAI.
- **Rate Limiting**: Configurable rate limiting using leaky bucket algorithm.
- **Multi-architecture Support**: Docker images available for AMD64 and ARM64 architectures.

## Requirements
- **Docker and Docker Compose** (recommended) or **Rust**
Expand Down
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ services:
build:
context: .
dockerfile: Dockerfile
platforms:
- "linux/amd64"
- "linux/arm64"
image: 3loc/rustygate
ports:
- "${PORT:-8080}:8080"
Expand All @@ -28,6 +31,9 @@ services:
build:
context: .
dockerfile: tests/python/Dockerfile
platforms:
- "linux/amd64"
- "linux/arm64"
image: 3loc/rustygate-test
environment:
- RUSTYGATE_URL=http://rustygate:8080
Expand Down
17 changes: 12 additions & 5 deletions tests/python/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
FROM python:3.11-alpine
# Builder stage
FROM --platform=$BUILDPLATFORM python:3.11-alpine AS builder

WORKDIR /tests
WORKDIR /build

# Install build dependencies for pytest and aiohttp
# Install build dependencies
RUN apk add --no-cache gcc musl-dev python3-dev

COPY tests/python/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --no-cache-dir -r requirements.txt --target /install

# Final stage
FROM --platform=$TARGETPLATFORM python:3.11-alpine

WORKDIR /tests

# Copy only the installed packages and test files
COPY --from=builder /install /usr/local/lib/python3.11/site-packages/
COPY tests/python .

# Use pytest-asyncio to run async tests
CMD ["python", "-m", "pytest", "test_rustygate.py", "-v", "--asyncio-mode=auto"]

0 comments on commit 3f19c09

Please sign in to comment.