Sha256: 5567ed6dab03d5755b2e31b8f6b909337bd21757dfbe2fbb5a7575fd28a80d6d

Contents?: true

Size: 1.67 KB

Versions: 3

Compression:

Stored size: 1.67 KB

Contents

require "net/ssh"
require "thor"

module Dogids
  class Cli < Thor
    no_commands do
      def deploy_worker
        print_heading("Deploying dogids-backgrounder")

        Net::SSH.start("worker1.dogids.codelation.net", "dogids") do |ssh|
          print_command("Pulling latest from master")
          ssh.exec!(worker_git_pull_command) do |_channel, _stream, data|
            print_command(data)
          end

          print_heading("Building application")
          ssh.exec!(worker_build_command) do |_channel, _stream, data|
            print_command(data)
          end

          print_heading("Restarting")
          %w(clock web worker).each do |process|
            # First stop each process
            command = "sudo stop dogids-#{process}"
            ssh.exec!(command) do |_channel, _stream, data|
              print_command(data)
            end
            # Then start each process (restart doesn't work if not running)
            command = "sudo start dogids-#{process}"
            ssh.exec!(command) do |_channel, _stream, data|
              print_command(data)
            end
          end
        end

        print_heading("Done.")
      end
    end

  private

    def worker_build_command
      commands = []
      commands << "cd /home/dogids/apps/dogids-backgrounder"
      commands << "git archive master | docker run -v /tmp/dogids-backgrounder-cache:/tmp/cache:rw -i -a stdin -a stderr -a stdout flynn/slugbuilder - > slug.tgz"
      commands.join("&& ")
    end

    def worker_git_pull_command
      commands = []
      commands << "cd /home/dogids/apps/dogids-backgrounder"
      commands << "git pull origin master"
      commands.join("&& ")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dogids-cli-0.0.11 lib/dogids/deploy/worker.rb
dogids-cli-0.0.10 lib/dogids/deploy/worker.rb
dogids-cli-0.0.9 lib/dogids/deploy/worker.rb