lib/generators/dockerfile_generator.rb in dockerfile-rails-1.2.2 vs lib/generators/dockerfile_generator.rb in dockerfile-rails-1.2.3

- old
+ new

@@ -12,10 +12,11 @@ "ci" => false, "compose" => false, "fullstaq" => false, "jemalloc" => false, "label" => {}, + "lock" => true, "mysql" => false, "nginx" => false, "parallel" => false, "platform" => nil, "postgresql" => false, @@ -65,10 +66,13 @@ end class_option :ci, type: :boolean, default: OPTION_DEFAULTS.ci, desc: "include test gems in bundle" + class_option :lock, type: :boolean, default: OPTION_DEFAULTS.lock, + desc: "lock Gemfile/package.json" + class_option :precompile, type: :string, default: OPTION_DEFAULTS.precompile, desc: 'if set to "defer", assets:precompile will be done at deploy time' class_option "bin-cd", type: :boolean, default: OPTION_DEFAULTS["bin-cd"], desc: "modify binstubs to set working directory" @@ -250,11 +254,11 @@ ERB.new(template, trim_mode: "-").result(scope.get_binding).strip end def platform if options.platform - "--platform #{options.platform} " + "--platform=#{options.platform} " else "" end end @@ -293,36 +297,51 @@ end def install_gems ENV["BUNDLE_IGNORE_MESSAGES"] = "1" + gemfile = IO.read("Gemfile") + if options.postgresql? || @postgresql - system "bundle add pg" unless @gemfile.include? "pg" + system "bundle add pg --skip-install" unless @gemfile.include? "pg" end if options.mysql? || @mysql - system "bundle add mysql2" unless @gemfile.include? "mysql2" + system "bundle add mysql2 --skip-install" unless @gemfile.include? "mysql2" end if options.redis? || using_redis? - system "bundle add redis" unless @gemfile.include? "redis" + system "bundle add redis --skip-install" unless @gemfile.include? "redis" end - # ensure linux platform is in the bundle lock - current_platforms = `bundle platform` - add_platforms = [] - - if !current_platforms.include?("x86_64-linux") - add_platforms += ["--add-platform=x86_64-linux"] + # https://stackoverflow.com/questions/70500220/rails-7-ruby-3-1-loaderror-cannot-load-such-file-net-smtp/70500221#70500221 + if @gemfile.include? "mail" + %w(net-smtp net-imap net-pop).each do |gem| + system "bundle add #{gem} --skip-install --require false" unless @gemfile.include? gem + end end - if !current_platforms.include?("aarch64-linux") && RUBY_PLATFORM.start_with?("arm64") - add_platforms += ["--add-platform=aarch64-linux"] + unless gemfile == IO.read("Gemfile") + system "bundle install --quiet" end - unless add_platforms.empty? - system "bundle lock #{add_platforms.join(" ")}" + if options.lock? + # ensure linux platform is in the bundle lock + current_platforms = `bundle platform` + add_platforms = [] + + if !current_platforms.include?("x86_64-linux") + add_platforms += ["--add-platform=x86_64-linux"] + end + + if !current_platforms.include?("aarch64-linux") && RUBY_PLATFORM.start_with?("arm64") + add_platforms += ["--add-platform=aarch64-linux"] + end + + unless add_platforms.empty? + system "bundle lock #{add_platforms.join(" ")}" + end end end def base_packages packages = [] @@ -368,13 +387,10 @@ packages << "default-libmysqlclient-dev" if options.mysql? || @mysql # add git if needed to install gems packages << "git" if @git - # add redis if Action Cable, caching, or sidekiq are used - packages << "redis" if options.redis? || using_redis? - # ActiveStorage preview support packages << "libvips" if @gemfile.include? "ruby-vips" # Rmagick gem packages += %w[pkg-config libmagickwand-dev] if @gemfile.include? "rmagick" @@ -416,13 +432,10 @@ # start with databases: sqlite3, postgres, mysql packages << "libsqlite3-0" if options.sqlite3? || @sqlite3 packages << "postgresql-client" if options.postgresql? || @postgresql packages << "default-mysql-client" if options.mysql || @mysql - # add redis in case Action Cable, caching, or sidekiq are added later - packages << "redis" if using_redis? - # ActiveStorage preview support packages << "libvips" if @gemfile.include? "ruby-vips" # Rmagick gem if @gemfile.include?("rmagick") || @gemfile.include?("mini_magick") @@ -463,12 +476,15 @@ end def base_env env = { "RAILS_ENV" => "production", - "BUNDLE_DEPLOYMENT" => "1", "BUNDLE_WITHOUT" => options.ci? ? "development" : "development:test" } + + if options.lock? + env["BUNDLE_DEPLOYMENT"] = "1" + end if @@args["base"] env.merge! @@args["base"].to_h { |key, value| [key, "$#{key}"] } end