diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9c0af39c..25b5b7c1 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,7 +2,7 @@ "image": "mcr.microsoft.com/devcontainers/javascript-node:4-24-trixie", "features": { "ghcr.io/devcontainers/features/docker-in-docker:2": { - "moby":"false" + "moby": "false" } }, "postCreateCommand": "npm install -g @devcontainers/cli", diff --git a/src/ruby-rails-postgres/.devcontainer/Dockerfile b/src/ruby-rails-postgres/.devcontainer/Dockerfile index 47767878..dd84a119 100644 --- a/src/ruby-rails-postgres/.devcontainer/Dockerfile +++ b/src/ruby-rails-postgres/.devcontainer/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/devcontainers/ruby:2-${templateOption:imageVariant} +FROM mcr.microsoft.com/devcontainers/ruby:3-${templateOption:imageVariant} # Install Rails RUN su vscode -c "gem install rails webdrivers" diff --git a/src/ruby-rails-postgres/.devcontainer/docker-compose.yml b/src/ruby-rails-postgres/.devcontainer/docker-compose.yml index a963103b..2f9927ed 100644 --- a/src/ruby-rails-postgres/.devcontainer/docker-compose.yml +++ b/src/ruby-rails-postgres/.devcontainer/docker-compose.yml @@ -1,4 +1,5 @@ -version: '3' +# Dev Container Docker Compose Configuration for Ruby on Rails with PostgreSQL +# This configuration has been optimized for reliability in automated and remote environments services: app: @@ -12,17 +13,38 @@ services: # Overrides default command so things don't shut down after the process ends. command: sleep infinity - # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. - network_mode: service:db + # Database connection string for Rails applications + # Provides a standard way to connect to the PostgreSQL database + environment: + DATABASE_URL: "postgresql://postgres:postgres@db:5432/postgres" + # IMPORTANT: Use proper Docker networking instead of network_mode to avoid namespace issues + # The previous network_mode: service:db caused container startup failures in automated environments + # This approach is more reliable and works consistently across different deployment scenarios + depends_on: + db: + condition: service_healthy # Wait for PostgreSQL to be ready before starting the app + networks: + - app-network # Connect to custom bridge network for service communication # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. # (Adding the "ports" property to this file will not forward from a Codespace.) db: image: postgres:latest restart: unless-stopped + networks: + - app-network # Connect to the same network as the app container + + # Health check ensures PostgreSQL is ready before dependent services start + # This is critical for depends_on with condition: service_healthy to work properly + healthcheck: + test: [ "CMD-SHELL", "pg_isready -U postgres" ] + interval: 10s # Check every 10 seconds + timeout: 5s # Wait up to 5 seconds for response + retries: 5 # Retry 5 times before marking as unhealthy + start_period: 30s # Give PostgreSQL 30 seconds to start before health checks begin volumes: - - postgres-data:/var/lib/postgresql/data + - postgres-data:/var/lib/postgresql - ./create-db-user.sql:/docker-entrypoint-initdb.d/create-db-user.sql environment: POSTGRES_USER: postgres @@ -53,5 +75,15 @@ services: # Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally. # (Adding the "ports" property to this file will not forward from a Codespace.) +# Persistent storage for PostgreSQL data volumes: postgres-data: + # Named volume ensures data persists across container restarts + # Located at /var/lib/postgresql/data inside the container + +# Custom bridge network for service communication +# Replaces the problematic network_mode: service:db approach +networks: + app-network: + driver: bridge # Standard bridge driver for container-to-container communication + # Services on this network can communicate using service names (app -> db) diff --git a/src/ruby-rails-postgres/README.md b/src/ruby-rails-postgres/README.md index deb86ec2..4fde3a01 100644 --- a/src/ruby-rails-postgres/README.md +++ b/src/ruby-rails-postgres/README.md @@ -7,7 +7,7 @@ Develop Ruby on Rails applications with Postgres. Includes a Rails application c | Options Id | Description | Type | Default Value | |-----|-----|-----|-----| -| imageVariant | Ruby version (use -trixie, -bookworm, -bullseye variants on local arm64/Apple Silicon) : | string | 3.4-trixie | +| imageVariant | Ruby version (use -trixie, -bookworm, -bullseye variants on local arm64/Apple Silicon) : | string |4.0-trixie | This template references an image that was [pre-built](https://containers.dev/implementors/reference/#prebuilding) to automatically include needed devcontainer.json metadata. diff --git a/src/ruby-rails-postgres/devcontainer-template.json b/src/ruby-rails-postgres/devcontainer-template.json index e277e7ef..0368efef 100644 --- a/src/ruby-rails-postgres/devcontainer-template.json +++ b/src/ruby-rails-postgres/devcontainer-template.json @@ -1,6 +1,6 @@ { "id": "ruby-rails-postgres", - "version": "5.0.0", + "version": "6.0.0", "name": "Ruby on Rails & Postgres", "description": "Develop Ruby on Rails applications with Postgres. Includes a Rails application container and PostgreSQL server.", "documentationURL": "https://github.com/devcontainers/templates/tree/main/src/ruby-rails-postgres", @@ -9,23 +9,23 @@ "options": { "imageVariant": { "type": "string", - "description": "Ruby version (use -bookworm, -bullseye variants on local arm64/Apple Silicon):", + "description": "Ruby version (use - trixie, -bookworm, -bullseye variants on local arm64/Apple Silicon):", "proposals": [ - "3-trixie", + "4-trixie", "3.4-trixie", "3.3-trixie", "3.2-trixie", - "3-bookworm", + "4-bookworm", "3.4-bookworm", "3.3-bookworm", "3.2-bookworm", - "3-bullseye", + "4-bullseye", "3.4-bullseye", "3.3-bullseye", "3.2-bullseye" ], - "default": "3.4-trixie" - } + "default": "4-trixie" + } }, "platforms": ["Ruby"], "optionalPaths": [ diff --git a/src/ruby/.devcontainer/devcontainer.json b/src/ruby/.devcontainer/devcontainer.json index eead7386..3f642645 100644 --- a/src/ruby/.devcontainer/devcontainer.json +++ b/src/ruby/.devcontainer/devcontainer.json @@ -3,7 +3,7 @@ { "name": "Ruby", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/ruby:2-${templateOption:imageVariant}" + "image": "mcr.microsoft.com/devcontainers/ruby:3-${templateOption:imageVariant}" // Features to add to the dev container. More info: https://containers.dev/features. // "features": {}, diff --git a/src/ruby/README.md b/src/ruby/README.md index 9857029f..28936c71 100644 --- a/src/ruby/README.md +++ b/src/ruby/README.md @@ -7,7 +7,7 @@ Develop Ruby based applications. includes everything you need to get up and runn | Options Id | Description | Type | Default Value | |-----|-----|-----|-----| -| imageVariant | Ruby version (use -trixie, -bookworm, -bullseye variants on local arm64/Apple Silicon) : | string | 3.4-trixie | +| imageVariant | Ruby version (use -trixie, -bookworm, -bullseye variants on local arm64/Apple Silicon) : | string |4.0-trixie | This template references an image that was [pre-built](https://containers.dev/implementors/reference/#prebuilding) to automatically include needed devcontainer.json metadata. diff --git a/src/ruby/devcontainer-template.json b/src/ruby/devcontainer-template.json index d3ae4051..fc3c64a9 100644 --- a/src/ruby/devcontainer-template.json +++ b/src/ruby/devcontainer-template.json @@ -1,6 +1,6 @@ { "id": "ruby", - "version": "5.0.0", + "version": "6.0.0", "name": "Ruby", "description": "Develop Ruby based applications. includes everything you need to get up and running.", "documentationURL": "https://github.com/devcontainers/templates/tree/main/src/ruby", @@ -11,20 +11,20 @@ "type": "string", "description": "Ruby version (use -trixie, -bookworm, -bullseye variants on local arm64/Apple Silicon):", "proposals": [ - "3-trixie", + "4.0-trixie", "3.4-trixie", "3.3-trixie", "3.2-trixie", - "3-bookworm", + "4.0-bookworm", "3.4-bookworm", "3.3-bookworm", "3.2-bookworm", - "3-bullseye", + "4.0-bullseye", "3.4-bullseye", "3.3-bullseye", "3.2-bullseye" ], - "default": "3.4-trixie" + "default": "4.0-trixie" } }, "platforms": ["Ruby"], diff --git a/test/ruby-rails-postgres/test.sh b/test/ruby-rails-postgres/test.sh index 7ef1d08b..99e4d900 100755 --- a/test/ruby-rails-postgres/test.sh +++ b/test/ruby-rails-postgres/test.sh @@ -10,12 +10,17 @@ fixTestProjectFolderPrivs # Run common tests checkCommon + # Run devcontainer specific tests check "rails" rails --version check "rails installation path" gem which rails check "user has write permission to rvm gems" [ -w /usr/local/rvm/gems ] check "user has write permission to rvm gems default" [ -w /usr/local/rvm/gems/default ] check "user can install gems" gem install github-markup +check "gem command works" gem --version +check "user can install gems" gem install github-markup +check "Bundler gem presence " gem list | grep -q "bundler" + # Report result reportResults