Class: Fantasia::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/fantasia/cli.rb

Instance Method Summary collapse

Instance Method Details

#buildObject



14
15
16
17
18
19
20
21
# File 'lib/fantasia/cli.rb', line 14

def build
  if system("git diff-index --quiet --cached HEAD --") || options[:force]
    system("docker-compose build") || exit(1)
  else
    puts "There are unsaved changes. Commit, stash, or revert them, or use the force option."
    exit(1)
  end
end

#deployObject



50
51
52
53
54
# File 'lib/fantasia/cli.rb', line 50

def deploy
  invoke :build
  invoke :push
  invoke :update
end

#pushObject



24
25
26
# File 'lib/fantasia/cli.rb', line 24

def push
  system("docker-compose push") || exit(1)
end

#showObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/fantasia/cli.rb', line 57

def show
  spec = YAML.load(File.read "fantasia.yml")
  secrets = YAML.load(File.read(spec["secrets"] || "fantasia.secrets.yml"))
  url = spec["url"]
  http = Faraday.new("#{url}api/v1/")
  name = spec["stack"]
  http.authorization(:Bearer, secrets[name])
  r = JSON.parse(http.get("stack").body)
  puts "#{"State".colorize(:green)}:        #{r["state"]}"
  puts "#{"Portainer ID".colorize(:green)}: #{r["portainer_id"]}"
  puts
  puts "Fantasia config".colorize(:green)
  puts r["fantasia_file"]
  puts
  puts "Compose config".colorize(:green)
  puts r["compose_file"]
end

#updateObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fantasia/cli.rb', line 29

def update
  spec = YAML.load(File.read "fantasia.yml")
  secrets = YAML.load(File.read(spec["secrets"] || "fantasia.secrets.yml"))
  url = spec["url"]
  http = Faraday.new("#{url}api/v1/")
  name = spec["stack"]
  http.authorization(:Bearer, secrets[name])
  r = http.post "stack", {
    fantasia_file: spec.to_yaml,
    compose_file: File.read(spec["compose-file"] || "docker-compose.yml")
  }
  r = JSON.parse(r.body)
  if r["success"]
    puts r["message"].colorize(:green)
  else
    puts r["message"].colorize(:red)
    exit 1
  end
end