Skip to content

Commit fc23cf4

Browse files
Update Ruby version to 4.0 and adjust related documentation (#401)
* Update Ruby version to 4.0 and adjust related documentation * Add network check for rubygems.org accessibility in test script * Improve network check for rubygems.org accessibility with retries and conditional gem installation * Refactor gem installation check to use built-in bundler instead of external gem * Add support for ruby 4.0 * Fix ruby-rails-postgres template option default * Fix ruby template option default * Update Ruby version in README and devcontainer configuration to 4.0-trixie * Enhance Docker networking * Refactor Docker Compose configuration for improved readability * Update PostgreSQL image to latest and adjust volume path for data persistence * Update PostgreSQL image to latest and adjust volume path for data persistence * addressing review comments * addressing review comments * Update gem presence check for Bundler * Update Ruby version format in devcontainer template * Update Ruby version format in README and devcontainer templates * Consolidate comments
1 parent d67c7ed commit fc23cf4

9 files changed

Lines changed: 56 additions & 21 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"image": "mcr.microsoft.com/devcontainers/javascript-node:4-24-trixie",
33
"features": {
44
"ghcr.io/devcontainers/features/docker-in-docker:2": {
5-
"moby":"false"
5+
"moby": "false"
66
}
77
},
88
"postCreateCommand": "npm install -g @devcontainers/cli",

src/ruby-rails-postgres/.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/devcontainers/ruby:2-${templateOption:imageVariant}
1+
FROM mcr.microsoft.com/devcontainers/ruby:3-${templateOption:imageVariant}
22

33
# Install Rails
44
RUN su vscode -c "gem install rails webdrivers"

src/ruby-rails-postgres/.devcontainer/docker-compose.yml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
version: '3'
1+
# Dev Container Docker Compose Configuration for Ruby on Rails with PostgreSQL
2+
# This configuration has been optimized for reliability in automated and remote environments
23

34
services:
45
app:
@@ -12,17 +13,36 @@ services:
1213
# Overrides default command so things don't shut down after the process ends.
1314
command: sleep infinity
1415

15-
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
16-
network_mode: service:db
16+
# Database connection string for Rails applications
17+
# Provides a standard way to connect to the PostgreSQL database
18+
environment:
19+
DATABASE_URL: "postgresql://postgres:postgres@db:5432/postgres"
1720

21+
# Use proper Docker networking (not network_mode) to avoid namespace issues and ensure reliable container startup across environments
22+
depends_on:
23+
db:
24+
condition: service_healthy # Wait for PostgreSQL to be ready before starting the app
25+
networks:
26+
- app-network # Connect to custom bridge network for service communication
1827
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
1928
# (Adding the "ports" property to this file will not forward from a Codespace.)
2029

2130
db:
2231
image: postgres:latest
2332
restart: unless-stopped
33+
networks:
34+
- app-network # Connect to the same network as the app container
35+
36+
# Health check ensures PostgreSQL is ready before dependent services start
37+
# This is critical for depends_on with condition: service_healthy to work properly
38+
healthcheck:
39+
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
40+
interval: 10s # Check every 10 seconds
41+
timeout: 5s # Wait up to 5 seconds for response
42+
retries: 5 # Retry 5 times before marking as unhealthy
43+
start_period: 30s # Give PostgreSQL 30 seconds to start before health checks begin
2444
volumes:
25-
- postgres-data:/var/lib/postgresql/data
45+
- postgres-data:/var/lib/postgresql
2646
- ./create-db-user.sql:/docker-entrypoint-initdb.d/create-db-user.sql
2747
environment:
2848
POSTGRES_USER: postgres
@@ -53,5 +73,15 @@ services:
5373
# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
5474
# (Adding the "ports" property to this file will not forward from a Codespace.)
5575

76+
# Persistent storage for PostgreSQL data
5677
volumes:
5778
postgres-data:
79+
# Named volume ensures data persists across container restarts
80+
# Located at /var/lib/postgresql/data inside the container
81+
82+
# Custom bridge network for service communication
83+
# Replaces the problematic network_mode: service:db approach
84+
networks:
85+
app-network:
86+
driver: bridge # Standard bridge driver for container-to-container communication
87+
# Services on this network can communicate using service names (app -> db)

src/ruby-rails-postgres/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Develop Ruby on Rails applications with Postgres. Includes a Rails application c
77

88
| Options Id | Description | Type | Default Value |
99
|-----|-----|-----|-----|
10-
| imageVariant | Ruby version (use -trixie, -bookworm, -bullseye variants on local arm64/Apple Silicon) : | string | 3.4-trixie |
10+
| imageVariant | Ruby version (use -trixie, -bookworm, -bullseye variants on local arm64/Apple Silicon) : | string |4-trixie |
1111

1212
This template references an image that was [pre-built](https://containers.dev/implementors/reference/#prebuilding) to automatically include needed devcontainer.json metadata.
1313

src/ruby-rails-postgres/devcontainer-template.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "ruby-rails-postgres",
3-
"version": "5.0.0",
3+
"version": "6.0.0",
44
"name": "Ruby on Rails & Postgres",
55
"description": "Develop Ruby on Rails applications with Postgres. Includes a Rails application container and PostgreSQL server.",
66
"documentationURL": "https://github.com/devcontainers/templates/tree/main/src/ruby-rails-postgres",
@@ -9,23 +9,23 @@
99
"options": {
1010
"imageVariant": {
1111
"type": "string",
12-
"description": "Ruby version (use -bookworm, -bullseye variants on local arm64/Apple Silicon):",
12+
"description": "Ruby version (use - trixie, -bookworm, -bullseye variants on local arm64/Apple Silicon):",
1313
"proposals": [
14-
"3-trixie",
14+
"4-trixie",
1515
"3.4-trixie",
1616
"3.3-trixie",
1717
"3.2-trixie",
18-
"3-bookworm",
18+
"4-bookworm",
1919
"3.4-bookworm",
2020
"3.3-bookworm",
2121
"3.2-bookworm",
22-
"3-bullseye",
22+
"4-bullseye",
2323
"3.4-bullseye",
2424
"3.3-bullseye",
2525
"3.2-bullseye"
2626
],
27-
"default": "3.4-trixie"
28-
}
27+
"default": "4-trixie"
28+
}
2929
},
3030
"platforms": ["Ruby"],
3131
"optionalPaths": [

src/ruby/.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"name": "Ruby",
55
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6-
"image": "mcr.microsoft.com/devcontainers/ruby:2-${templateOption:imageVariant}"
6+
"image": "mcr.microsoft.com/devcontainers/ruby:3-${templateOption:imageVariant}"
77

88
// Features to add to the dev container. More info: https://containers.dev/features.
99
// "features": {},

src/ruby/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Develop Ruby based applications. includes everything you need to get up and runn
77

88
| Options Id | Description | Type | Default Value |
99
|-----|-----|-----|-----|
10-
| imageVariant | Ruby version (use -trixie, -bookworm, -bullseye variants on local arm64/Apple Silicon) : | string | 3.4-trixie |
10+
| imageVariant | Ruby version (use -trixie, -bookworm, -bullseye variants on local arm64/Apple Silicon) : | string |4-trixie |
1111

1212
This template references an image that was [pre-built](https://containers.dev/implementors/reference/#prebuilding) to automatically include needed devcontainer.json metadata.
1313

src/ruby/devcontainer-template.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "ruby",
3-
"version": "5.0.0",
3+
"version": "6.0.0",
44
"name": "Ruby",
55
"description": "Develop Ruby based applications. includes everything you need to get up and running.",
66
"documentationURL": "https://github.com/devcontainers/templates/tree/main/src/ruby",
@@ -11,20 +11,20 @@
1111
"type": "string",
1212
"description": "Ruby version (use -trixie, -bookworm, -bullseye variants on local arm64/Apple Silicon):",
1313
"proposals": [
14-
"3-trixie",
14+
"4-trixie",
1515
"3.4-trixie",
1616
"3.3-trixie",
1717
"3.2-trixie",
18-
"3-bookworm",
18+
"4-bookworm",
1919
"3.4-bookworm",
2020
"3.3-bookworm",
2121
"3.2-bookworm",
22-
"3-bullseye",
22+
"4-bullseye",
2323
"3.4-bullseye",
2424
"3.3-bullseye",
2525
"3.2-bullseye"
2626
],
27-
"default": "3.4-trixie"
27+
"default": "4-trixie"
2828
}
2929
},
3030
"platforms": ["Ruby"],

test/ruby-rails-postgres/test.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ fixTestProjectFolderPrivs
1010
# Run common tests
1111
checkCommon
1212

13+
1314
# Run devcontainer specific tests
1415
check "rails" rails --version
1516
check "rails installation path" gem which rails
1617
check "user has write permission to rvm gems" [ -w /usr/local/rvm/gems ]
1718
check "user has write permission to rvm gems default" [ -w /usr/local/rvm/gems/default ]
1819
check "user can install gems" gem install github-markup
20+
check "gem command works" gem --version
21+
check "user can install gems" gem install github-markup
22+
check "Bundler gem presence " gem list | grep -q "bundler"
23+
1924

2025
# Report result
2126
reportResults

0 commit comments

Comments
 (0)