Module: OnContainer::Dev::SetupOps

Defined in:
lib/on_container/dev/setup_ops.rb

Constant Summary collapse

APP_PATH =
File.expand_path '.'
TRUEISH_VALUES =
%w[true True TRUE yes Yes YES].freeze
SKIP_SETUP_ENV_VAR =
'ON_CONTAINER_SKIP_SETUP_LOCK'.freeze

Instance Method Summary collapse

Instance Method Details

#app_setup_lock_pathObject



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_waitObject



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_pathObject



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

Returns:

  • (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

Returns:

  • (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_setupObject



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_acquiredObject



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_setupObject



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_setupObject



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