lib/generators/dockerfile_generator.rb in dockerfile-rails-0.0.1 vs lib/generators/dockerfile_generator.rb in dockerfile-rails-0.0.2
- old
+ new
@@ -1,8 +1,29 @@
class DockerfileGenerator < Rails::Generators::Base
include DockerfileRails::Scanner
+ class_option :ci, type: :boolean, default: false,
+ desc: 'include test gems in bundle'
+
+ class_option :cache, type: :boolean, default: false,
+ desc: 'use build cache to speed up installs'
+
+ class_option :parallel, type: :boolean, default: false,
+ desc: 'use build stages to install gems and node modules in parallel'
+
+ class_option :redit, type: :boolean, default: false,
+ desc: 'include redis libraries'
+
+ class_option :sqlite3, aliases: '--sqlite', type: :boolean, default: false,
+ desc: 'include sqlite3 libraries'
+
+ class_option :postgresql, aliases: '--postgres', type: :boolean, default: false,
+ desc: 'include postgresql libraries'
+
+ class_option :mysql, type: :boolean, default: false,
+ desc: 'include mysql libraries'
+
def generate_app
source_paths.push File.expand_path('./templates', __dir__)
scan_rails_app
@@ -16,34 +37,41 @@
end
private
def using_node?
- File.exist? 'package.json'
+ return @using_node if @using_node != nil
+ @using_node = File.exist? 'package.json'
end
+ def parallel?
+ using_node? && options.parallel
+ end
+
def keeps?
return @keeps if @keeps != nil
@keeps = !Dir['**/.keep']
end
def build_packages
# start with the essentials
packages = %w(build-essential)
# add databases: sqlite3, postgres, mysql
- packages += %w(pkg-config libpq-dev default-libmysqlclient-dev)
+ packages << 'pkg-config' if options.sqlite3? or @sqlite3
+ packages << 'libpq-dev' if options.postgresql? or @postgresql
+ packages << 'default-libmysqlclient-dev' if options.mysql or @mysql
# add redis in case Action Cable, caching, or sidekiq are added later
- packages << "redis"
+ packages << "redis" if options.redis? or @redis
# ActiveStorage preview support
packages << "libvips" if @gemfile.include? 'ruby-vips'
# node support, including support for building native modules
if using_node?
- packages += %w(curl node-gyp) # pkg-config already listed above
+ packages += %w(curl node-gyp pkg-config)
# module build process depends on Python, and debian changed
# how python is installed with the bullseye release. Below
# is based on debian release included with the Ruby images on
# Dockerhub.
@@ -61,19 +89,23 @@
else
packages << "python"
end
end
- packages.sort
+ packages.sort.uniq
end
def deploy_packages
+ packages = []
+
# start with databases: sqlite3, postgres, mysql
- packages = %w(libsqlite3-0 postgresql-client default-mysql-client)
+ packages << 'libsqlite3-0' if options.sqlite3? or @sqlite3
+ packages << 'postgresql-client' if options.postgresql? or @postgresql
+ packages << 'default-mysql-client' if options.mysql or @mysql
# add redis in case Action Cable, caching, or sidekiq are added later
- packages << "redis"
+ packages << "redis" if options.redis? or @redis
# ActiveStorage preview support
packages << "libvips" if @gemfile.include? 'ruby-vips'
packages.sort
@@ -124,7 +156,15 @@
@gemfile.include? 'bootstrap'
end
def api_only?
Rails.application.config.api_only
+ end
+
+ def dbprep_command
+ if Rails::VERSION::MAJOR >= 6
+ 'db:prepare'
+ else
+ 'db:migrate'
+ end
end
end
\ No newline at end of file