class DockerRailsProxy::Compose::Up

Constants

EIO_ERROR
FSWATCH_CMD

Attributes

branch_name[RW]
from_scratch[RW]
from_scratch?[RW]
options[RW]
stopping[RW]
stopping?[RW]

Public Instance Methods

process() click to toggle source
# File lib/docker_rails_proxy/commands/compose/up.rb, line 45
def process
  system 'docker-compose up -d' if docker_compose?
  sync_app_and_gems_folders

  set_app_container_id if app_container_id.empty?
  run_bundle_install   if options[:bundle]
  seed                 if from_scratch?
end

Private Instance Methods

current_branch() click to toggle source
# File lib/docker_rails_proxy/commands/compose/up.rb, line 115
def current_branch
  %x(git rev-parse --abbrev-ref HEAD).strip
end
fswatch_start() click to toggle source
# File lib/docker_rails_proxy/commands/compose/up.rb, line 78
def fswatch_start
  logger.debug "fswatch command: #{FSWATCH_CMD}"
  logger.info 'fswatch has been started'

  PTY.spawn(FSWATCH_CMD) do |stdout, stdin, pid|
    begin
      stdout.each { |path| sync_or_kill(path: path.strip, pid: pid) }
    rescue Errno::EIO
      logger.error EIO_ERROR
    end
  end

rescue PTY::ChildExited
  logger.error '"The fswatch process exited!'

# Captures Ctrl-C
rescue Exception
  logger.info 'fswatch has been stopped'
end
opt_parser() click to toggle source
# File lib/docker_rails_proxy/commands/compose/up.rb, line 132
def opt_parser
  @opt_parser ||= OptionParser.new do |opts|
    opts.banner = "Usage: bin/#{APP_NAME} compose up [options]"

    opts.on(
      '--[no-]bundle',
      'Run bundle install in all related containers'
    ) { |bundle| options[:bundle] = bundle }

    opts.on('-h', '--help', 'Display this screen') do
      puts opts
      exit
    end
  end
end
parse_options!() click to toggle source
# File lib/docker_rails_proxy/commands/compose/up.rb, line 124
def parse_options!
  opt_parser.parse!(arguments)
end
rsync_app() click to toggle source
# File lib/docker_rails_proxy/commands/compose/up.rb, line 70
def rsync_app
  loop do
    break if sync(source: APP_PATH)
    logger.info "waiting for rsync-volume service on #{_rsync_host}"
    sleep 5
  end
end
run_bundle_install() click to toggle source

since new gems may have been added, we need bundle install

# File lib/docker_rails_proxy/commands/compose/up.rb, line 120
def run_bundle_install
  execute "bundle install"
end
seed() click to toggle source
# File lib/docker_rails_proxy/commands/compose/up.rb, line 56
def seed
  logger.info "Seeding #{APP_NAME} data"

  loop do
    break if execute "bin/rake db:reset"
    sleep 5
  end
end
set_defaults() click to toggle source
# File lib/docker_rails_proxy/commands/compose/up.rb, line 128
def set_defaults
  options[:bundle] = true if options[:bundle].nil?
end
sync_app_and_gems_folders() click to toggle source
# File lib/docker_rails_proxy/commands/compose/up.rb, line 65
def sync_app_and_gems_folders
  rsync_app
  sync source: GEMS_PATH if GEMS_PATH.present?
end
sync_or_kill(path:, pid:) click to toggle source
# File lib/docker_rails_proxy/commands/compose/up.rb, line 98
def sync_or_kill(path:, pid:)
  return if stopping?

  if branch_name == (branch = current_branch)
    logger.debug("syncing #{path}")
    sync source: path
    logger.debug("#{path} synced")
  else
    $stderr.puts %(
    `git checkout #{branch}` was detected, stopping fswatch
    Previous branch was '#{branch_name}'
    )
    Process.kill(9, pid)
    self.stopping = true
  end
end