github.com/ssube/gitlab-ci-multi-runner@v1.2.1-0.20160607142738-b8d1285632e6/common/network.go (about)

     1  package common
     2  
     3  import (
     4  	"io"
     5  )
     6  
     7  type UpdateState int
     8  type UploadState int
     9  type DownloadState int
    10  
    11  const (
    12  	UpdateSucceeded UpdateState = iota
    13  	UpdateAbort
    14  	UpdateFailed
    15  )
    16  
    17  const (
    18  	UploadSucceeded UploadState = iota
    19  	UploadTooLarge
    20  	UploadForbidden
    21  	UploadFailed
    22  )
    23  
    24  const (
    25  	DownloadSucceeded DownloadState = iota
    26  	DownloadForbidden
    27  	DownloadFailed
    28  	DownloadNotFound
    29  )
    30  
    31  type FeaturesInfo struct {
    32  	Variables bool `json:"variables"`
    33  	Image     bool `json:"image"`
    34  	Services  bool `json:"services"`
    35  	Artifacts bool `json:"features"`
    36  	Cache     bool `json:"cache"`
    37  }
    38  
    39  type VersionInfo struct {
    40  	Name         string       `json:"name,omitempty"`
    41  	Version      string       `json:"version,omitempty"`
    42  	Revision     string       `json:"revision,omitempty"`
    43  	Platform     string       `json:"platform,omitempty"`
    44  	Architecture string       `json:"architecture,omitempty"`
    45  	Executor     string       `json:"executor,omitempty"`
    46  	Features     FeaturesInfo `json:"features"`
    47  }
    48  
    49  type GetBuildRequest struct {
    50  	Info  VersionInfo `json:"info,omitempty"`
    51  	Token string      `json:"token,omitempty"`
    52  }
    53  
    54  type BuildArtifacts struct {
    55  	Filename string `json:"filename,omitempty"`
    56  	Size     int64  `json:"size,omitempty"`
    57  }
    58  
    59  type BuildInfo struct {
    60  	ID        int             `json:"id,omitempty"`
    61  	Sha       string          `json:"sha,omitempty"`
    62  	RefName   string          `json:"ref,omitempty"`
    63  	Token     string          `json:"token"`
    64  	Name      string          `json:"name"`
    65  	Stage     string          `json:"stage"`
    66  	Tag       bool            `json:"tag"`
    67  	Artifacts *BuildArtifacts `json:"artifacts_file"`
    68  }
    69  
    70  type GetBuildResponse struct {
    71  	ID              int            `json:"id,omitempty"`
    72  	ProjectID       int            `json:"project_id,omitempty"`
    73  	Commands        string         `json:"commands,omitempty"`
    74  	RepoURL         string         `json:"repo_url,omitempty"`
    75  	Sha             string         `json:"sha,omitempty"`
    76  	RefName         string         `json:"ref,omitempty"`
    77  	BeforeSha       string         `json:"before_sha,omitempty"`
    78  	AllowGitFetch   bool           `json:"allow_git_fetch,omitempty"`
    79  	Timeout         int            `json:"timeout,omitempty"`
    80  	Variables       BuildVariables `json:"variables"`
    81  	Options         BuildOptions   `json:"options"`
    82  	Token           string         `json:"token"`
    83  	Name            string         `json:"name"`
    84  	Stage           string         `json:"stage"`
    85  	Tag             bool           `json:"tag"`
    86  	DependsOnBuilds []BuildInfo    `json:"depends_on_builds"`
    87  	TLSCAChain      string         `json:"-"`
    88  }
    89  
    90  type RegisterRunnerRequest struct {
    91  	Info        VersionInfo `json:"info,omitempty"`
    92  	Token       string      `json:"token,omitempty"`
    93  	Description string      `json:"description,omitempty"`
    94  	Tags        string      `json:"tag_list,omitempty"`
    95  }
    96  
    97  type RegisterRunnerResponse struct {
    98  	Token string `json:"token,omitempty"`
    99  }
   100  
   101  type DeleteRunnerRequest struct {
   102  	Token string `json:"token,omitempty"`
   103  }
   104  
   105  type VerifyRunnerRequest struct {
   106  	Token string `json:"token,omitempty"`
   107  }
   108  
   109  type UpdateBuildRequest struct {
   110  	Info  VersionInfo `json:"info,omitempty"`
   111  	Token string      `json:"token,omitempty"`
   112  	State BuildState  `json:"state,omitempty"`
   113  	Trace string      `json:"trace,omitempty"`
   114  }
   115  
   116  type BuildCredentials struct {
   117  	ID        int    `long:"id" env:"CI_BUILD_ID" description:"The build ID to upload artifacts for"`
   118  	Token     string `long:"token" env:"CI_BUILD_TOKEN" required:"true" description:"Build token"`
   119  	URL       string `long:"url" env:"CI_SERVER_URL" required:"true" description:"GitLab CI URL"`
   120  	TLSCAFile string `long:"tls-ca-file" env:"CI_SERVER_TLS_CA_FILE" description:"File containing the certificates to verify the peer when using HTTPS"`
   121  }
   122  
   123  type BuildTrace interface {
   124  	io.Writer
   125  	Success()
   126  	Fail(err error)
   127  	Notify(abort func())
   128  	IsStdout() bool
   129  }
   130  
   131  type Network interface {
   132  	GetBuild(config RunnerConfig) (*GetBuildResponse, bool)
   133  	RegisterRunner(config RunnerCredentials, description, tags string) *RegisterRunnerResponse
   134  	DeleteRunner(config RunnerCredentials) bool
   135  	VerifyRunner(config RunnerCredentials) bool
   136  	UpdateBuild(config RunnerConfig, id int, state BuildState, trace string) UpdateState
   137  	DownloadArtifacts(config BuildCredentials, artifactsFile string) DownloadState
   138  	UploadRawArtifacts(config BuildCredentials, reader io.Reader, baseName string) UploadState
   139  	UploadArtifacts(config BuildCredentials, artifactsFile string) UploadState
   140  	ProcessBuild(config RunnerConfig, id int) BuildTrace
   141  }