Sha256: addcb9e5ab01d1248550363735e79c603f158417deb8ffdb5acd9e88401be0b1

Contents?: true

Size: 836 Bytes

Versions: 1

Compression:

Stored size: 836 Bytes

Contents

require 'net/scp'

module Evrone
  module CI
    module Worker

      DockerBeforeScript = Struct.new(:app) do

        include Helper::Logger

        def call(env)
          if env.ssh && env.docker_repo_dir
            code = run_before_script(env)
            if code == 0
              app.call env
            else
              -1
            end
          else
            app.call env
          end
        end

        private

          def run_before_script(env)
            scp = ::Net::SCP.new(env.ssh.connection)
            script = [env.docker_repo_dir, ".ci_before_script.sh"].join("/")
            scp.upload! StringIO.new(env.job.message.before_script), script
            env.ssh.spawn "env - bash #{script}", chdir: env.docker_repo_dir, &env.job.method(:add_to_output)
          end

      end
    end
  end
end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
evrone-ci-worker-0.2.0.pre0 lib/evrone/ci/worker/middlewares/docker_before_script.rb