Class: StackatoOutThingy

Inherits:
OutThingy show all
Defined in:
lib/conan/output.rb

Constant Summary collapse

@@stackato_file_name =
"stackato.yml"
@@metadata_file_name =
"metadata.xml"

Instance Attribute Summary collapse

Attributes inherited from OutThingy

#output_dir, #time

Instance Method Summary collapse

Methods inherited from OutThingy

#loadAppMetadataFromDeploymentIfExists, #outputToFile

Constructor Details

#initialize(output_dir) ⇒ StackatoOutThingy

Returns a new instance of StackatoOutThingy.



33
34
35
36
37
38
39
40
# File 'lib/conan/output.rb', line 33

def initialize(output_dir)
  super(output_dir)
  workdir = File.join(output_dir,'tmp')
  @environments_dir = File.join(output_dir,'environments')
  @apps_dir = File.join(workdir,'apps')
  FileUtils.mkdir_p environments_dir
  FileUtils.mkdir_p apps_dir
end

Instance Attribute Details

#apps_dirObject

Returns the value of attribute apps_dir.



26
27
28
# File 'lib/conan/output.rb', line 26

def apps_dir
  @apps_dir
end

#environments_dirObject

Returns the value of attribute environments_dir.



26
27
28
# File 'lib/conan/output.rb', line 26

def environments_dir
  @environments_dir
end

Instance Method Details

#clean(app, environment) ⇒ Object



42
43
44
# File 'lib/conan/output.rb', line 42

def clean(app, environment)
  #  TODO: cleanup
end

#filePath(app, deploy) ⇒ Object



50
51
52
# File 'lib/conan/output.rb', line 50

def filePath(app, deploy)
  "#{deploy.environment.id}/#{deploy.shipcloud}/#{app.id}"
end

#loadAppMetadataFromDeployment(app, deploy, fail_silent = false) ⇒ Object

TODO this needs a refactor, it’s knoted up with App



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/conan/output.rb', line 59

def loadAppMetadataFromDeployment(app, deploy, fail_silent=false)
  p = filePath(app, deploy)
  path = File.join(@environments_dir, p)
   = File.join(path, @@metadata_file_name)

  if (File.exists? path)
    File.open(, 'r') { |f| app.(f.read) }
  else
    raise "Build meta-data was not found: #{path}" unless fail_silent
  end
end

#provision(app) ⇒ Object



46
47
48
# File 'lib/conan/output.rb', line 46

def provision(app)
  app.download(@apps_dir)
end

#workingDir(app) ⇒ Object



54
55
56
# File 'lib/conan/output.rb', line 54

def workingDir(app)
  File.join(apps_dir, app.artifact_id)
end

#writeArtifactMetadata(app, deploy) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/conan/output.rb', line 71

def (app, deploy)
  if (deploy.enabled?)
    path = filePath(app, deploy)
    outputToFile("environments/#{path}/#{@@metadata_file_name}") { |f|
      f.write(app.)
    }
  end
end

#writeConfiguration(app, deploy, bg = false) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/conan/output.rb', line 80

def writeConfiguration(app, deploy, bg=false)
  if (deploy.enabled?)
    target_dir = workingDir(app)
    templates_dir = File.join(target_dir, "deploy-templates")

    daphne_tokens = [ "#{app.id}", "#{deploy.environment.id}" ]
    daphne_tokens = daphne_tokens << "facility-#{deploy.facility_id}" unless deploy.facility_id.nil?

    n_changes = Templates.evaluate templates_dir, target_dir, {
      :app => app,
      :deploy => deploy,

      #daphne, generate oauth app tokens
      #TODO: seems like this should be refactored
      :oauth_id => DaphneUtil.generate_id(*daphne_tokens),
      :oauth_secret => DaphneUtil.generate_secret(*daphne_tokens),
      :api_key => DaphneUtil.generate_api_key(*daphne_tokens),

      # short-cuts
      :app_id => app.id,
      :deploy_base_name => deploy.name(app),
      :deploy_name => bg ? deploy.unique_name(app) : deploy.name(app),
      :deploy_urls => bg ? deploy.inactive_urls(app) : deploy.active_urls(app),
      :env => deploy.environment.id,
      :org => deploy.org,
      :ship => deploy.ship,
      :infra => deploy.shipcloud, # TODO: remove infra key, this is just to avoid breaking existing templates
      :shipcloud => deploy.shipcloud,
      :facility => deploy.facility_id,
      :options => deploy.options
    }
  end
  #TODO: can this be used to provide idempotency for config-only deploymnent?
  puts "#{n_changes} files changed"
end