Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "Template Rust Development",
"image": "mcr.microsoft.com/devcontainers/rust:1-bookworm",

"features": {
"ghcr.io/devcontainers/features/rust:1": {
"version": "latest",
"profile": "default"
},
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/github-cli:1": {}
},

"customizations": {
"vscode": {
"extensions": [
"rust-lang.rust-analyzer",
"vadimcn.vscode-lldb",
"serayuzgur.crates",
"tamasfe.even-better-toml",
"usernamehw.errorlens",
"ms-vscode.makefile-tools"
],
"settings": {
"rust-analyzer.checkOnSave.command": "clippy",
"rust-analyzer.cargo.features": "all",
"editor.formatOnSave": true,
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
}
}
}
},

"postCreateCommand": "cargo build",

"remoteEnv": {
"RUST_BACKTRACE": "1",
"DATABASE_URL": "todo.db"
},

"mounts": [
"source=${localWorkspaceFolder}/data,target=/workspaces/${localWorkspaceFolderBasename}/data,type=bind,consistency=cached"
],

"forwardPorts": [],

"portsAttributes": {},

"remoteUser": "vscode"
}
35 changes: 35 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Build artifacts
target/
*.db
*.db-*

# Git
.git/
.gitignore

# IDE
.vscode/
.idea/

# CI/CD
.github/

# Documentation
*.md
docs/

# Nix
*.nix
.envrc

# Devcontainer
.devcontainer/

# Docker
Dockerfile
docker-compose.yml
.dockerignore

# Misc
.env
.env.*
8 changes: 8 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Automatically use Nix flakes when entering this directory
# Install direnv and run: direnv allow

use flake

# Optional: Set additional environment variables
# export DATABASE_URL="todo.db"
# export RUST_BACKTRACE="1"
47 changes: 47 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Docker Build

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
docker-build:
name: Docker Build Test
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
push: false
tags: template-rust:test
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Test Docker image
run: |
docker run --rm template-rust:test --version || echo "Application does not support --version flag"
docker run --rm template-rust:test --help

docker-compose:
name: Docker Compose Validation
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4

- name: Validate docker-compose.yml
run: docker compose config > /dev/null
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Rust build artifacts
/target
Cargo.lock.bak

# Database files
*.db
*.db-*
*.sqlite
*.sqlite3

# Environment files
.env
.env.*
!.envrc

# macOS
.DS_Store

# IDE
.idea/
*.swp
*.swo
*~

# Docker data
data/

# Nix
result
result-*
.direnv/
58 changes: 58 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Multi-stage build for minimal final image
FROM rust:1.83-slim AS builder

# Install build dependencies
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*

# Create a new empty project
WORKDIR /app

# Copy manifests
COPY Cargo.toml Cargo.lock ./

# Copy source code
COPY src ./src
COPY examples ./examples
COPY tests ./tests

# Build the application in release mode
RUN cargo build --release

# Runtime stage
FROM debian:bookworm-slim

# Install runtime dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
libssl3 \
&& rm -rf /var/lib/apt/lists/*

# Create a non-root user
RUN useradd -m -u 1000 appuser

WORKDIR /app

# Copy the binary from builder
COPY --from=builder /app/target/release/template-rust /usr/local/bin/template-rust

# Change ownership
RUN chown -R appuser:appuser /app

# Switch to non-root user
USER appuser

# Set default database path
ENV DATABASE_URL=/app/data/todo.db

# Create data directory
RUN mkdir -p /app/data

# Expose any necessary ports (if needed for future web features)
# EXPOSE 8080

# Set the default command
ENTRYPOINT ["template-rust"]
CMD ["--help"]
48 changes: 48 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.PHONY: help build test clean docker-build docker-run docker-compose-up docker-compose-down

help: ## Show this help message
@echo 'Usage: make [target]'
@echo ''
@echo 'Available targets:'
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'

build: ## Build the project in debug mode
cargo build

build-release: ## Build the project in release mode
cargo build --release

test: ## Run all tests
cargo test

test-verbose: ## Run tests with verbose output
cargo test -- --nocapture

clippy: ## Run clippy linter
cargo clippy -- -D warnings

fmt: ## Format code
cargo fmt

fmt-check: ## Check code formatting
cargo fmt --all -- --check

clean: ## Clean build artifacts
cargo clean

docker-build: ## Build Docker image
docker build -t template-rust:latest .

docker-run: ## Run Docker container in TUI mode
docker run --rm -it -v $(PWD)/data:/app/data template-rust:latest tui

docker-compose-up: ## Start services with docker-compose
docker compose up

docker-compose-down: ## Stop services with docker-compose
docker compose down

docker-compose-dev: ## Start development service with docker-compose
docker compose up dev

all: fmt clippy test build ## Run format, clippy, test, and build
67 changes: 62 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ A Rust project template featuring a todo application with SQLite database and te
- 🚀 CI/CD with GitHub Actions
- 📦 Cross-platform releases
- 🔒 Security auditing
- 🐳 Docker and Docker Compose support
- ❄️ Nix flakes for reproducible environments
- 📦 Devcontainer configuration for GitHub Codespaces

## Installation

> **💡 Quick Start**: See [SETUP.md](SETUP.md) for detailed setup instructions using Docker, Nix, Codespaces, or local development.

### From Source

```bash
Expand All @@ -26,6 +31,33 @@ cargo build --release

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

### With Docker

```bash
# Build the image
docker build -t template-rust:latest .

# Run with interactive TUI
docker run --rm -it -v $(pwd)/data:/app/data template-rust:latest tui

# Or use Docker Compose
docker compose up
```

### With Nix

```bash
# Enter development environment
nix develop

# Or run directly
nix run
```

### With GitHub Codespaces

Click the "Code" button on GitHub and select "Create codespace on main" - everything is pre-configured!

## Usage

### Command Line Interface
Expand Down Expand Up @@ -93,15 +125,28 @@ template-rust/

## Development

> **📚 Full Setup Guide**: See [SETUP.md](SETUP.md) for comprehensive development environment setup instructions.

### Prerequisites

- Rust 1.70 or later
- SQLite3
Choose your preferred development method:

- **Local**: Rust 1.70 or later, SQLite3
- **Docker**: Docker 20.10+ and Docker Compose
- **Nix**: Nix package manager with flakes enabled
- **Codespaces**: Just a GitHub account!

### Building

```bash
# Local
cargo build

# Docker
docker compose up --build

# Nix
nix build
```

### Running Tests
Expand All @@ -122,6 +167,15 @@ cargo clippy -- -D warnings
cargo fmt
```

### Development Environments

The project provides multiple development environment options:

- **Docker Compose**: `docker compose up dev` - Containerized development with live code mounting
- **Nix Flakes**: `nix develop` - Reproducible environment with all dependencies
- **Devcontainer**: Open in VS Code or GitHub Codespaces - Fully configured IDE
- **Traditional**: Local Rust installation with cargo

## Database

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:
Expand All @@ -140,9 +194,12 @@ For testing with in-memory database:

The project includes comprehensive GitHub Actions workflows:

- **CI**: Build, test, lint, and format checks on multiple platforms
- **Security**: Weekly security audits with `cargo audit`
- **Release**: Automated binary releases for Linux, macOS, and Windows
- **CI** (`ci.yml`): Build, test, lint, and format checks on multiple platforms (Linux, macOS, Windows)
- **Security** (`security.yml`): Weekly security audits with `cargo audit`
- **Release** (`release.yml`): Automated binary releases for Linux, macOS, and Windows on version tags
- **Docker** (`docker.yml`): Docker image build testing and docker-compose validation

All workflows run automatically on push and pull requests to ensure code quality and security.

## Contributing

Expand Down
Loading
Loading