Class: Avm::Stereotypes::EacWebappBase0::Deploy

Inherits:
Object
  • Object
show all
Includes:
ActiveSupport::Callbacks
Defined in:
lib/avm/stereotypes/eac_webapp_base0/deploy.rb

Defined Under Namespace

Classes: FilesUnit

Constant Summary collapse

JOBS =
%w[git_deploy setup_files_units assert_instance_branch].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance, git_reference) ⇒ Deploy

Returns a new instance of Deploy.



24
25
26
27
# File 'lib/avm/stereotypes/eac_webapp_base0/deploy.rb', line 24

def initialize(instance, git_reference)
  @instance = instance
  @git_reference = git_reference
end

Instance Attribute Details

#git_referenceObject (readonly)

Returns the value of attribute git_reference.



22
23
24
# File 'lib/avm/stereotypes/eac_webapp_base0/deploy.rb', line 22

def git_reference
  @git_reference
end

#instanceObject (readonly)

Returns the value of attribute instance.



22
23
24
# File 'lib/avm/stereotypes/eac_webapp_base0/deploy.rb', line 22

def instance
  @instance
end

Instance Method Details

#assert_instance_branchObject



63
64
65
66
# File 'lib/avm/stereotypes/eac_webapp_base0/deploy.rb', line 63

def assert_instance_branch
  infom 'Setting instance branch...'
  git.execute!('push', git_remote_name, "#{commit_sha1}:refs/heads/#{instance.id}", '-f')
end

#commit_sha1_uncachedObject



68
69
70
71
72
73
74
# File 'lib/avm/stereotypes/eac_webapp_base0/deploy.rb', line 68

def commit_sha1_uncached
  git_fetch
  r = git.rev_parse(git_reference_found)
  return r if r

  raise ::Avm::Result::Error, "No commit SHA1 found for \"#{git_reference_found}\""
end

#git_deployObject



49
50
51
52
53
54
55
# File 'lib/avm/stereotypes/eac_webapp_base0/deploy.rb', line 49

def git_deploy
  infom 'Deploying source code and appended content...'
  ::Avm::Git::Commit.new(git, commit_sha1).deploy_to_env_path(
    instance.host_env,
    instance.read_entry(:fs_path)
  ).append_directory(template_path).variables_source_set(instance).run
end

#git_fetch_uncachedObject



104
105
106
107
# File 'lib/avm/stereotypes/eac_webapp_base0/deploy.rb', line 104

def git_fetch_uncached
  infom "Fetching remote \"#{git_remote_name}\" from \"#{git_repository_path}\"..."
  git.fetch(git_remote_name)
end

#git_reference_found_uncachedObject



76
77
78
79
80
81
82
# File 'lib/avm/stereotypes/eac_webapp_base0/deploy.rb', line 76

def git_reference_found_uncached
  %w[git_reference instance_branch master_branch].map { |b| send(b) }.find(&:present?) ||
    raise(
      ::Avm::Result::Error,
      'No git reference found (Searched for option, instance and master)'
    )
end

#git_remote_hashs_uncachedObject



100
101
102
# File 'lib/avm/stereotypes/eac_webapp_base0/deploy.rb', line 100

def git_remote_hashs_uncached
  git.remote_hashs(git_remote_name)
end

#git_remote_nameObject



96
97
98
# File 'lib/avm/stereotypes/eac_webapp_base0/deploy.rb', line 96

def git_remote_name
  ::Avm::Git::DEFAULT_REMOTE_NAME
end

#git_repository_pathObject



109
110
111
# File 'lib/avm/stereotypes/eac_webapp_base0/deploy.rb', line 109

def git_repository_path
  instance.source_instance.read_entry(:fs_path)
end

#git_uncachedObject



84
85
86
# File 'lib/avm/stereotypes/eac_webapp_base0/deploy.rb', line 84

def git_uncached
  ::EacLauncher::Git::Base.new(git_repository_path)
end

#instance_branchObject



88
89
90
# File 'lib/avm/stereotypes/eac_webapp_base0/deploy.rb', line 88

def instance_branch
  remote_branch(instance.id)
end

#master_branchObject



92
93
94
# File 'lib/avm/stereotypes/eac_webapp_base0/deploy.rb', line 92

def master_branch
  remote_branch('master')
end

#remote_branch(name) ⇒ Object



113
114
115
# File 'lib/avm/stereotypes/eac_webapp_base0/deploy.rb', line 113

def remote_branch(name)
  git_remote_hashs.key?("refs/heads/#{name}") ? "#{git_remote_name}/#{name}" : nil
end

#runObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/avm/stereotypes/eac_webapp_base0/deploy.rb', line 29

def run
  start_banner
  JOBS.each do |job|
    run_callbacks job do
      send(job)
    end
  end
  ::Avm::Result.success('Deployed')
rescue ::Avm::Result::Error => e
  e.to_result
end

#setup_files_unitsObject



57
58
59
60
61
# File 'lib/avm/stereotypes/eac_webapp_base0/deploy.rb', line 57

def setup_files_units
  instance.class.const_get('FILES_UNITS').each do |data_key, fs_path_subpath|
    FilesUnit.new(self, data_key, fs_path_subpath).run
  end
end

#start_bannerObject



41
42
43
44
45
46
47
# File 'lib/avm/stereotypes/eac_webapp_base0/deploy.rb', line 41

def start_banner
  infov 'Instance', instance
  infov 'Git reference (User)', git_reference.if_present('- BLANK -')
  infov 'Git remote name', git_remote_name
  infov 'Git reference (Found)', git_reference_found
  infov 'Git commit SHA1', commit_sha1
end