Skip to content

Add Docker support for multi-version Rails testing#10

Merged
takaokouji merged 10 commits intomasterfrom
docker-support-speee
Jan 20, 2026
Merged

Add Docker support for multi-version Rails testing#10
takaokouji merged 10 commits intomasterfrom
docker-support-speee

Conversation

@takaokouji
Copy link
Collaborator

Summary

This PR adds Docker support to enable easy testing across multiple Rails versions in isolated environments.

Changes

Docker Configuration

  • Dockerfile: Ruby 3.2 base image with required dependencies (SQLite, PostgreSQL client, git)
  • docker-compose.yml: Service definitions for multiple Rails versions
  • .dockerignore: Optimized Docker context by excluding unnecessary files

Docker Services Available

The docker-compose.yml provides services for testing with:

  • Rails 6.1
  • Rails 7.0
  • And easily extensible for additional versions

Usage Examples

# Test with specific Rails version
docker-compose run rails-6.1
docker-compose run rails-7.0

# Interactive shell with specific Rails version
docker-compose run shell
RAILS_VERSION=7.0.10 docker-compose run shell

# Run tests in interactive shell
docker-compose run shell
# Inside container:
bundle update
bundle exec rake test

# Build/rebuild images
docker-compose build

# Clean up
docker-compose down -v

Other Changes

  • Updated .gitignore to use coverage/ directory pattern and removed duplicate entry

Benefits

  1. Consistent Development Environment: All developers use the same Ruby and system dependencies
  2. Easy Version Testing: Quick switching between Rails versions without affecting local setup
  3. CI/CD Ready: Docker images can be used in CI pipelines
  4. Isolated Testing: Each Rails version runs in its own container
  5. Documentation: Clear examples for using Docker in development

Testing

Tested with:

  • Rails 6.1.7.10 ✅
  • Rails 7.0.10 ✅

Related

This Docker setup complements the Rails 7.1-8.1 support added in #9, providing a convenient way to test across the expanded version matrix.


🤖 Generated with Claude Code

takaokouji and others added 10 commits January 20, 2026 19:41
- Add Dockerfile with Ruby 3.2 and required dependencies
- Add docker-compose.yml with services for Rails 6.1 and 7.0
- Add .dockerignore to exclude unnecessary files from Docker context
- Update .gitignore to use coverage/ directory and remove duplicate entry

This provides an easy way to test the gem with different Rails versions
in isolated Docker environments.
Expand docker-compose.yml to include services for all supported
Rails versions from the CI matrix:

Services added:
- rails-7.1: Rails 7.1.6
- rails-7.2: Rails 7.2.3
- rails-8.0: Rails 8.0.4
- rails-8.1: Rails 8.1.2

Updated services:
- rails-6.1: 6.1.7 → 6.1.7.10
- rails-7.0: 7.0.4 → 7.0.10
- shell: default Rails version 6.1.7 → 8.1.2

Usage:
  docker-compose run rails-7.1
  docker-compose run rails-7.2
  docker-compose run rails-8.0
  docker-compose run rails-8.1

This matches the expanded CI matrix and enables local testing
across all supported Rails versions.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Change command from "bundle update" to "rm -f Gemfile.lock && bundle install"
to avoid dependency conflicts between different Rails versions.

With "bundle update", the existing Gemfile.lock would cause version
resolution failures when switching between Rails versions, especially
when both activerecord and railties are specified with different
version requirements.

Removing Gemfile.lock ensures each container gets the correct
dependencies for its specified RAILS_VERSION environment variable.

Tested and verified all services pass:
- Rails 6.1.7.10: 674 runs, 8772 assertions, 0 failures ✅
- Rails 7.0.10: 674 runs, 8772 assertions, 0 failures ✅
- Rails 7.1.6: 674 runs, 8772 assertions, 0 failures ✅
- Rails 7.2.3: 674 runs, 8772 assertions, 0 failures ✅
- Rails 8.0.4: 674 runs, 8772 assertions, 0 failures ✅
- Rails 8.1.2: 674 runs, 8772 assertions, 0 failures ✅

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add test/test_db-shm and test/test_db-wal to .gitignore to exclude
SQLite Write-Ahead Logging (WAL) mode files that are created during
test execution.

These files are temporary database files created by SQLite when WAL
mode is enabled and should not be tracked in version control.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add Docker Compose services for older Rails versions to enable
comprehensive testing across the full compatibility matrix:

Services added:
- rails-5.1: Rails 5.1.7
- rails-5.2: Rails 5.2.8.1
- rails-6.0: Rails 6.0.6

Usage:
  docker-compose run rails-5.1
  docker-compose run rails-5.2
  docker-compose run rails-6.0

This completes the Docker setup for all Rails versions supported
in the CI matrix (5.1.7 through 8.1.2).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add Dockerfile.ruby2.7 to support older Rails versions that are not
compatible with Ruby 3.2. Based on CI matrix compatibility:

Ruby 2.7 supports:
- Rails 5.1.7 ✅
- Rails 5.2.8.1 ✅
- Rails 6.0.6 ✅
- Rails 6.1.7.10 (also works with Ruby 3.2)
- Rails 7.0.10 (also works with Ruby 3.2)

Ruby 3.2 (existing Dockerfile):
- Rails 6.1.7.10 ✅
- Rails 7.0.10 ✅
- Rails 7.1.6 ✅
- Rails 7.2.3 ✅
- Rails 8.0.4 ✅
- Rails 8.1.2 ✅

Changes:
- Add Dockerfile.ruby2.7 with Ruby 2.7 base image
- Update docker-compose.yml to use Ruby 2.7 for Rails 5.1, 5.2, 6.0
- Add bundle-cache-ruby27 volume for separate gem caching
- Keep Ruby 3.2 for Rails 6.1-8.1

This ensures all Rails versions in the CI matrix can be tested locally
with the appropriate Ruby version.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Ruby 2.7 requires bundler < 2.5. Install bundler 2.4.22 specifically
to avoid compatibility issues.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add Psych patch to allow loading Date, Time, DateTime classes from
YAML fixtures in Rails 6.0 test environment.

Rails 6.0 + Ruby 2.7 combination uses Psych 3.1+, which introduced
stricter security for YAML.load. The default safe_load behavior
rejects Date/Time/DateTime classes, causing test fixtures to fail.

Solution: Patch Psych.load to use unsafe_load in test environment.
This is safe since we're only loading trusted test fixture files.

Fixes error:
  Psych::DisallowedClass: Tried to load unspecified class: Date

Test result: Rails 6.0.6 now passes all 674 tests ✅

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Replace Ruby 3.2 with Ruby 3.1.5 for Rails 6.1-8.1 testing.
This change will be validated by running tests on each version
sequentially.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Updated Docker configuration to use specific Ruby versions for each Rails version:
- Rails 5.1-6.0: Ruby 2.7 with bundler 2.4.22
- Rails 6.1-7.2: Ruby 3.1.5 with bundler 2.4.14
- Rails 8.0-8.1: Ruby 3.4 with bundler 2.4.14

Rails 8.0+ requires Ruby >= 3.2.0, so we use Ruby 3.4 for these versions.
All tests pass successfully for all 9 Rails versions.

Changes:
- Created Dockerfile.ruby3.1 for Ruby 3.1.5
- Created Dockerfile.ruby3.4 for Ruby 3.4
- Updated docker-compose.yml to use appropriate Ruby versions
- Added separate bundle cache volumes for each Ruby version

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@takaokouji takaokouji merged commit 37bad60 into master Jan 20, 2026
@takaokouji takaokouji deleted the docker-support-speee branch January 20, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant