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
56 changes: 56 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# syntax=docker/dockerfile:1

ARG RUBY_VERSION=3.4.4
FROM ruby:$RUBY_VERSION-slim

# Install system dependencies
RUN apt-get update -qq && \
apt-get install -y \
build-essential \
curl \
git \
libpq-dev \
libvips \
libyaml-dev \
nodejs \
npm \
pkg-config \
postgresql-client \
sudo \
vim \
wget \
xz-utils \
imagemagick \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Create a non-root user
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME

# Set the working directory
WORKDIR /workspaces/OutcomeTrackerAPI

# Change ownership of the working directory
RUN chown -R $USERNAME:$USERNAME /workspaces

# Switch to the non-root user
USER $USERNAME

# Install bundler
RUN gem install bundler

# Set environment variables
ENV BUNDLE_PATH=/usr/local/bundle \
BUNDLE_BIN=/usr/local/bundle/bin \
GEM_HOME=/usr/local/bundle
ENV PATH=$BUNDLE_BIN:$PATH

# Default command
CMD ["/bin/bash"]
113 changes: 113 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Dev Container Documentation

This project includes a complete dev container setup for consistent development environments.

## What's Included

- **Ruby 3.4.4**: Matches the project's Ruby version
- **PostgreSQL 16**: Database server in a separate container
- **VS Code Extensions**: Ruby LSP, GitHub Copilot, and other useful extensions
- **Development Tools**: Git, GitHub CLI, build tools
- **Auto Setup**: Database creation, migration, and seeding

## Getting Started

1. **Install Prerequisites**:
- [Docker Desktop](https://www.docker.com/products/docker-desktop)
- [VS Code](https://code.visualstudio.com/)
- [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)

2. **Open in Dev Container**:
- Open the project in VS Code
- Click "Reopen in Container" when prompted
- Or use Command Palette: "Dev Containers: Reopen in Container"

3. **Wait for Setup**: The first build takes a few minutes

## Common Commands

Once inside the dev container, you can use these commands:

```bash
# Start the Rails server
rails server

# Database operations
rails db:migrate
rails db:seed
rails db:reset

# Run tests
rails test

# Rails console
rails console

# Helper script for common tasks
.devcontainer/dev-helper.sh reset # Reset database
.devcontainer/dev-helper.sh server # Start server
.devcontainer/dev-helper.sh console # Rails console
```

## Port Forwarding

The following ports are automatically forwarded:
- **3000**: Rails application server
- **5432**: PostgreSQL database

## Database Connection

From within the dev container:
- **Host**: `db`
- **Database**: `outcome_tracker_api_development`
- **Username**: `postgres`
- **Password**: `postgres`

From your local machine:
- **Host**: `localhost`
- **Port**: `5432`
- **Database**: `outcome_tracker_api_development`
- **Username**: `postgres`
- **Password**: `postgres`

## Environment Variables

The dev container automatically sets:
- `DATABASE_URL`: Points to the PostgreSQL container
- `POSTGRES_USER`: postgres
- `POSTGRES_PASSWORD`: postgres
- `POSTGRES_DB`: outcome_tracker_api_development

## Troubleshooting

### Container Won't Start
- Ensure Docker Desktop is running
- Try rebuilding: Command Palette → "Dev Containers: Rebuild Container"

### Database Connection Issues
- Check if the database container is running: `docker ps`
- Restart the containers: "Dev Containers: Rebuild Container"

### Slow Performance
- Ensure you have enough resources allocated to Docker Desktop
- Consider enabling file system caching in Docker settings

### Port Already in Use
- Check if you have local services running on ports 3000 or 5432
- Stop local PostgreSQL: `brew services stop postgresql` (on macOS)

## Customization

To modify the dev container:
1. Edit `.devcontainer/devcontainer.json` for VS Code settings
2. Edit `.devcontainer/Dockerfile` for system dependencies
3. Edit `.devcontainer/docker-compose.yml` for service configuration
4. Rebuild the container after changes

## Benefits

- ✅ **Consistency**: Same environment for all developers
- ✅ **Isolation**: No conflicts with local setup
- ✅ **Zero Configuration**: Everything pre-configured
- ✅ **Fast Onboarding**: New developers can start immediately
- ✅ **Reproducible**: Exact same setup every time
40 changes: 40 additions & 0 deletions .devcontainer/dev-helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# Simple script to help with common dev container database tasks

case "$1" in
"reset")
echo "🔄 Resetting database..."
rails db:drop db:create db:migrate db:seed
echo "✅ Database reset complete!"
;;
"migrate")
echo "🔄 Running migrations..."
rails db:migrate
echo "✅ Migrations complete!"
;;
"seed")
echo "🌱 Seeding database..."
rails db:seed
echo "✅ Seeding complete!"
;;
"console")
echo "🚀 Starting Rails console..."
rails console
;;
"server")
echo "🚀 Starting Rails server..."
rails server -b 0.0.0.0
;;
*)
echo "Usage: $0 {reset|migrate|seed|console|server}"
echo ""
echo "Commands:"
echo " reset - Drop, create, migrate and seed the database"
echo " migrate - Run pending migrations"
echo " seed - Seed the database"
echo " console - Start Rails console"
echo " server - Start Rails server (bound to all interfaces)"
exit 1
;;
esac
64 changes: 64 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "Government Outcomes Tracker API",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/github-cli:1": {}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [3000, 5432],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "bin/setup",

// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"rebornix.Ruby",
"Shopify.ruby-lsp",
"bradlc.vscode-tailwindcss",
"ms-vscode.vscode-json",
"formulahendry.auto-rename-tag",
"ms-vscode-remote.remote-containers",
"GitHub.copilot",
"ms-azuretools.vscode-docker"
],
"settings": {
"ruby.lsp.enabledFeatures": {
"codeActions": true,
"diagnostics": true,
"documentHighlights": true,
"documentLink": true,
"documentSymbols": true,
"foldingRanges": true,
"formatting": true,
"hover": true,
"inlayHint": true,
"onTypeFormatting": true,
"selectionRanges": true,
"semanticHighlighting": true,
"completion": true,
"codeLens": true,
"definition": true,
"workspaceSymbol": true,
"signatureHelp": true,
"typeHierarchy": true
},
"ruby.lsp.featuresConfiguration": {
"inlayHint": {
"enableAll": true
}
}
}
}
},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "vscode"
}
37 changes: 37 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
services:
app:
build:
context: ..
dockerfile: .devcontainer/Dockerfile
volumes:
- ../..:/workspaces:cached
command: sleep infinity
environment:
DATABASE_URL: postgres://postgres:postgres@db:5432/outcome_tracker_api_development
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: outcome_tracker_api_development
depends_on:
- db
networks:
- rails-network

db:
image: postgres:16
restart: unless-stopped
volumes:
- postgres-data:/var/lib/postgresql/data
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: outcome_tracker_api_development
networks:
- rails-network
ports:
- "5432:5432"

volumes:
postgres-data:

networks:
rails-network: