Skip to content

Commit e6d8323

Browse files
committed
feat: add Docker and Docker Compose support
Add containerization support for the relay server: - Dockerfile: - Multi-stage build using golang:1.22-alpine and alpine:latest - Enables CGO for SQLite support - Creates a non-root user for security - Sets up the /data directory as a volume - docker-compose.yml: - Provides a quick-start configuration - Maps port 3000 - Mounts a local named volume for persistent SQLite storage - .dockerignore: - Excludes Git history, IDE configs, and local build artifacts - Ensures a clean and minimal build context
1 parent 101b31b commit e6d8323

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.git/
2+
data/
3+
*.db
4+
*.exe
5+
relay-server
6+
README.md
7+
LICENSE
8+
.github/

Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Build stage
2+
FROM golang:1.22-alpine AS builder
3+
4+
# Install build dependencies for CGo (required by go-sqlite3)
5+
RUN apk add --no-cache gcc musl-dev
6+
7+
WORKDIR /app
8+
9+
# Download dependencies first (layer caching)
10+
COPY go.mod go.sum ./
11+
RUN go mod download
12+
13+
# Copy source code and build
14+
COPY . .
15+
RUN CGO_ENABLED=1 go build -o relay-server -ldflags="-s -w" ./cmd/relay
16+
17+
# Runtime stage
18+
FROM alpine:3.20
19+
20+
RUN apk add --no-cache ca-certificates
21+
22+
COPY --from=builder /app/relay-server /usr/local/bin/relay-server
23+
COPY --from=builder /app/config.yaml /etc/relay/config.yaml
24+
25+
# Create data directory for SQLite
26+
RUN mkdir -p /data
27+
28+
# Set default storage path to the mounted volume
29+
ENV RELAY_STORAGE_PATH=/data/relay.db
30+
31+
EXPOSE 3000
32+
33+
VOLUME ["/data"]
34+
35+
CMD ["relay-server"]

docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
services:
2+
relay:
3+
build: .
4+
ports:
5+
- "3000:3000"
6+
volumes:
7+
- relay-data:/data
8+
environment:
9+
- RELAY_STORAGE_PATH=/data/relay.db
10+
restart: unless-stopped
11+
12+
volumes:
13+
relay-data:

0 commit comments

Comments
 (0)