Skip to content

Commit f6d91b1

Browse files
Copilotnpv2k1
andcommitted
Add Docker, Nix, and devcontainer configurations with setup documentation
Co-authored-by: npv2k1 <[email protected]>
1 parent f4257bb commit f6d91b1

File tree

8 files changed

+828
-2
lines changed

8 files changed

+828
-2
lines changed

.devcontainer/devcontainer.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "Template Rust Development",
3+
"image": "mcr.microsoft.com/devcontainers/rust:1-bookworm",
4+
5+
"features": {
6+
"ghcr.io/devcontainers/features/rust:1": {
7+
"version": "latest",
8+
"profile": "default"
9+
},
10+
"ghcr.io/devcontainers/features/git:1": {},
11+
"ghcr.io/devcontainers/features/github-cli:1": {}
12+
},
13+
14+
"customizations": {
15+
"vscode": {
16+
"extensions": [
17+
"rust-lang.rust-analyzer",
18+
"vadimcn.vscode-lldb",
19+
"serayuzgur.crates",
20+
"tamasfe.even-better-toml",
21+
"usernamehw.errorlens",
22+
"ms-vscode.makefile-tools"
23+
],
24+
"settings": {
25+
"rust-analyzer.checkOnSave.command": "clippy",
26+
"rust-analyzer.cargo.features": "all",
27+
"editor.formatOnSave": true,
28+
"editor.defaultFormatter": "rust-lang.rust-analyzer",
29+
"[rust]": {
30+
"editor.defaultFormatter": "rust-lang.rust-analyzer"
31+
}
32+
}
33+
}
34+
},
35+
36+
"postCreateCommand": "cargo build",
37+
38+
"remoteEnv": {
39+
"RUST_BACKTRACE": "1",
40+
"DATABASE_URL": "todo.db"
41+
},
42+
43+
"mounts": [
44+
"source=${localWorkspaceFolder}/data,target=/workspaces/${localWorkspaceFolderBasename}/data,type=bind,consistency=cached"
45+
],
46+
47+
"forwardPorts": [],
48+
49+
"portsAttributes": {},
50+
51+
"remoteUser": "vscode"
52+
}

.dockerignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Build artifacts
2+
target/
3+
*.db
4+
*.db-*
5+
6+
# Git
7+
.git/
8+
.gitignore
9+
10+
# IDE
11+
.vscode/
12+
.idea/
13+
14+
# CI/CD
15+
.github/
16+
17+
# Documentation
18+
*.md
19+
docs/
20+
21+
# Nix
22+
*.nix
23+
.envrc
24+
25+
# Devcontainer
26+
.devcontainer/
27+
28+
# Docker
29+
Dockerfile
30+
docker-compose.yml
31+
.dockerignore
32+
33+
# Misc
34+
.env
35+
.env.*

Dockerfile

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Multi-stage build for minimal final image
2+
FROM rust:1.75-slim as builder
3+
4+
# Install build dependencies
5+
RUN apt-get update && apt-get install -y \
6+
pkg-config \
7+
libssl-dev \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
# Create a new empty project
11+
WORKDIR /app
12+
13+
# Copy manifests
14+
COPY Cargo.toml Cargo.lock ./
15+
16+
# Copy source code
17+
COPY src ./src
18+
COPY examples ./examples
19+
COPY tests ./tests
20+
21+
# Build the application in release mode
22+
RUN cargo build --release
23+
24+
# Runtime stage
25+
FROM debian:bookworm-slim
26+
27+
# Install runtime dependencies
28+
RUN apt-get update && apt-get install -y \
29+
ca-certificates \
30+
libssl3 \
31+
&& rm -rf /var/lib/apt/lists/*
32+
33+
# Create a non-root user
34+
RUN useradd -m -u 1000 appuser
35+
36+
WORKDIR /app
37+
38+
# Copy the binary from builder
39+
COPY --from=builder /app/target/release/template-rust /usr/local/bin/template-rust
40+
41+
# Change ownership
42+
RUN chown -R appuser:appuser /app
43+
44+
# Switch to non-root user
45+
USER appuser
46+
47+
# Set default database path
48+
ENV DATABASE_URL=/app/data/todo.db
49+
50+
# Create data directory
51+
RUN mkdir -p /app/data
52+
53+
# Expose any necessary ports (if needed for future web features)
54+
# EXPOSE 8080
55+
56+
# Set the default command
57+
ENTRYPOINT ["template-rust"]
58+
CMD ["--help"]

README.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ A Rust project template featuring a todo application with SQLite database and te
1111
- 🚀 CI/CD with GitHub Actions
1212
- 📦 Cross-platform releases
1313
- 🔒 Security auditing
14+
- 🐳 Docker and Docker Compose support
15+
- ❄️ Nix flakes for reproducible environments
16+
- 📦 Devcontainer configuration for GitHub Codespaces
1417

1518
## Installation
1619

20+
> **💡 Quick Start**: See [SETUP.md](SETUP.md) for detailed setup instructions using Docker, Nix, Codespaces, or local development.
21+
1722
### From Source
1823

1924
```bash
@@ -26,6 +31,33 @@ cargo build --release
2631

2732
Download the latest binary from the [Releases](https://github.com/pnstack/template-rust/releases) page.
2833

34+
### With Docker
35+
36+
```bash
37+
# Build the image
38+
docker build -t template-rust:latest .
39+
40+
# Run with interactive TUI
41+
docker run --rm -it -v $(pwd)/data:/app/data template-rust:latest tui
42+
43+
# Or use Docker Compose
44+
docker compose up
45+
```
46+
47+
### With Nix
48+
49+
```bash
50+
# Enter development environment
51+
nix develop
52+
53+
# Or run directly
54+
nix run
55+
```
56+
57+
### With GitHub Codespaces
58+
59+
Click the "Code" button on GitHub and select "Create codespace on main" - everything is pre-configured!
60+
2961
## Usage
3062

3163
### Command Line Interface
@@ -93,15 +125,28 @@ template-rust/
93125

94126
## Development
95127

128+
> **📚 Full Setup Guide**: See [SETUP.md](SETUP.md) for comprehensive development environment setup instructions.
129+
96130
### Prerequisites
97131

98-
- Rust 1.70 or later
99-
- SQLite3
132+
Choose your preferred development method:
133+
134+
- **Local**: Rust 1.70 or later, SQLite3
135+
- **Docker**: Docker 20.10+ and Docker Compose
136+
- **Nix**: Nix package manager with flakes enabled
137+
- **Codespaces**: Just a GitHub account!
100138

101139
### Building
102140

103141
```bash
142+
# Local
104143
cargo build
144+
145+
# Docker
146+
docker compose up --build
147+
148+
# Nix
149+
nix build
105150
```
106151

107152
### Running Tests
@@ -122,6 +167,15 @@ cargo clippy -- -D warnings
122167
cargo fmt
123168
```
124169

170+
### Development Environments
171+
172+
The project provides multiple development environment options:
173+
174+
- **Docker Compose**: `docker compose up dev` - Containerized development with live code mounting
175+
- **Nix Flakes**: `nix develop` - Reproducible environment with all dependencies
176+
- **Devcontainer**: Open in VS Code or GitHub Codespaces - Fully configured IDE
177+
- **Traditional**: Local Rust installation with cargo
178+
125179
## Database
126180

127181
The application uses SQLite for persistence. By default, it creates a `todo.db` file in the current directory. You can specify a different database path:

0 commit comments

Comments
 (0)