Class: Shippy::Deployer

Inherits:
Object
  • Object
show all
Defined in:
lib/shippy/deployer.rb

Instance Method Summary collapse

Constructor Details

#initialize(app_name:, host:, ui:) ⇒ Deployer

Returns a new instance of Deployer.



3
4
5
6
7
8
9
10
# File 'lib/shippy/deployer.rb', line 3

def initialize(app_name:, host:, ui:)
  @app_name = app_name
  @ui = ui
  @app_config = Shippy::Repo.load_app(app_name)
  @builder = Shippy::Builder.new(@app_config)
  @remote_app = Shippy::Remote::App.new(host, app_name)
  @docker = Shippy::Docker::Client.new(host)
end

Instance Method Details

#deploy ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/shippy/deployer.rb', line 12

def deploy
  @ui.say "Deploying #{@app_name}...", :magenta

  @builder.compile
  archive = @builder.archive

  @ui.say "Backing up current version...", :blue
  backup_path = @remote_app.backup_current_release

  @ui.say "Uploading new version...", :blue
  @remote_app.prepare_directories
  @remote_app.upload_release(archive)

  @docker.ensure_network("lan_access")

  @ui.say "Pulling images...", :blue
  @docker.compose_pull(@remote_app.current_path, stream: true)

  @ui.say "Pinning image digests...", :blue
  @docker.pin_image_digests(@remote_app.current_path)

  if backup_path
    @ui.say "Stopping old version...", :yellow
    @docker.compose_down(backup_path)
  end

  run_hooks

  @ui.say "Starting application...", :green
  @docker.compose_up(@remote_app.current_path, flags: @app_config&.deploy_flags)

  @builder.cleanup
  @remote_app.prune_old_releases(keep: SHIPPY.config.keep_releases)

  @docker.status(@remote_app.current_path)
rescue => e
  @ui.error "Deployment failed: #{e.message}"
  raise e
end