Skip to content

expand check to match Rails generated Dockerfiles#148

Merged
rubys merged 4 commits intomainfrom
match-rails-dockerfiles
Feb 25, 2025
Merged

expand check to match Rails generated Dockerfiles#148
rubys merged 4 commits intomainfrom
match-rails-dockerfiles

Conversation

@rubys
Copy link
Contributor

@rubys rubys commented Feb 25, 2025

An example:

ARG RUBY_VERSION=3.4.2
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base

An example:
```
ARG RUBY_VERSION=3.4.2
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
```
@rubys rubys requested a review from albus522 February 25, 2025 13:56
Copy link
Collaborator

@albus522 albus522 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with possible suggestion

matching_ruby = [">= 3.4.2", "~> 3.3.7", "~> 3.2.7", "~> 3.1.7"].any? { |v| Gem::Requirement.new(v).satisfied_by?(Gem.ruby_version) }
# Only slim and alpine are missing libyaml-dev/yaml-dev
matching_image = /FROM ruby:.+-(alpine|slim)/i.match?(dockerfile)
matching_image = /FROM .*ruby:.+-(alpine|slim)/i.match?(dockerfile)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe?

Suggested change
matching_image = /FROM .*ruby:.+-(alpine|slim)/i.match?(dockerfile)
matching_image = /FROM .*\/ruby:.+-(alpine|slim)/i.match?(dockerfile)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That suggestion is wrong

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
matching_image = /FROM .*ruby:.+-(alpine|slim)/i.match?(dockerfile)
# https://rubular.com/r/Jb4LEfrMSmxkp9
matching_image = /FROM (.*\/)?ruby:(.+-)?(alpine|slim)/i.match?(dockerfile)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should do the trick:

@@ -418,7 +418,7 @@ class DockerfileGenerator < Rails::Generators::Base
       # Older versions no longer release new images
       matching_ruby = [">= 3.4.2", "~> 3.3.7", "~> 3.2.7", "~> 3.1.7"].any? { |v| Gem::Requirement.new(v).satisfied_by?(Gem.ruby_version) }
       # Only slim and alpine are missing libyaml-dev/yaml-dev
-      matching_image = /FROM .*ruby:.+-(alpine|slim)/i.match?(dockerfile)
+      matching_image = /FROM (|.+/)ruby:.+-(alpine|slim)/i.match?(dockerfile)

@albus522
Copy link
Collaborator

Did you notice my updated suggestion with test cases?

@rubys rubys merged commit 499267a into main Feb 25, 2025
8 checks passed
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.

2 participants