Class: Shippy::Cli::App

Inherits:
Base
  • Object
show all
Defined in:
lib/shippy/cli/app.rb

Instance Method Summary collapse

Methods inherited from Base

exit_on_failure?

Constructor Details

#initialize ⇒ App

Returns a new instance of App.



4
5
6
7
8
# File 'lib/shippy/cli/app.rb', line 4

def initialize(...)
  super
  @remote_app = Shippy::Remote::App.new(SHIPPY.host, app_name)
  @docker = Shippy::Docker::Client.new(SHIPPY.host)
end

Instance Method Details

#compile ⇒ Object



58
59
60
61
62
# File 'lib/shippy/cli/app.rb', line 58

def compile
  say "Compiling #{app_name}...", :magenta
  app_config = Shippy::Repo.load_app(app_name)
  Shippy::Builder.new(app_config).compile
end

#deploy ⇒ Object



11
12
13
14
15
16
17
# File 'lib/shippy/cli/app.rb', line 11

def deploy
  Shippy::Deployer.new(
    app_name: app_name,
    host: SHIPPY.host,
    ui: self
  ).deploy
end

#logs ⇒ Object



48
49
50
# File 'lib/shippy/cli/app.rb', line 48

def logs
  @docker.logs(@remote_app.current_path, follow: options[:follow])
end

#refresh ⇒ Object



20
21
22
23
# File 'lib/shippy/cli/app.rb', line 20

def refresh
  say "Pulling images...", :magenta
  @docker.compose_pull(@remote_app.current_path, stream: true)
end

#restart ⇒ Object



34
35
36
37
38
# File 'lib/shippy/cli/app.rb', line 34

def restart
  say "Restarting...", :magenta
  services = options[:service] ? [options[:service]] : []
  @docker.compose_restart(@remote_app.current_path, services)
end

#rollback ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/shippy/cli/app.rb', line 66

def rollback
  steps = options[:step]

  backups = @remote_app.list_backups
  if backups.empty?
    error "No backups found."
    exit(1)
  end

  target_index = steps - 1
  if target_index < 0 || target_index >= backups.length
    error "Cannot rollback #{steps} steps. Only #{backups.length} backups available."
    exit(1)
  end

  target_ts = backups[target_index]
  say "Rolling back #{steps} step(s) to: #{target_ts}", :yellow

  @docker.compose_down(@remote_app.current_path)

  say "Restoring files...", :blue
  @remote_app.restore_backup(target_ts)

  say "Starting restored application...", :green
  app_config = Shippy::Repo.load_app(app_name)
  @docker.compose_up(@remote_app.current_path, flags: app_config&.deploy_flags)
rescue => e
  error "Rollback failed: #{e.message}"
  exit(1)
end

#start ⇒ Object



26
27
28
29
30
# File 'lib/shippy/cli/app.rb', line 26

def start
  say "Starting...", :magenta
  app_config = Shippy::Repo.load_app(app_name)
  @docker.compose_up(@remote_app.current_path, flags: app_config&.deploy_flags)
end

#status ⇒ Object



53
54
55
# File 'lib/shippy/cli/app.rb', line 53

def status
  @docker.status(@remote_app.current_path)
end

#stop ⇒ Object



41
42
43
44
# File 'lib/shippy/cli/app.rb', line 41

def stop
  say "Stopping...", :magenta
  @docker.compose_down(@remote_app.current_path)
end