Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/publish-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Publish Backend Container

on:
push:
branches: [ "main" ]
paths:
- 'backend/**'
- '.github/workflows/publish-backend.yml'
workflow_dispatch:

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: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=sha,format=short

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./backend
file: ./backend/Dockerfile_build_and_publish
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

40 changes: 40 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Git files
.git
.gitignore
.github

# Build artifacts
target/

# Documentation
*.md
README*
CHANGELOG*

# Docker files
.dockerignore
Dockerfile*
docker-compose*

# IDE and editor files
.vscode
.idea
*.iml
.DS_Store
*.swp
*.swo
*~

# Environment files
.env
.env.local
.env.*.local

# Test and coverage
*.test
coverage/
.nyc_output

# Logs
*.log
logs/
31 changes: 31 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM rust:1.91-slim

# Install build dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
gcc \
g++ \
cmake \
pkg-config \
libssl-dev \
libclang-dev \
libzstd-dev \
libhugetlbfs-dev \
&& rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /usr/src/app

# Copy all source files
COPY . .

# Build the binary
RUN cargo build --release --bin backend

# Expose WebSocket port
EXPOSE 8443

# Set entrypoint with default server address for container
ENTRYPOINT ["cargo", "run", "--release", "--bin", "backend", "--"]
CMD ["--server-addr", "0.0.0.0:8443"]
50 changes: 50 additions & 0 deletions backend/Dockerfile_build_and_publish
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Builder stage
FROM rust:1.91-slim AS builder

# Install build dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
gcc \
g++ \
cmake \
pkg-config \
libssl-dev \
libclang-dev \
libzstd-dev \
libhugetlbfs-dev \
&& rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /usr/src/app

# Copy all source files
COPY . .

# Build the binary
RUN cargo build --release --bin backend

# Runtime stage
FROM debian:bookworm-slim AS runtime

# Install runtime dependencies
RUN apt-get update && apt-get install -y \
libssl3 \
libzstd1 \
libhugetlbfs0 \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /usr/src/app

# Copy the compiled binary from the builder stage
COPY --from=builder /usr/src/app/target/release/backend /usr/local/bin/backend

# Expose WebSocket port
EXPOSE 8443

# Set entrypoint
ENTRYPOINT ["backend"]
CMD ["--server-addr", "0.0.0.0:8443"]

27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3.9'

services:
backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: backend
network_mode: host
environment:
- RUST_LOG=info
volumes:
# Mount the Monad event ring (read-only)
# Note: Update the host path if your event ring is located elsewhere
- /var/lib/hugetlbfs/user/monad/pagesize-2MB/event-rings:/var/lib/hugetlbfs/user/monad/pagesize-2MB/event-rings:ro
# Optional: Persistent logs volume
- logs:/var/log/eventwatch
restart: unless-stopped
command: ["--server-addr", "0.0.0.0:8443"]
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"

volumes:
logs: