An open API service indexing awesome lists of open source software.

https://github.com/opensoft/flutterbench

This is a devcontainer setup for Flutter development. Scripts for setting up new devcontainer projects with well manered containers.
https://github.com/opensoft/flutterbench

Last synced: 12 days ago
JSON representation

This is a devcontainer setup for Flutter development. Scripts for setting up new devcontainer projects with well manered containers.

Awesome Lists containing this project

README

          

# ๐Ÿš€ FlutterBench - Flutter Development Environment

A comprehensive Flutter development environment with DevContainer templates and project creation tools.

## ๐Ÿงฑ Container Architecture (Layered)

FlutterBench is standardizing on the layered workBenches model:
- **Layer 0**: `workbench-base:latest`
- **Layer 1a**: `dev-bench-base:latest`
- **Layer 2**: `flutter-bench:latest` (bench-specific tools)
- **Layer 3**: `flutter-bench:{user}` (user image built from Layer 2)

### Legacy Note
Any monolithic `.devcontainer/` Dockerfiles are **deprecated**. The layered images are the source of truth going forward.

## Bench Image Workflow

Use these commands for the bench itself:

```bash
# Check whether Flutter bench images are current
./scripts/rebuild-stack.sh --check

# Rebuild Layer 2 and Layer 3
./scripts/build-layer.sh

# Start the bench container from the prebuilt user image
./scripts/start-monster.sh
```

`./scripts/start-monster.sh` no longer builds a monolithic devcontainer image. It ensures `flutter-bench:latest` exists, refreshes `flutter-bench:${USER}` if needed, and then starts the bench container from the layered image.

## Flutter SDK policy

`flutterBench` now carries two SDK tracks in Layer 2:

- `/opt/flutter` โ€” the shared current stable SDK used as the default `flutter`
- `/opt/flutter-3.27.0` โ€” the long-term supported Flutter 3.27 line for pinned repos

Shell helpers exposed in bench user environments:

- `flutter` / `dart` โ†’ current stable
- `flutter327` / `dart327` โ†’ pinned Flutter 3.27.0

Use project-local FVM where the repo pins a version. The baked 3.27 SDK exists to avoid slow first-run downloads for long-lived pinned projects.

## ๐ŸŽฏ Purpose

FlutterBench provides two ways to create Flutter projects with DevContainer support:

1. **๐Ÿค– Automated Setup** - Use `new-flutter-project.sh` for quick, standardized project creation
2. **๐Ÿ”ง Manual Setup** - Copy templates manually for maximum customization control

## ๐Ÿ“ Structure

```
flutterBench/
โ”œโ”€โ”€ scripts/
โ”‚ โ”œโ”€โ”€ new-flutter-project.sh # Automated project creation
โ”‚ โ”œโ”€โ”€ new-dartwing-project.sh # DartWing project creation
โ”‚ โ”œโ”€โ”€ update-flutter-project.sh # Update existing projects
โ”‚ โ”œโ”€โ”€ launch-devbench.sh # Launch development container
โ”‚ โ””โ”€โ”€ start-monster.sh # Container startup script
โ”œโ”€โ”€ templates/
โ”‚ โ””โ”€โ”€ flutter-devcontainer-template/ # DevContainer template
โ”‚ โ”œโ”€โ”€ .devcontainer/ # VS Code DevContainer config
โ”‚ โ”œโ”€โ”€ .vscode/ # VS Code settings & tasks
โ”‚ โ”œโ”€โ”€ scripts/
โ”‚ โ”‚ โ”œโ”€โ”€ manual-setup-project.sh # Manual setup validation
โ”‚ โ”‚ โ””โ”€โ”€ README.md # Script usage guide
โ”‚ โ”œโ”€โ”€ .env.example # Environment template
โ”‚ โ””โ”€โ”€ README.md # Template documentation
โ””โ”€โ”€ docs/ # Additional documentation
```

## ๐Ÿš€ Getting Started

### Option 1: Automated Setup (Recommended)

**Best for**: New projects, standardized setup, quick start

```bash
# Navigate to flutterBench scripts
cd /path/to/workBenches/devBenches/flutterBench/scripts

# Create new Flutter project with DevContainer
./new-flutter-project.sh my-flutter-app

# Or specify custom target directory
./new-flutter-project.sh my-flutter-app ~/projects/special-projects
```

**What it does automatically:**
- โœ… Creates Flutter project using `flutter create`
- โœ… Copies and configures DevContainer template
- โœ… Sets up environment variables (`.env`)
- โœ… Configures user UID/GID for proper permissions
- โœ… Sets up infrastructure paths
- โœ… Includes specKit for spec-driven development
- โœ… Ready to open in VS Code

### Option 2: Manual Setup (Advanced)

**Best for**: Existing projects, template customization, learning/understanding

```bash
# 1. Create or navigate to your Flutter project
flutter create my-flutter-app # or use existing project
cd my-flutter-app

# 2. Copy template files
TEMPLATE_PATH="/path/to/workBenches/devBenches/flutterBench/templates/flutter-devcontainer-template"
cp -r "$TEMPLATE_PATH/.devcontainer" .
cp -r "$TEMPLATE_PATH/.vscode" .
cp -r "$TEMPLATE_PATH/scripts" .
cp "$TEMPLATE_PATH/.env.example" .

# 3. Set up environment configuration
cp .env.example .env
# Edit .env file with your project settings...

# 4. Validate setup (IMPORTANT!)
./scripts/manual-setup-project.sh
```

**When to use manual setup:**
- โœ… Adding DevContainer to existing Flutter project
- โœ… Need to customize template before applying
- โœ… Working with non-standard directory structure
- โœ… Want to understand how the template works
- โœ… Debugging container configuration issues

## ๐Ÿ“‹ Key Differences

| Feature | Automated Setup | Manual Setup |
|---------|----------------|-------------|
| **Speed** | โšก Fast (single command) | ๐Ÿข Multiple steps required |
| **Control** | ๐ŸŽฏ Standardized | ๐Ÿ”ง Full customization |
| **Validation** | โœ… Built-in | ๐Ÿ“‹ Manual validation required |
| **Learning** | ๐Ÿ“ฆ Black box | ๐ŸŽ“ Educational |
| **Best For** | New projects | Existing projects, customization |
| **Difficulty** | ๐ŸŸข Easy | ๐ŸŸก Intermediate |

## ๐Ÿ”ง Manual Setup Validation

**โš ๏ธ IMPORTANT**: When using manual setup, you **MUST** run the validation script:

```bash
./scripts/manual-setup-project.sh
```

This script:
- ๐Ÿ” Creates `.env` from `.env.example` if missing
- โœ… Validates all required environment variables
- ๐Ÿ”ง Checks variable formats and values
- ๐Ÿณ Verifies Docker environment
- ๐Ÿ“‹ Tests container configuration
- ๐Ÿ—๏ธ Validates infrastructure paths

**๐Ÿ“– For detailed manual setup guidance**, see [`templates/flutter-devcontainer-template/scripts/README.md`](templates/flutter-devcontainer-template/scripts/README.md)

## ๐Ÿ’ก Which Approach Should I Use?

### Use **Automated Setup** when:
- โœ… Creating a new Flutter project from scratch
- โœ… You want standard workBenches project structure
- โœ… You need to get started quickly
- โœ… You trust the default configuration
- โœ… You're new to DevContainers

### Use **Manual Setup** when:
- โœ… Adding DevContainer to existing Flutter project
- โœ… You need custom template modifications
- โœ… Working with unique directory structures
- โœ… You want to learn how DevContainers work
- โœ… Debugging container issues
- โœ… You need maximum control over the setup process

## โš™๏ธ Centralized Configuration Philosophy

**Key Principle: The `.env` file is the single source of truth for ALL project and user-specific configuration.**

### What This Means:
- โœ… **Template files remain untouched** - `devcontainer.json`, `docker-compose.yml`, etc. are never modified
- โœ… **All customization via environment variables** - container names, user settings, versions, ports
- โœ… **Project-specific settings isolated** - each project has its own `.env` file
- โœ… **Easy template updates** - template improvements don't conflict with your settings

### Configuration Examples:

```bash
# .env file controls everything:
PROJECT_NAME=dartwing
APP_CONTAINER_SUFFIX=app # Results in: dartwing-app
SERVICE_CONTAINER_SUFFIX=gateway # Results in: dartwing-gateway
USER_UID=1000
FLUTTER_VERSION=3.24.0
COMPOSE_PROJECT_NAME=dartwingers
```

**Result**: Template files use `${PROJECT_NAME}-${APP_CONTAINER_SUFFIX}` โ†’ resolves to `dartwing-app`

## ๐Ÿš€ Next Steps After Setup

Regardless of which setup method you used:

1. **Open in VS Code**: `code .`
2. **Reopen in Container**: Click prompt or Ctrl+Shift+P โ†’ "Dev Containers: Reopen in Container"
3. **Wait for build**: First time takes 2-5 minutes
4. **Start coding**: Container includes Flutter SDK, Android tools, and VS Code extensions

## ๐Ÿ”ง Available Scripts

### Project Creation
- `scripts/new-flutter-project.sh` - Create new Flutter project with DevContainer
- `scripts/new-dartwing-project.sh` - Create new DartWing project variant

### Project Management
- `scripts/update-flutter-project.sh` - Update existing project to latest template
- `templates/.../scripts/manual-setup-project.sh` - Validate manual setup

### Development Environment
- `scripts/launch-devbench.sh` - Launch development container
- `scripts/start-monster.sh` - Ensure Layer 2 and Layer 3, then start the bench container
- `scripts/rebuild-stack.sh` - Check or rebuild the Flutter bench image stack
- `scripts/ensure-images.sh` - Lightweight Layer 2/Layer 3 check for devcontainer startup

### SonarCloud Coverage
- `sonarcloud-dart-flutter` - Run Dart/Flutter coverage and SonarCloud scan

`sonarcloud-dart-flutter` reads `SONARQUBE_TOKEN` from
`~/.config/sonarqube/sonar.env`. For Flutter projects it runs
`flutter test --coverage`; for pure Dart projects it runs the Dart `coverage`
package. Both paths produce `coverage/lcov.info`, then the helper invokes:

```bash
sonar-scanner -Dsonar.dart.lcov.reportPaths=coverage/lcov.info
```

Shell aliases: `flutter-sonar-coverage` and `dart-sonar-coverage`.

## ๐Ÿ“š Documentation

- [`templates/flutter-devcontainer-template/README.md`](templates/flutter-devcontainer-template/README.md) - Template details
- [`templates/flutter-devcontainer-template/scripts/README.md`](templates/flutter-devcontainer-template/scripts/README.md) - Manual setup guide
- [`docs/env-file-docker-compose-guide.md`](docs/env-file-docker-compose-guide.md) - Environment configuration guide

## ๐ŸŽฏ Template Features

The DevContainer template includes:

- ๐Ÿณ **Lightweight container** (~500MB vs 2GB+ FlutterBench)
- ๐Ÿ”ง **Centralized configuration** - ALL project and user settings in `.env` file only
- ๐Ÿ“ **No template file modification** - template files remain untouched, use environment variables
- ๐Ÿท๏ธ **Configurable container naming** - customize app and service container names via `.env`
- ๐Ÿ“ฑ **Shared ADB infrastructure** (connects to external ADB server)
- โš™๏ธ **VS Code integration** (tasks, launch configs, extensions)
- ๐Ÿ—๏ธ **Proper user permissions** (UID/GID matching)
- ๐Ÿ”„ **Hot reload support** (port forwarding configured)
- ๐Ÿงช **Testing support** (launch configurations)
- ๐Ÿ“‹ **Spec-driven development** (includes specKit)

## ๐Ÿ—๏ธ Container Philosophy

- **FlutterBench** = Heavy development workbench (~2GB, all tools)
- **Project Containers** = Lightweight project-specific environment (~500MB)

Use FlutterBench for heavy development, project containers for debugging and light development.