github.com/ssube/gitlab-ci-multi-runner@v1.2.1-0.20160607142738-b8d1285632e6/executors/docker/machine/executor.go (about)

     1  package machine
     2  
     3  import (
     4  	"errors"
     5  
     6  	"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
     7  
     8  	// Force to load docker executor
     9  	_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/docker"
    10  )
    11  
    12  type machineExecutor struct {
    13  	provider *machineProvider
    14  	executor common.Executor
    15  	data     common.ExecutorData
    16  	config   common.RunnerConfig
    17  }
    18  
    19  func (e *machineExecutor) Prepare(globalConfig *common.Config, config *common.RunnerConfig, build *common.Build) (err error) {
    20  	// Use the machine
    21  	e.config, e.data, err = e.provider.Use(config, build.ExecutorData)
    22  	if err != nil {
    23  		return err
    24  	}
    25  
    26  	// TODO: Currently the docker-machine doesn't support multiple builds
    27  	build.ProjectRunnerID = 0
    28  	if details, _ := build.ExecutorData.(*machineDetails); details != nil {
    29  		build.Hostname = details.Name
    30  	} else if details, _ := e.data.(*machineDetails); details != nil {
    31  		build.Hostname = details.Name
    32  	}
    33  
    34  	// Create original executor
    35  	e.executor = e.provider.provider.Create()
    36  	if e.executor == nil {
    37  		return errors.New("failed to create an executor")
    38  	}
    39  	return e.executor.Prepare(globalConfig, &e.config, build)
    40  }
    41  
    42  func (e *machineExecutor) ShellScript() *common.ShellScript {
    43  	if e.executor == nil {
    44  		return nil
    45  	}
    46  	return e.executor.ShellScript()
    47  }
    48  
    49  func (e *machineExecutor) Run(cmd common.ExecutorCommand) error {
    50  	if e.executor == nil {
    51  		return errors.New("missing executor")
    52  	}
    53  	return e.executor.Run(cmd)
    54  }
    55  
    56  func (e *machineExecutor) Finish(err error) {
    57  	if e.executor != nil {
    58  		e.executor.Finish(err)
    59  	}
    60  }
    61  
    62  func (e *machineExecutor) Cleanup() {
    63  	// Cleanup executor if were created
    64  	if e.executor != nil {
    65  		e.executor.Cleanup()
    66  	}
    67  
    68  	// Release allocated machine
    69  	if e.data != "" {
    70  		e.provider.Release(&e.config, e.data)
    71  		e.data = nil
    72  	}
    73  }
    74  
    75  func init() {
    76  	common.RegisterExecutor("docker+machine", newMachineProvider("docker"))
    77  	common.RegisterExecutor("docker-ssh+machine", newMachineProvider("docker-ssh"))
    78  }