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