Class: Kraaken::App

Inherits:
Object
  • Object
show all
Defined in:
lib/kraaken/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, destination:, server:, config:) ⇒ App

Returns a new instance of App.



6
7
8
9
10
11
# File 'lib/kraaken/app.rb', line 6

def initialize(name:, destination:, server:, config:)
  @name = name
  @destination = destination
  @server = server
  @config = config
end

Instance Attribute Details

#destinationObject (readonly)

Returns the value of attribute destination.



4
5
6
# File 'lib/kraaken/app.rb', line 4

def destination
  @destination
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/kraaken/app.rb', line 4

def name
  @name
end

#serverObject (readonly)

Returns the value of attribute server.



4
5
6
# File 'lib/kraaken/app.rb', line 4

def server
  @server
end

Instance Method Details

#createObject



26
27
28
29
30
31
# File 'lib/kraaken/app.rb', line 26

def create
  ssh.connect(server) do |ssh|
    ssh.run("mkdir -p ~/#{full_name}")
    ssh.run("touch ~/#{full_name}/.env")
  end
end

#deploy(file) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/kraaken/app.rb', line 33

def deploy(file)
  ssh.connect(server) do |ssh|
    ssh.run <<~BASH
      mkdir -p ~/#{full_name}
      cd ~/#{full_name}
      touch .env
    BASH
    ssh.write_file("~/#{full_name}/docker-compose.yml", config.load_template(file.path, app: self))
    ssh.run <<~BASH
      cd ~/#{full_name}
      docker-compose pull
      docker-compose up -d
    BASH
  end
end

#destroyObject



49
50
51
52
53
54
# File 'lib/kraaken/app.rb', line 49

def destroy
  ssh.connect(server) do |ssh|
    ssh.run("cd ~/#{full_name} && docker-compose down --volumes --remove-orphans")
    ssh.run("rm -rf ~/#{full_name}")
  end
end

#environmentObject



13
14
15
16
17
18
# File 'lib/kraaken/app.rb', line 13

def environment
  create
  ssh.connect(server) do |ssh|
    ssh.read_file("~/#{full_name}/.env")
  end
end

#environment=(content) ⇒ Object



20
21
22
23
24
# File 'lib/kraaken/app.rb', line 20

def environment=(content)
  ssh.connect(server) do |ssh|
    ssh.write_file("~/#{full_name}/.env", content)
  end
end

#full_nameObject



62
63
64
# File 'lib/kraaken/app.rb', line 62

def full_name
  "#{name}-#{destination}"
end

#logsObject



56
57
58
59
60
# File 'lib/kraaken/app.rb', line 56

def logs
  ssh.connect(server) do |ssh|
    ssh.run("cd ~/#{full_name} && docker-compose logs -f")
  end
end