Class: Vx::Builder::ScriptBuilder::Prepare

Inherits:
Struct
  • Object
show all
Includes:
Common::Helper::UploadShCommand, Helper::TraceShCommand
Defined in:
lib/vx/builder/script_builder/prepare.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper::TraceShCommand

#trace_sh_command

Instance Attribute Details

#appObject

Returns the value of attribute app

Returns:

  • (Object)

    the current value of app



7
8
9
# File 'lib/vx/builder/script_builder/prepare.rb', line 7

def app
  @app
end

Instance Method Details

#call(env) ⇒ Object



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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/vx/builder/script_builder/prepare.rb', line 12

def call(env)
  name         = env.task.name
  deploy_key   = env.task.deploy_key

  repo_path    = "${VX_ROOT}/code/#{name}"
  data_path    = "${VX_ROOT}/data/#{name}"
  key_file     = "#{data_path}/key"
  git_ssh_file = "#{data_path}/git_ssh"

  sha          = env.task.sha
  scm          = build_scm(env, sha, repo_path)
  git_ssh      = scm.git_ssh_content(deploy_key && "#{key_file}")

  env.init.tap do |i|
    i << 'export VX_ROOT=$(pwd)'
    i << 'export PATH=$VX_ROOT/bin:$PATH'

    i << "mkdir -p $VX_ROOT/bin"
    i << "mkdir -p #{data_path}"
    i << "mkdir -p #{repo_path}"

    %w{ vx_parallel_rspec vx_parallel_spinach vx_builder }.each do |bin|
      src = File.expand_path("../../../../../bin/#{bin}", __FILE__)
      bin.sub!("vx_", '') unless bin == 'vx_builder'
      dst = "$(pwd)/bin/#{bin}"
      i << upload_sh_command(dst, File.read(src))
      i << "chmod 0750 #{dst}"
    end

    if deploy_key
      i << upload_sh_command(key_file, deploy_key)
      i << "chmod 0600 #{key_file}"
      i << "export VX_PRIVATE_KEY=#{key_file}"
    end

    i << upload_sh_command(git_ssh_file, git_ssh)
    i << "chmod 0750 #{git_ssh_file}"

    i << "export GIT_SSH=#{git_ssh_file}"
    i << "#{scm.fetch_cmd} || exit 1"
    i << "unset GIT_SSH"

    i << 'echo "starting SSH Agent"'
    i << 'eval "$(ssh-agent)" > /dev/null'
    i << "ssh-add $VX_PRIVATE_KEY 2> /dev/null"

    i << "cd #{repo_path}"

    i << 'echo "download latest version of vxvm"'
    i << "curl --tcp-nodelay --retry 3 --fail --silent --show-error -o $VX_ROOT/bin/vxvm https://raw.githubusercontent.com/vexor/vx-packages/master/vxvm"
    i << "chmod +x $VX_ROOT/bin/vxvm"
  end

  env.after_script_init.tap do |i|
    i << 'export VX_ROOT=$(pwd)'
    i << "test -d #{repo_path} || exit 1"
    i << "cd #{repo_path}"
  end

  app.call env
end