最后执行,通过pipec exec:
# pipec exec proc "pipeline_clone_0" started + git init Initialized empty Git repository in /go/src/github.com/drone/envsubst/.git/ + git remote add origin https://github.com/drone/envsubst.git + git fetch --no-tags --depth=50 origin +refs/heads/master: From https://github.com/drone/envsubst * branch master -> FETCH_HEAD * [new branch] master -> origin/master + git reset --hard -q d0876d3176965f9552a611cbd56e24a9264355e6 + git submodule update --init --recursive proc "pipeline_clone_0" exited with status 0 proc "pipeline_step_0" started + go get -t ./... + go build + go test -v === RUN TestExpand --- PASS: TestExpand (0.00s) === RUN TestFuzz --- PASS: TestFuzz (0.01s) === RUN Test_len --- PASS: Test_len (0.00s) === RUN Test_lower --- PASS: Test_lower (0.00s) === RUN Test_lowerFirst --- PASS: Test_lowerFirst (0.00s) === RUN Test_upper --- PASS: Test_upper (0.00s) === RUN Test_upperFirst --- PASS: Test_upperFirst (0.00s) === RUN Test_default --- PASS: Test_default (0.00s) PASS ok github.com/drone/envsubst 0.009s proc "pipeline_step_0" exited with status 0 pipeline 原理分析 编译过程可以形象的理解为 .env+pipeline.yml --> pipeline.json
编译过程不复杂,主要是解析pipeline.yml为Config:
Config struct { Cache libcompose.Stringorslice Platform string Branches Constraint Workspace Workspace Clone Containers Pipeline Containers Services Containers Networks Networks Volumes Volumes Labels libcompose.SliceorMap }然后转换为json对应的config:
Config struct { Stages []*Stage `json:"pipeline"` // pipeline stages Networks []*Network `json:"networks"` // network definitions Volumes []*Volume `json:"volumes"` // volume definitions Secrets []*Secret `json:"secrets"` // secret definitions }该部分主要代码在pipeline/frontend里
执行过程我们主要关注执行过程,主要代码在pipeline/backend里。
首先是读取配置文件为backend.Config
config, err := pipeline.Parse(reader) if err != nil { return err }然后创建执行环境,目前的代码仅docker可用,k8s是空代码。
var engine backend.Engine if c.Bool("kubernetes") { engine = kubernetes.New( c.String("kubernetes-namepsace"), c.String("kubernetes-endpoint"), c.String("kubernetes-token"), ) } else { engine, err = docker.NewEnv() if err != nil { return err } }