Skip to content

Commit e355bd4

Browse files
committed
Add Docker support with Dockerfile and Compose
Introduces .dockerignore, Dockerfile, and docker-compose.yml to enable containerized builds and deployment for the project. The Dockerfile builds the Rust application and sets up a secure runtime environment, while docker-compose.yml configures service parameters, environment variables, volumes, and resource limits for local development and deployment.
1 parent fd3073d commit e355bd4

3 files changed

Lines changed: 86 additions & 0 deletions

File tree

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
target/
2+
.git/
3+
.env
4+
.DS_Store

Dockerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
FROM docker.io/library/rust:1.85-slim-bookworm AS builder
2+
3+
WORKDIR /usr/src/app
4+
5+
RUN apt-get update && apt-get install -y \
6+
pkg-config \
7+
libssl-dev \
8+
gcc \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
# Cache dependencies by building a dummy project first
12+
COPY Cargo.toml Cargo.lock ./
13+
RUN mkdir src && \
14+
echo "fn main() {}" > src/main.rs && \
15+
mkdir -p src/bin && \
16+
echo "fn main() {}" > src/bin/seed.rs && \
17+
echo "fn main() {}" > src/bin/compress.rs && \
18+
cargo build --release && \
19+
rm -rf src
20+
21+
COPY . .
22+
23+
RUN cargo build --release
24+
25+
FROM docker.io/library/debian:bookworm-slim
26+
27+
WORKDIR /app
28+
29+
RUN apt-get update && apt-get install -y \
30+
ca-certificates \
31+
libssl3 \
32+
sqlite3 \
33+
&& rm -rf /var/lib/apt/lists/*
34+
35+
COPY --from=builder /usr/src/app/target/release/tulpar-api /usr/local/bin/
36+
COPY --from=builder /usr/src/app/target/release/seed /usr/local/bin/
37+
COPY --from=builder /usr/src/app/target/release/compress /usr/local/bin/
38+
39+
# Create non-root user (UID 10001) for rootless Podman compatibility
40+
RUN useradd -r -u 10001 -g root tulpar && \
41+
mkdir -p /app/data /app/storage && \
42+
chown -R tulpar:root /app
43+
44+
ENV RUST_LOG=info \
45+
DATABASE_URL=sqlite:/app/data/data.db \
46+
STORAGE_PATH=/app/storage
47+
48+
USER tulpar
49+
50+
EXPOSE 3000
51+
52+
CMD ["tulpar-api"]

docker-compose.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
services:
2+
api:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
image: tulpar-api:latest
7+
container_name: tulpar_api
8+
restart: always
9+
ports:
10+
# Bind to localhost ONLY (security requirement)
11+
- "127.0.0.1:3000:3000"
12+
env_file:
13+
- .env
14+
environment:
15+
- DATABASE_URL=sqlite:/app/data/data.db
16+
- STORAGE_PATH=/app/storage
17+
- RUST_LOG=info
18+
- HOST=0.0.0.0
19+
- PORT=3000
20+
volumes:
21+
# :Z flag is critical for Podman SELinux support
22+
# Map the data and storage directories
23+
- ./data:/app/data:Z
24+
- ./storage:/app/storage:Z
25+
security_opt:
26+
- no-new-privileges:true
27+
deploy:
28+
resources:
29+
limits:
30+
memory: 512M

0 commit comments

Comments
 (0)