Skip to content

Commit 95331dc

Browse files
committed
build(dev): add live development environment with cargo-watch
- Add Dockerfile.dev with cargo-watch for automatic recompilation on file changes - Configure compose.dev.yaml with read-only volume mounts for source code - Use Docker volumes for build artifacts to keep host filesystem clean - Enable RUST_LOG=debug for development logging - Update comment to use modern 'docker compose' syntax Development workflow: - Start: docker compose -f compose.dev.yaml up --build - Edit code and cargo-watch automatically recompiles - No manual rebuilds or restarts needed
1 parent 2dc6b5f commit 95331dc

File tree

2 files changed

+47
-12
lines changed

2 files changed

+47
-12
lines changed

Dockerfile.dev

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Development Dockerfile - prepares dev environment for live compilation
2+
# supported versions here: https://hub.docker.com/_/rust
3+
ARG ALPINE_VERSION=3.20
4+
5+
FROM rust:alpine${ALPINE_VERSION}
6+
7+
RUN apk add --no-cache musl-dev wget
8+
9+
WORKDIR /redlib
10+
11+
# Pre-download dependencies (will be cached in Docker volume)
12+
COPY Cargo.lock Cargo.toml ./
13+
RUN mkdir -p src && echo "fn main() {}" > src/main.rs && \
14+
cargo build --bin redlib && \
15+
rm -rf src
16+
17+
# Install cargo-watch for automatic recompilation on file changes
18+
RUN cargo install cargo-watch
19+
20+
EXPOSE 8080
21+
22+
# Use cargo-watch to automatically recompile and restart on source changes
23+
CMD ["cargo", "watch", "-x", "run --bin redlib"]
24+

compose.dev.yaml

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
1-
# docker-compose -f docker-compose.dev.yml up -d
2-
version: "3.8"
1+
# docker compose -f compose.dev.yaml up
2+
# Development setup - source mounted read-only, build cache in Docker volumes
33

44
services:
55
redlib:
6-
build: .
7-
restart: always
6+
build:
7+
context: .
8+
dockerfile: Dockerfile.dev
89
container_name: "redlib"
910
ports:
10-
- 8080:8080 # Specify `127.0.0.1:8080:8080` instead if using a reverse proxy
11-
user: nobody
12-
read_only: true
13-
security_opt:
14-
- no-new-privileges:true
15-
# - seccomp=seccomp-redlib.json
16-
cap_drop:
17-
- ALL
11+
- 8080:8080
12+
volumes:
13+
# Mount source code as read-only - code changes trigger rebuild
14+
- ./src:/redlib/src:ro
15+
- ./templates:/redlib/templates:ro
16+
- ./static:/redlib/static:ro
17+
- ./Cargo.toml:/redlib/Cargo.toml:ro
18+
- ./Cargo.lock:/redlib/Cargo.lock:ro
19+
- ./build.rs:/redlib/build.rs:ro
20+
# Build artifacts stay in Docker volumes (not on your disk)
21+
- redlib-target:/redlib/target
22+
- redlib-cargo:/usr/local/cargo
23+
environment:
24+
- RUST_LOG=debug
1825
networks:
1926
- redlib
2027
healthcheck:
2128
test: ["CMD", "wget", "--spider", "-q", "--tries=1", "http://localhost:8080/settings"]
2229
interval: 5m
2330
timeout: 3s
2431

32+
volumes:
33+
redlib-target:
34+
redlib-cargo:
35+
2536
networks:
2637
redlib:

0 commit comments

Comments
 (0)