From dcf050b4d1b4f6e732856f468683a1d252ceea73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 18 Jul 2025 19:52:38 +0000 Subject: [PATCH 1/5] Fix devcontainer config --- .devcontainer/{.devcontainer.json => devcontainer.json} | 0 Gemfile.lock | 3 +++ 2 files changed, 3 insertions(+) rename .devcontainer/{.devcontainer.json => devcontainer.json} (100%) diff --git a/.devcontainer/.devcontainer.json b/.devcontainer/devcontainer.json similarity index 100% rename from .devcontainer/.devcontainer.json rename to .devcontainer/devcontainer.json diff --git a/Gemfile.lock b/Gemfile.lock index c97dae35..c9f7e763 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -94,6 +94,8 @@ GEM mutex_m (0.3.0) mysql2 (0.5.6) nio4r (2.7.4) + nokogiri (1.18.0-aarch64-linux-gnu) + racc (~> 1.4) nokogiri (1.18.0-arm64-darwin) racc (~> 1.4) nokogiri (1.18.0-x86_64-darwin) @@ -185,6 +187,7 @@ GEM zeitwerk (2.6.0) PLATFORMS + aarch64-linux arm64-darwin-22 arm64-darwin-23 arm64-darwin-24 From ef422265defc3734e29abc851fc414bdb5aec4f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 18 Jul 2025 20:03:25 +0000 Subject: [PATCH 2/5] Make sure the devcontainer can install all gems --- .devcontainer/Dockerfile | 1 + .devcontainer/devcontainer.json | 12 +++++++++--- Gemfile.lock | 7 ++++--- 3 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 .devcontainer/Dockerfile diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..cfe9b96c --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1 @@ +FROM ghcr.io/rails/devcontainer/images/ruby:3.3.5 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9ab714fc..4b38b298 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,12 +3,18 @@ { "name": "solid_queue", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "ghcr.io/rails/devcontainer/images/ruby:3.3.5", + "build": { + "dockerfile": "Dockerfile" + }, // Features to add to the dev container. More info: https://containers.dev/features. "features": { "ghcr.io/devcontainers/features/github-cli:1": { "version": "latest" - } + }, + "ghcr.io/rails/devcontainer/features/postgres-client": { + "version": "15" + }, + "ghcr.io/rails/devcontainer/features/mysql-client": {} } // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], @@ -18,4 +24,4 @@ // "customizations": {}, // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. // "remoteUser": "root" -} \ No newline at end of file +} diff --git a/Gemfile.lock b/Gemfile.lock index c9f7e763..bd3a369d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -87,7 +87,6 @@ GEM loofah (2.23.1) crass (~> 1.0.2) nokogiri (>= 1.12.0) - mini_portile2 (2.8.8) minitest (5.25.4) mocha (2.1.0) ruby2_keywords (>= 0.0.5) @@ -174,8 +173,10 @@ GEM ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) securerandom (0.4.1) - sqlite3 (1.5.4) - mini_portile2 (~> 2.8.0) + sqlite3 (2.7.3-aarch64-linux-gnu) + sqlite3 (2.7.3-arm64-darwin) + sqlite3 (2.7.3-x86_64-darwin) + sqlite3 (2.7.3-x86_64-linux-gnu) stringio (3.1.2) thor (1.3.2) timeout (0.4.3) From c179f284f2e8204c8e9526068f92c93c04766098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 18 Jul 2025 20:06:51 +0000 Subject: [PATCH 3/5] Make sure docker-compose is available in the devcontainer This is required to run the tests. --- .devcontainer/devcontainer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4b38b298..96f8bcfe 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -8,6 +8,7 @@ }, // Features to add to the dev container. More info: https://containers.dev/features. "features": { + "ghcr.io/devcontainers/features/docker-in-docker": {}, "ghcr.io/devcontainers/features/github-cli:1": { "version": "latest" }, From b3fdee5b359487ff285fe0db7dc8b3759431a2ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 18 Jul 2025 20:16:34 +0000 Subject: [PATCH 4/5] Don't reset all 3 databases in setup Just reset the current database selected. --- Rakefile | 17 +++++++++++++++++ bin/setup | 4 +--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index 951e3527..2a72f704 100644 --- a/Rakefile +++ b/Rakefile @@ -19,3 +19,20 @@ task :test do sh("TARGET_DB=#{database} bin/rails test") end end + +namespace :test do + task :mysql do + sh("TARGET_DB=mysql bin/setup") + sh("TARGET_DB=mysql bin/rails test") + end + + task :postgres do + sh("TARGET_DB=postgres bin/setup") + sh("TARGET_DB=postgres bin/rails test") + end + + task :sqlite do + sh("TARGET_DB=sqlite bin/setup") + sh("TARGET_DB=sqlite bin/rails test") + end +end diff --git a/bin/setup b/bin/setup index 5fbe3e57..3c1f24eb 100755 --- a/bin/setup +++ b/bin/setup @@ -15,6 +15,4 @@ bundle echo "Creating databases..." -rails db:reset TARGET_DB=sqlite -rails db:reset TARGET_DB=mysql -rails db:reset TARGET_DB=postgres +rails db:reset From d870557299d363af851100c6150f61714e334b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 18 Jul 2025 20:30:57 +0000 Subject: [PATCH 5/5] Improve the Rakefile adding a TaskLib --- Rakefile | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/Rakefile b/Rakefile index 2a72f704..bdb0ea23 100644 --- a/Rakefile +++ b/Rakefile @@ -8,31 +8,36 @@ load "rails/tasks/engine.rake" load "rails/tasks/statistics.rake" require "bundler/gem_tasks" +require "rake/tasklib" -def databases - %w[ mysql postgres sqlite ] -end - -task :test do - databases.each do |database| - sh("TARGET_DB=#{database} bin/setup") - sh("TARGET_DB=#{database} bin/rails test") +class TestHelpers < Rake::TaskLib + def initialize(databases) + @databases = databases + define end -end -namespace :test do - task :mysql do - sh("TARGET_DB=mysql bin/setup") - sh("TARGET_DB=mysql bin/rails test") + def define + desc "Run tests for all databases (mysql, postgres, sqlite)" + task :test do + @databases.each { |database| run_test_for_database(database) } + end + + namespace :test do + @databases.each do |database| + desc "Run tests for #{database} database" + task database do + run_test_for_database(database) + end + end + end end - task :postgres do - sh("TARGET_DB=postgres bin/setup") - sh("TARGET_DB=postgres bin/rails test") - end + private - task :sqlite do - sh("TARGET_DB=sqlite bin/setup") - sh("TARGET_DB=sqlite bin/rails test") + def run_test_for_database(database) + sh("TARGET_DB=#{database} bin/setup") + sh("TARGET_DB=#{database} bin/rails test") end end + +TestHelpers.new(%w[ mysql postgres sqlite ])