Skip to content

Commit 37bad60

Browse files
authored
Merge pull request #10 from speee/docker-support-speee
Add Docker support for multi-version Rails testing
2 parents 7a7b80e + 49d75c6 commit 37bad60

8 files changed

Lines changed: 270 additions & 2 deletions

File tree

.dockerignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Git
2+
.git
3+
.gitignore
4+
.github
5+
6+
# Claude/AI configuration
7+
.claude
8+
.serena
9+
CLAUDE.md
10+
11+
# Documentation
12+
*.md
13+
!README.md
14+
15+
# Test artifacts
16+
coverage/
17+
test_db
18+
*.sqlite3
19+
.last_run.json
20+
.resultset.json
21+
22+
# Ruby/bundler
23+
.bundle
24+
vendor/bundle
25+
26+
# OS files
27+
.DS_Store
28+
Thumbs.db
29+
30+
# Editor files
31+
.vscode
32+
.idea
33+
*.swp
34+
*.swo
35+
*~

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Gemfile.lock
99
InstalledFiles
1010
_yardoc
11-
coverage
11+
coverage/
1212
doc/
1313
lib/bundler/man
1414
pkg
@@ -17,10 +17,11 @@ spec/reports
1717
test/tmp
1818
test/version_tmp
1919
tmp
20-
coverage
2120
test/log
2221
log/*.log
2322
test_db
2423
test_db-journal
24+
test/test_db-shm
25+
test/test_db-wal
2526
.idea
2627
*.iml

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Dockerfile for testing jsonapi-resources with multiple Rails versions
2+
3+
FROM ruby:3.2
4+
5+
# Install dependencies
6+
RUN apt-get update -qq && \
7+
apt-get install -y build-essential libpq-dev nodejs && \
8+
apt-get clean && \
9+
rm -rf /var/lib/apt/lists/*
10+
11+
# Set working directory
12+
WORKDIR /app
13+
14+
# Copy Gemfile and gemspec
15+
COPY Gemfile jsonapi-resources.gemspec ./
16+
COPY lib/jsonapi/resources/version.rb ./lib/jsonapi/resources/
17+
18+
# Install bundler
19+
RUN gem install bundler
20+
21+
# Note: bundle install will happen at runtime with specific RAILS_VERSION
22+
# This allows testing multiple Rails versions without rebuilding the image

Dockerfile.ruby2.7

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Dockerfile for testing jsonapi-resources with Rails 5.1-7.0 (Ruby 2.7)
2+
3+
FROM ruby:2.7
4+
5+
# Install dependencies
6+
RUN apt-get update -qq && \
7+
apt-get install -y build-essential libpq-dev nodejs && \
8+
apt-get clean && \
9+
rm -rf /var/lib/apt/lists/*
10+
11+
# Set working directory
12+
WORKDIR /app
13+
14+
# Copy Gemfile and gemspec
15+
COPY Gemfile jsonapi-resources.gemspec ./
16+
COPY lib/jsonapi/resources/version.rb ./lib/jsonapi/resources/
17+
18+
# Install bundler (Ruby 2.7 requires bundler < 2.5)
19+
RUN gem install bundler -v 2.4.22
20+
21+
# Note: bundle install will happen at runtime with specific RAILS_VERSION
22+
# This allows testing multiple Rails versions without rebuilding the image

Dockerfile.ruby3.1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Dockerfile for testing jsonapi-resources with Rails 6.1-8.1 (Ruby 3.1.5)
2+
3+
FROM ruby:3.1.5
4+
5+
# Install dependencies
6+
RUN apt-get update -qq && \
7+
apt-get install -y build-essential libpq-dev nodejs && \
8+
apt-get clean && \
9+
rm -rf /var/lib/apt/lists/*
10+
11+
# Set working directory
12+
WORKDIR /app
13+
14+
# Copy Gemfile and gemspec
15+
COPY Gemfile jsonapi-resources.gemspec ./
16+
COPY lib/jsonapi/resources/version.rb ./lib/jsonapi/resources/
17+
18+
# Install specific bundler version for compatibility
19+
RUN gem install bundler -v 2.4.14 --no-document && \
20+
gem install bundler -v 2.4.14 --install-dir /usr/local/bundle --no-document && \
21+
bundle --version
22+
23+
# Note: bundle install will happen at runtime with specific RAILS_VERSION
24+
# This allows testing multiple Rails versions without rebuilding the image

Dockerfile.ruby3.4

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Dockerfile for testing jsonapi-resources with Rails 8.0-8.1 (Ruby 3.4)
2+
3+
FROM ruby:3.4
4+
5+
# Install dependencies
6+
RUN apt-get update -qq && \
7+
apt-get install -y build-essential libpq-dev nodejs && \
8+
apt-get clean && \
9+
rm -rf /var/lib/apt/lists/*
10+
11+
# Set working directory
12+
WORKDIR /app
13+
14+
# Copy Gemfile and gemspec
15+
COPY Gemfile jsonapi-resources.gemspec ./
16+
COPY lib/jsonapi/resources/version.rb ./lib/jsonapi/resources/
17+
18+
# Install specific bundler version for compatibility
19+
RUN gem install bundler -v 2.4.14 --no-document && \
20+
gem install bundler -v 2.4.14 --install-dir /usr/local/bundle --no-document && \
21+
bundle --version
22+
23+
# Note: bundle install will happen at runtime with specific RAILS_VERSION
24+
# This allows testing multiple Rails versions without rebuilding the image

docker-compose.yml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
services:
2+
# Base service definition for Ruby 3.1.5 (Rails 6.1-8.1)
3+
test-base: &test-base
4+
build:
5+
context: .
6+
dockerfile: Dockerfile.ruby3.1
7+
volumes:
8+
- .:/app
9+
- bundle-cache-ruby31:/usr/local/bundle
10+
working_dir: /app
11+
stdin_open: true
12+
tty: true
13+
14+
# Base service definition for Ruby 2.7 (Rails 5.1-6.0)
15+
test-base-ruby27: &test-base-ruby27
16+
build:
17+
context: .
18+
dockerfile: Dockerfile.ruby2.7
19+
volumes:
20+
- .:/app
21+
- bundle-cache-ruby27:/usr/local/bundle
22+
working_dir: /app
23+
stdin_open: true
24+
tty: true
25+
26+
# Base service definition for Ruby 3.4 (Rails 8.0-8.1)
27+
test-base-ruby34: &test-base-ruby34
28+
build:
29+
context: .
30+
dockerfile: Dockerfile.ruby3.4
31+
volumes:
32+
- .:/app
33+
- bundle-cache-ruby34:/usr/local/bundle
34+
working_dir: /app
35+
stdin_open: true
36+
tty: true
37+
38+
# Rails 5.1.7
39+
rails-5.1:
40+
<<: *test-base-ruby27
41+
container_name: jsonapi-rails-5.1
42+
environment:
43+
- RAILS_VERSION=5.1.7
44+
command: bash -c "rm -f Gemfile.lock && bundle install && bundle exec rake test"
45+
46+
# Rails 5.2.8.1
47+
rails-5.2:
48+
<<: *test-base-ruby27
49+
container_name: jsonapi-rails-5.2
50+
environment:
51+
- RAILS_VERSION=5.2.8.1
52+
command: bash -c "rm -f Gemfile.lock && bundle install && bundle exec rake test"
53+
54+
# Rails 6.0.6
55+
rails-6.0:
56+
<<: *test-base-ruby27
57+
container_name: jsonapi-rails-6.0
58+
environment:
59+
- RAILS_VERSION=6.0.6
60+
command: bash -c "rm -f Gemfile.lock && bundle install && bundle exec rake test"
61+
62+
# Rails 6.1.7.10
63+
rails-6.1:
64+
<<: *test-base
65+
container_name: jsonapi-rails-6.1
66+
environment:
67+
- RAILS_VERSION=6.1.7.10
68+
command: bash -c "rm -f Gemfile.lock && /usr/local/bin/bundler _2.4.14_ install && /usr/local/bin/bundler _2.4.14_ exec rake test"
69+
70+
# Rails 7.0.10
71+
rails-7.0:
72+
<<: *test-base
73+
container_name: jsonapi-rails-7.0
74+
environment:
75+
- RAILS_VERSION=7.0.10
76+
command: bash -c "rm -f Gemfile.lock && /usr/local/bin/bundler _2.4.14_ install && /usr/local/bin/bundler _2.4.14_ exec rake test"
77+
78+
# Rails 7.1.6
79+
rails-7.1:
80+
<<: *test-base
81+
container_name: jsonapi-rails-7.1
82+
environment:
83+
- RAILS_VERSION=7.1.6
84+
command: bash -c "rm -f Gemfile.lock && /usr/local/bin/bundler _2.4.14_ install && /usr/local/bin/bundler _2.4.14_ exec rake test"
85+
86+
# Rails 7.2.3
87+
rails-7.2:
88+
<<: *test-base
89+
container_name: jsonapi-rails-7.2
90+
environment:
91+
- RAILS_VERSION=7.2.3
92+
command: bash -c "rm -f Gemfile.lock && /usr/local/bin/bundler _2.4.14_ install && /usr/local/bin/bundler _2.4.14_ exec rake test"
93+
94+
# Rails 8.0.4 (Ruby 3.4 required)
95+
rails-8.0:
96+
<<: *test-base-ruby34
97+
container_name: jsonapi-rails-8.0
98+
environment:
99+
- RAILS_VERSION=8.0.4
100+
command: bash -c "rm -f Gemfile.lock && /usr/local/bin/bundler _2.4.14_ install && /usr/local/bin/bundler _2.4.14_ exec rake test"
101+
102+
# Rails 8.1.2 (Ruby 3.4 required)
103+
rails-8.1:
104+
<<: *test-base-ruby34
105+
container_name: jsonapi-rails-8.1
106+
environment:
107+
- RAILS_VERSION=8.1.2
108+
command: bash -c "rm -f Gemfile.lock && /usr/local/bin/bundler _2.4.14_ install && /usr/local/bin/bundler _2.4.14_ exec rake test"
109+
110+
# Interactive shell for debugging (defaults to Rails 8.1)
111+
shell:
112+
<<: *test-base
113+
container_name: jsonapi-shell
114+
environment:
115+
- RAILS_VERSION=${RAILS_VERSION:-8.1.2}
116+
command: /bin/bash
117+
118+
volumes:
119+
bundle-cache-ruby31:
120+
bundle-cache-ruby27:
121+
bundle-cache-ruby34:

test/test_helper.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@ class TestApp < Rails::Application
7878
require 'jsonapi-resources'
7979
require 'pry'
8080

81+
# Fix Psych::DisallowedClass error for Rails 6.0 with Ruby 2.7+
82+
# In test environment, allow all classes from YAML (safe for test fixtures)
83+
if defined?(Psych::VERSION) && Psych::VERSION.to_f >= 3.1 && Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR == 0
84+
require 'psych'
85+
86+
# Patch Psych.load to use unsafe_load in test environment
87+
# This is safe because we're only loading trusted test fixtures
88+
module Psych
89+
class << self
90+
alias_method :safe_load_original, :load
91+
92+
def load(yaml, *args, **kwargs)
93+
# Use unsafe_load to allow Date, Time, DateTime from YAML
94+
unsafe_load(yaml)
95+
end
96+
end
97+
end
98+
end
99+
81100
require File.expand_path('../helpers/value_matchers', __FILE__)
82101
require File.expand_path('../helpers/assertions', __FILE__)
83102
require File.expand_path('../helpers/functional_helpers', __FILE__)

0 commit comments

Comments
 (0)