Module: Gmortar

Defined in:
lib/gmortar.rb,
lib/gmortar/version.rb,
lib/gmortar/template.rb,
lib/gmortar/fire_command.rb,
lib/gmortar/list_command.rb,
lib/gmortar/root_command.rb,
lib/gmortar/yank_command.rb,
lib/gmortar/describe_command.rb

Defined Under Namespace

Classes: DescribeCommand, FireCommand, ListCommand, RootCommand, Template, YankCommand

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.run(project, template, source: nil, variables: [], name: nil, debug:) ⇒ Object



11
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
51
# File 'lib/gmortar.rb', line 11

def self.run(project, template, source:nil, variables:[], name: nil, debug:)
  t = Template.new template
  for pair in variables
    t.set pair.first, pair.last
  end
  t.set :name, name if name

  gcloud_config = Tempfile.new
  File.write gcloud_config.path, t.result

  puts t.result if debug

  log_bucket = "gs://#{project}_cloudbuild/gmortar-logs/#{SecureRandom.uuid}"
  source_bucket = "gs://#{project}_cloudbuild/gmortar-sources/#{SecureRandom.uuid}"

  cmd = ["gcloud","builds","submit"]
  if source
    cmd << source
    cmd += ["--gcs-log-dir", log_bucket]
    cmd += ["--gcs-source-staging-dir", source_bucket]
  else
    cmd << "--no-source"
  end

  cmd += ["--config", gcloud_config.path]
  cmd += ["--project", project]

  puts cmd.join(" ") if debug
  k = Kommando.new cmd.join(" "), output: true
  k.run

  waits = []
  if source
    puts "removing source from #{source_bucket}"
    waits << (Kommando.run_async "gsutil rm -r #{source_bucket}")
  end

  puts "removing logs from #{log_bucket}"
  waits << (Kommando.run_async "gsutil rm -r #{log_bucket}")
  waits.each { |k| k.wait }
end