github.com/ssube/gitlab-ci-multi-runner@v1.2.1-0.20160607142738-b8d1285632e6/executors/docker/executor_docker_ssh.go (about) 1 package docker 2 3 import ( 4 "errors" 5 6 "gitlab.com/gitlab-org/gitlab-ci-multi-runner/common" 7 "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors" 8 "gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers/ssh" 9 ) 10 11 type sshExecutor struct { 12 executor 13 sshCommand ssh.Client 14 } 15 16 func (s *sshExecutor) Prepare(globalConfig *common.Config, config *common.RunnerConfig, build *common.Build) error { 17 err := s.executor.Prepare(globalConfig, config, build) 18 if err != nil { 19 return err 20 } 21 22 if s.Config.SSH == nil { 23 return errors.New("Missing SSH configuration") 24 } 25 26 s.Debugln("Starting SSH command...") 27 28 imageName, err := s.getImageName() 29 if err != nil { 30 return err 31 } 32 33 options, err := s.prepareBuildContainer() 34 if err != nil { 35 return err 36 } 37 38 // Start build container which will run actual build 39 container, err := s.createContainer("build", imageName, []string{}, *options) 40 if err != nil { 41 return err 42 } 43 44 s.Debugln("Starting container", container.ID, "...") 45 err = s.client.StartContainer(container.ID, nil) 46 if err != nil { 47 return err 48 } 49 50 containerData, err := s.client.InspectContainer(container.ID) 51 if err != nil { 52 return err 53 } 54 55 // Create SSH command 56 s.sshCommand = ssh.Client{ 57 Config: *s.Config.SSH, 58 Stdout: s.BuildLog, 59 Stderr: s.BuildLog, 60 } 61 s.sshCommand.Host = containerData.NetworkSettings.IPAddress 62 63 s.Debugln("Connecting to SSH server...") 64 err = s.sshCommand.Connect() 65 if err != nil { 66 return err 67 } 68 return nil 69 } 70 71 func (s *sshExecutor) Run(cmd common.ExecutorCommand) error { 72 return s.sshCommand.Run(ssh.Command{ 73 Environment: s.BuildScript.Environment, 74 Command: s.BuildScript.GetCommandWithArguments(), 75 Stdin: cmd.Script, 76 Abort: cmd.Abort, 77 }) 78 } 79 80 func (s *sshExecutor) Cleanup() { 81 s.sshCommand.Cleanup() 82 s.executor.Cleanup() 83 } 84 85 func init() { 86 options := executors.ExecutorOptions{ 87 DefaultBuildsDir: "builds", 88 SharedBuildsDir: false, 89 Shell: common.ShellScriptInfo{ 90 Shell: "bash", 91 Type: common.LoginShell, 92 }, 93 ShowHostname: true, 94 SupportedOptions: []string{"image", "services"}, 95 } 96 97 creator := func() common.Executor { 98 return &sshExecutor{ 99 executor: executor{ 100 AbstractExecutor: executors.AbstractExecutor{ 101 ExecutorOptions: options, 102 }, 103 }, 104 } 105 } 106 107 featuresUpdater := func(features *common.FeaturesInfo) { 108 features.Variables = true 109 features.Image = true 110 features.Services = true 111 } 112 113 common.RegisterExecutor("docker-ssh", executors.DefaultExecutorProvider{ 114 Creator: creator, 115 FeaturesUpdater: featuresUpdater, 116 }) 117 }