Module: OnContainer::Dev::SetupOps
- Defined in:
- lib/on_container/dev/setup_ops.rb
Constant Summary collapse
- APP_PATH =
File. '.'
- TRUEISH_VALUES =
%w[true True TRUE yes Yes YES].freeze
- SKIP_SETUP_ENV_VAR =
'ON_CONTAINER_SKIP_SETUP_LOCK'.freeze
Instance Method Summary collapse
- #app_setup_lock_path ⇒ Object
- #app_setup_wait ⇒ Object
- #app_temp_path ⇒ Object
- #command_might_require_database? ⇒ Boolean
- #command_requires_setup? ⇒ Boolean
- #lock_setup ⇒ Object
- #on_setup_lock_acquired ⇒ Object
- #unlock_setup ⇒ Object
- #wait_setup ⇒ Object
Instance Method Details
#app_setup_lock_path ⇒ Object
18 19 20 |
# File 'lib/on_container/dev/setup_ops.rb', line 18 def app_setup_lock_path "#{app_temp_path}/setup.lock" end |
#app_setup_wait ⇒ Object
14 15 16 |
# File 'lib/on_container/dev/setup_ops.rb', line 14 def app_setup_wait ENV.fetch('APP_SETUP_WAIT', '5').to_i end |
#app_temp_path ⇒ Object
10 11 12 |
# File 'lib/on_container/dev/setup_ops.rb', line 10 def app_temp_path "#{APP_PATH}/tmp" end |
#command_might_require_database? ⇒ Boolean
57 58 59 60 61 |
# File 'lib/on_container/dev/setup_ops.rb', line 57 def command_might_require_database? %w[ rails rspec sidekiq hutch puma rake ].include?(ARGV[0]) end |
#command_requires_setup? ⇒ Boolean
51 52 53 54 55 |
# File 'lib/on_container/dev/setup_ops.rb', line 51 def command_requires_setup? %w[ rails rspec sidekiq hutch puma rake webpack webpack-dev-server ].include?(ARGV[0]) end |
#lock_setup ⇒ Object
22 23 24 |
# File 'lib/on_container/dev/setup_ops.rb', line 22 def lock_setup system "mkdir -p #{app_temp_path} && touch #{app_setup_lock_path};" end |
#on_setup_lock_acquired ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/on_container/dev/setup_ops.rb', line 35 def on_setup_lock_acquired return yield if TRUEISH_VALUES.include? ENV[SKIP_SETUP_ENV_VAR] wait_setup while File.exist?(app_setup_lock_path) lock_setup %w[HUP INT QUIT TERM EXIT].each do |signal_string| Signal.trap(signal_string) { unlock_setup } end yield ensure unlock_setup end |
#unlock_setup ⇒ Object
26 27 28 |
# File 'lib/on_container/dev/setup_ops.rb', line 26 def unlock_setup system "rm -rf #{app_setup_lock_path}" end |
#wait_setup ⇒ Object
30 31 32 33 |
# File 'lib/on_container/dev/setup_ops.rb', line 30 def wait_setup puts 'Waiting for app setup to finish...' sleep app_setup_wait end |