Skip to content

Commit

Permalink
feat: add Docker configuration and GitHub workflow
Browse files Browse the repository at this point in the history
Adds:
- Dockerfile with multi-stage build and health checks
- docker-compose.yml with Prometheus integration
- GitHub Container Registry workflow
- Example config file
- Updated documentation
  • Loading branch information
teilomillet committed Dec 20, 2024
1 parent 5f23f1d commit 1eb7fa3
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 5 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Docker Build and Publish

on:
push:
tags:
- 'v*'
branches:
- main
pull_request:
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=
type=ref,event=branch
type=ref,event=pr
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ go.work.sum

# env file
.env

# Config files
config.yaml

hapax
52 changes: 52 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Build stage
FROM golang:1.22-alpine AS builder

# Install build dependencies
RUN apk add --no-cache git gcc musl-dev

# Set working directory
WORKDIR /app

# Copy go mod and sum files
COPY go.mod go.sum ./

# Download dependencies
RUN go mod download

# Copy source code
COPY . .

# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -o hapax ./cmd/hapax

# Final stage
FROM alpine:3.19

# Add non-root user
RUN adduser -D -g '' hapax

# Install runtime dependencies
RUN apk add --no-cache ca-certificates tzdata curl

# Set working directory
WORKDIR /app

# Copy binary from builder
COPY --from=builder /app/hapax .

# Copy default config file
COPY config.yaml ./config.yaml

# Use non-root user
USER hapax

# Expose ports
EXPOSE 8080

# Set healthcheck that waits for initial startup
HEALTHCHECK --interval=10s --timeout=5s --start-period=10s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1

# Run the application
ENTRYPOINT ["./hapax"]
CMD ["--config", "config.yaml"]
41 changes: 36 additions & 5 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,43 @@ Focus: Build a reliable, production-ready gateway server leveraging gollm's capa
- Error rate monitoring

## Phase 2: Production Readiness
Focus: Enhance reliability, scalability, and deployability for production environments.

### 2.1 Deployment & Containerization (High Priority)
- [x] Prometheus metrics integration
- Load balancing
- Circuit breakers
- Request queueing
- Configuration hot reload
- Docker support
- Request metrics
- Latency tracking
- Error monitoring
- Resource utilization
- [ ] Docker support
- Multi-stage build optimization
- Production-ready Dockerfile
- Docker Compose configuration
- Container health checks

### 2.2 Reliability & Scalability (Medium Priority)
- [ ] Circuit breakers
- Failure threshold configuration
- Half-open state management
- Automatic recovery
- Circuit state metrics
- [ ] Load balancing
- Weighted round-robin strategy
- Provider health awareness
- Dynamic provider selection
- Load distribution metrics

### 2.3 Performance & Operations (Lower Priority)
- [ ] Request queueing
- Queue size configuration
- Priority queuing support
- Queue metrics monitoring
- Backpressure handling
- [ ] Configuration hot reload
- File system monitoring
- Graceful config updates
- Zero-downtime reloading
- Config validation

## Phase 3: Enterprise Features
- Role-based access control
Expand Down
16 changes: 16 additions & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
server:
port: 8080
read_timeout: 30s
write_timeout: 30s

llm:
provider: "ollama" # Change to your preferred provider (ollama, openai, etc.)
model: "llama2" # Change to your preferred model
endpoint: "" # Set your provider's endpoint if needed

logging:
level: "info"
format: "json"

metrics:
enabled: true
34 changes: 34 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: '3.8'

services:
hapax:
build: .
ports:
- "8080:8080"
volumes:
- ./config.yaml:/app/config.yaml
environment:
- TZ=UTC
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8080/health"]
interval: 30s
timeout: 3s
retries: 3
networks:
- hapax-net

prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
depends_on:
- hapax
networks:
- hapax-net

networks:
hapax-net:
driver: bridge
9 changes: 9 additions & 0 deletions prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
global:
scrape_interval: 15s
evaluation_interval: 15s

scrape_configs:
- job_name: 'hapax'
static_configs:
- targets: ['hapax:8080']
metrics_path: '/metrics'

0 comments on commit 1eb7fa3

Please sign in to comment.