Sha256: 5a3f2fe6733f444d69e7a9077b0400a46d4e1a407116a454c1795db00012a6bc

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

require 'vx/common'

module Vx
  class Router
    class ScriptBuilder

      Prepare = Struct.new(:app) do

        include Helper::TraceShCommand
        include Common::Helper::UploadShCommand

        def call(env)
          name         = env.build.message.name
          deploy_key   = env.build.message.deploy_key

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

          sha          = env.build.message.sha
          scm          = build_scm(env, sha, repo_path)
          git_ssh      = scm.git_ssh.class.template(deploy_key && "$PWD/#{key_file}")

          env.init.tap do |i|
            i << "mkdir -p  #{data_path}"
            i << "mkdir -p  #{repo_path}"

            if deploy_key
              i << "echo instaling keys"
              i << upload_sh_command(key_file, deploy_key)
              i << "chmod 0600 #{key_file}"
            end

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

            i << "export GIT_SSH=$PWD/#{git_ssh_file}"
            i << scm.make_fetch_command
            i << "unset GIT_SSH"
          end

          app.call env
        end

        private

          def build_scm(env, sha, path)
            SCM::Git.new(env.build.message.src,
                         sha,
                         "$PWD/#{path}",
                         branch: env.build.message.branch,
                         pull_request_id: env.build.message.pull_request_id)
          end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vx-router-0.2.0.pre32 lib/vx/router/script_builder/prepare.rb