Skip to content

Commit 5fcbc2c

Browse files
committed
Update the Rails app devcontainer to use the Rail's orgs ruby image
1 parent 6b5f058 commit 5fcbc2c

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

railties/lib/rails/generators/devcontainer.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ module Rails
44
module Generators
55
module Devcontainer
66
private
7-
def devcontainer_ruby_version
8-
gem_ruby_version.to_s.match(/^\d+\.\d+/).to_s
9-
end
10-
117
def devcontainer_dependencies
128
return @devcontainer_dependencies if @devcontainer_dependencies
139

@@ -63,6 +59,13 @@ def db_volume_name_for_devcontainer(database = options[:database])
6359
end
6460
end
6561

62+
def db_package_for_dockerfile(database = options[:database])
63+
case database
64+
when "mysql" then "default-libmysqlclient-dev"
65+
when "postgresql" then "libpq-dev"
66+
end
67+
end
68+
6669
def devcontainer_db_service_yaml(**options)
6770
return unless service = db_service_for_devcontainer
6871

railties/lib/rails/generators/rails/app/templates/.devcontainer/Dockerfile.tt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
2-
ARG RUBY_VERSION=<%= devcontainer_ruby_version %>
3-
FROM mcr.microsoft.com/devcontainers/ruby:1-$RUBY_VERSION-bookworm
2+
ARG RUBY_VERSION=<%= gem_ruby_version %>
3+
FROM ghcr.io/rails/devcontainer/images/ruby:$RUBY_VERSION
44

55
<%- unless options.skip_active_storage -%>
66
# Install packages needed to build gems
77
RUN apt-get update -qq && \
88
apt-get install --no-install-recommends -y \
9-
libvips \
9+
<%= db_package_for_dockerfile %> libvips \
1010
# For video thumbnails
1111
ffmpeg \
1212
# For pdf thumbnails. If you want to use mupdf instead of poppler,

railties/test/generators/app_generator_test.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,8 +1011,7 @@ def test_inclusion_of_ruby_version
10111011
ruby_version = "#{Gem::Version.new(Gem::VERSION) >= Gem::Version.new("3.3.13") ? Gem.ruby_version : RUBY_VERSION}"
10121012

10131013
assert_file ".devcontainer/Dockerfile" do |content|
1014-
minor_ruby_version = ruby_version.match(/^\d+\.\d+/).to_s
1015-
assert_match(/ARG RUBY_VERSION=#{minor_ruby_version}$/, content)
1014+
assert_match(/ARG RUBY_VERSION=#{ruby_version}$/, content)
10161015
end
10171016
assert_file "Dockerfile" do |content|
10181017
assert_match(/ARG RUBY_VERSION=#{ruby_version}/, content)
@@ -1320,6 +1319,9 @@ def test_devonctainer_postgresql
13201319
assert_file("config/database.yml") do |content|
13211320
assert_match(/host: <%= ENV\["DB_HOST"\] %>/, content)
13221321
end
1322+
assert_file(".devcontainer/Dockerfile") do |content|
1323+
assert_match(/libpq-dev/, content)
1324+
end
13231325
end
13241326

13251327
def test_devonctainer_mysql
@@ -1348,6 +1350,9 @@ def test_devonctainer_mysql
13481350
assert_file("config/database.yml") do |content|
13491351
assert_match(/host: <%= ENV.fetch\("DB_HOST"\) \{ "localhost" } %>/, content)
13501352
end
1353+
assert_file(".devcontainer/Dockerfile") do |content|
1354+
assert_match(/default-libmysqlclient-dev/, content)
1355+
end
13511356
end
13521357

13531358
def test_devonctainer_mariadb

0 commit comments

Comments
 (0)