Skip to content

Commit f85b348

Browse files
authored
Merge pull request #3 from pnstack/copilot/add-ci-cd-config
Add Docker, Nix, devcontainer, and comprehensive setup documentation
2 parents 1d43bb6 + d2cc279 commit f85b348

File tree

15 files changed

+1611
-5
lines changed

15 files changed

+1611
-5
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.*

.envrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Automatically use Nix flakes when entering this directory
2+
# Install direnv and run: direnv allow
3+
4+
use flake
5+
6+
# Optional: Set additional environment variables
7+
# export DATABASE_URL="todo.db"
8+
# export RUST_BACKTRACE="1"

.github/workflows/docker.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Docker Build
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
docker-build:
14+
name: Docker Build Test
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v3
23+
24+
- name: Build Docker image
25+
uses: docker/build-push-action@v5
26+
with:
27+
context: .
28+
push: false
29+
tags: template-rust:test
30+
cache-from: type=gha
31+
cache-to: type=gha,mode=max
32+
33+
- name: Test Docker image
34+
run: |
35+
docker run --rm template-rust:test --version || echo "Application does not support --version flag"
36+
docker run --rm template-rust:test --help
37+
38+
docker-compose:
39+
name: Docker Compose Validation
40+
runs-on: ubuntu-latest
41+
permissions:
42+
contents: read
43+
steps:
44+
- uses: actions/checkout@v4
45+
46+
- name: Validate docker-compose.yml
47+
run: docker compose config > /dev/null

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
1+
# Rust build artifacts
12
/target
3+
Cargo.lock.bak
4+
5+
# Database files
26
*.db
37
*.db-*
8+
*.sqlite
9+
*.sqlite3
10+
11+
# Environment files
412
.env
13+
.env.*
14+
!.envrc
15+
16+
# macOS
517
.DS_Store
18+
19+
# IDE
20+
.idea/
21+
*.swp
22+
*.swo
23+
*~
24+
25+
# Docker data
26+
data/
27+
28+
# Nix
29+
result
30+
result-*
31+
.direnv/

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.83-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"]

Makefile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
.PHONY: help build test clean docker-build docker-run docker-compose-up docker-compose-down
2+
3+
help: ## Show this help message
4+
@echo 'Usage: make [target]'
5+
@echo ''
6+
@echo 'Available targets:'
7+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
8+
9+
build: ## Build the project in debug mode
10+
cargo build
11+
12+
build-release: ## Build the project in release mode
13+
cargo build --release
14+
15+
test: ## Run all tests
16+
cargo test
17+
18+
test-verbose: ## Run tests with verbose output
19+
cargo test -- --nocapture
20+
21+
clippy: ## Run clippy linter
22+
cargo clippy -- -D warnings
23+
24+
fmt: ## Format code
25+
cargo fmt
26+
27+
fmt-check: ## Check code formatting
28+
cargo fmt --all -- --check
29+
30+
clean: ## Clean build artifacts
31+
cargo clean
32+
33+
docker-build: ## Build Docker image
34+
docker build -t template-rust:latest .
35+
36+
docker-run: ## Run Docker container in TUI mode
37+
docker run --rm -it -v $(PWD)/data:/app/data template-rust:latest tui
38+
39+
docker-compose-up: ## Start services with docker-compose
40+
docker compose up
41+
42+
docker-compose-down: ## Stop services with docker-compose
43+
docker compose down
44+
45+
docker-compose-dev: ## Start development service with docker-compose
46+
docker compose up dev
47+
48+
all: fmt clippy test build ## Run format, clippy, test, and build

README.md

Lines changed: 62 additions & 5 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:
@@ -140,9 +194,12 @@ For testing with in-memory database:
140194

141195
The project includes comprehensive GitHub Actions workflows:
142196

143-
- **CI**: Build, test, lint, and format checks on multiple platforms
144-
- **Security**: Weekly security audits with `cargo audit`
145-
- **Release**: Automated binary releases for Linux, macOS, and Windows
197+
- **CI** (`ci.yml`): Build, test, lint, and format checks on multiple platforms (Linux, macOS, Windows)
198+
- **Security** (`security.yml`): Weekly security audits with `cargo audit`
199+
- **Release** (`release.yml`): Automated binary releases for Linux, macOS, and Windows on version tags
200+
- **Docker** (`docker.yml`): Docker image build testing and docker-compose validation
201+
202+
All workflows run automatically on push and pull requests to ensure code quality and security.
146203

147204
## Contributing
148205

0 commit comments

Comments
 (0)