Skip to content
This repository was archived by the owner on Aug 9, 2021. It is now read-only.

Commit c0af6b6

Browse files
authored
Merge 04835db into e6ebf7a
2 parents e6ebf7a + 04835db commit c0af6b6

8 files changed

Lines changed: 62 additions & 22 deletions

File tree

Gopkg.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
version = "v1.1.0"
3131

3232
[[constraint]]
33-
name = "gopkg.in/urfave/cli.v2"
33+
name = "github.com/urfave/cli"
34+
version = "=v1.19.1"
3435

3536
[[constraint]]
3637
name = "github.com/google/go-github"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,4 @@ CapsuleCD is licensed under the MIT License - see the
293293
- https://opencredo.com/why-i-dont-like-error-handling-in-go/
294294
- https://godoc.org/github.com/pkg/errors
295295
- https://blog.strapi.io/testing-npm-package-before-releasing-it-using-verdaccio-and-ngrok/
296+

capsule.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
---
2+
engine_disable_cleanup: true
23

34
engine_enable_code_mutation: true
5+
#- cp /usr/local/osx-ndk-x86/macports/pkgs/opt/local/lib/pkgconfig/libgit2.pc vendor/gopkg.in/libgit2/git2go.v25/vendor/libgit2/build/libgit2.pc
6+
# - '. /scripts/toolchains/osx/osx-build-env.sh && go build -ldflags "-X main.goos=darwin -X main.goarch=amd64" -o capsulecd-darwin-amd64 -tags "static" cmd/capsulecd/capsulecd.go'
47
engine_cmd_compile:
58
- mkdir -p vendor/gopkg.in/libgit2/git2go.v25/vendor/libgit2/build/
6-
- cp /usr/local/osx-ndk-x86/macports/pkgs/opt/local/lib/pkgconfig/libgit2.pc vendor/gopkg.in/libgit2/git2go.v25/vendor/libgit2/build/libgit2.pc
7-
- '. /scripts/toolchains/osx/osx-build-env.sh && go build -ldflags "-X main.goos=darwin -X main.goarch=amd64" -o capsulecd-darwin-amd64 -tags "static" $(go list ./cmd/...)'
89
- cp /usr/local/linux/lib/pkgconfig/libgit2.pc vendor/gopkg.in/libgit2/git2go.v25/vendor/libgit2/build/libgit2.pc
9-
- '. /scripts/toolchains/linux/linux-build-env.sh && go build -ldflags "-X main.goos=linux -X main.goarch=amd64" -o capsulecd-linux-amd64 -tags "static" $(go list ./cmd/...)'
10+
- '. /scripts/toolchains/linux/linux-build-env.sh && go build -ldflags "-X main.goos=linux -X main.goarch=amd64" -o capsulecd-linux-amd64 -tags "static" cmd/capsulecd/capsulecd.go'
1011
- 'echo "listing linked libraries" && ldd capsulecd-linux-amd64'
1112
engine_cmd_test: 'go test -v -tags "static" ./...'
1213
engine_cmd_lint: 'gometalinter.v2 --vendor --config=gometalinter.json ./...'

cmd/capsulecd/capsulecd.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/analogj/capsulecd/pkg/errors"
1111
"github.com/analogj/capsulecd/pkg/utils"
1212
"github.com/analogj/capsulecd/pkg/version"
13-
"gopkg.in/urfave/cli.v2"
13+
"github.com/urfave/cli"
1414
"path/filepath"
1515
)
1616

@@ -23,8 +23,8 @@ func main() {
2323
Usage: "Continuous Delivery scripts for automating package releases",
2424
Version: version.VERSION,
2525
Compiled: time.Now(),
26-
Authors: []*cli.Author{
27-
&cli.Author{
26+
Authors: []cli.Author{
27+
cli.Author{
2828
Name: "Jason Kulatunga",
2929
Email: "jason@thesparktree.com",
3030
},
@@ -49,7 +49,7 @@ func main() {
4949
return nil
5050
},
5151

52-
Commands: []*cli.Command{
52+
Commands: []cli.Command{
5353
{
5454
Name: "start",
5555
Usage: "Start a new CapsuleCD package pipeline",
@@ -104,7 +104,6 @@ func main() {
104104

105105
&cli.StringFlag{
106106
Name: "package_type",
107-
Aliases: []string{"package-type"},
108107
Value: "default",
109108
Usage: "The type of package being built.",
110109
},
@@ -119,7 +118,6 @@ func main() {
119118

120119
&cli.StringFlag{
121120
Name: "config_file",
122-
Aliases: []string{"config-file", "c"},
123121
Usage: "Specifies the location of the config file",
124122
},
125123
},

pkg/engine/engine_golang.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ type engineGolang struct {
2727
Scm scm.Interface //Interface
2828
CurrentMetadata *metadata.GolangMetadata
2929
NextMetadata *metadata.GolangMetadata
30-
GoPath string
3130
}
3231

3332
func (g *engineGolang) Init(pipelineData *pipeline.Data, config config.Interface, sourceScm scm.Interface) error {
@@ -60,8 +59,18 @@ func (g *engineGolang) Init(pipelineData *pipeline.Data, config config.Interface
6059
// to run, and hit the default deadline limit ( --deadline=30s).
6160
// we can have multiple workspaces in the gopath by separating them with colon (:), but this timeout is nasty if not required.
6261
//TODO: g.GoPath root will not be deleted (its the parent of GitParentPath), figure out if we can do this automatically.
63-
g.GoPath = g.PipelineData.GitParentPath
64-
os.Setenv("GOPATH", fmt.Sprintf("%s:%s", os.Getenv("GOPATH"), g.GoPath))
62+
g.PipelineData.GolangGoPath = g.PipelineData.GitParentPath
63+
os.Setenv("GOPATH", fmt.Sprintf("%s:%s", os.Getenv("GOPATH"), g.PipelineData.GolangGoPath))
64+
65+
// A proper gopath has a bin and src directory.
66+
goPathBin := path.Join(g.PipelineData.GitParentPath, "bin")
67+
goPathSrc := path.Join(g.PipelineData.GitParentPath, "src")
68+
os.MkdirAll(goPathBin, 0666)
69+
os.MkdirAll(goPathSrc, 0666)
70+
71+
// the gopath bin directory should aslo be added to Path
72+
os.Setenv("PATH", fmt.Sprintf("%s:%s", os.Getenv("PATH"), goPathBin))
73+
6574

6675
packagePathPrefix := path.Dir(g.Config.GetString("engine_golang_package_path")) //strip out the repo name.
6776
// customize the git parent path for Golang Engine
@@ -128,7 +137,7 @@ func (g *engineGolang) CompileStep() error {
128137

129138
if terr := g.ExecuteCmdList("engine_cmd_compile",
130139
g.PipelineData.GitLocalPath,
131-
nil,
140+
g.customGopathEnv(),
132141
"",
133142
"Compile command (%s) failed. Check log for more details.",
134143
); terr != nil {
@@ -152,7 +161,7 @@ func (g *engineGolang) TestStep() error {
152161
//run lint command
153162
if terr := g.ExecuteCmdList("engine_cmd_lint",
154163
g.PipelineData.GitLocalPath,
155-
nil,
164+
g.customGopathEnv(),
156165
"",
157166
"Lint command (%s) failed. Check log for more details.",
158167
); terr != nil {
@@ -163,7 +172,7 @@ func (g *engineGolang) TestStep() error {
163172
//code formatter
164173
if terr := g.ExecuteCmdList("engine_cmd_fmt",
165174
g.PipelineData.GitLocalPath,
166-
nil,
175+
g.customGopathEnv(),
167176
"",
168177
"Format command (%s) failed. Check log for more details.",
169178
); terr != nil {
@@ -175,7 +184,7 @@ func (g *engineGolang) TestStep() error {
175184
//run test command
176185
if terr := g.ExecuteCmdList("engine_cmd_test",
177186
g.PipelineData.GitLocalPath,
178-
nil,
187+
g.customGopathEnv(),
179188
"",
180189
"Test command (%s) failed. Check log for more details.",
181190
); terr != nil {
@@ -187,7 +196,7 @@ func (g *engineGolang) TestStep() error {
187196
//run security check command
188197
if terr := g.ExecuteCmdList("engine_cmd_security_check",
189198
g.PipelineData.GitLocalPath,
190-
nil,
199+
g.customGopathEnv(),
191200
"",
192201
"Dependency vulnerability check command (%s) failed. Check log for more details.",
193202
); terr != nil {
@@ -217,13 +226,20 @@ func (g *engineGolang) PackageStep() error {
217226

218227
func (g *engineGolang) customGopathEnv() []string {
219228
currentEnv := os.Environ()
220-
updatedEnv := []string{fmt.Sprintf("GOPATH=%s", g.GoPath)}
229+
updatedEnv := []string{fmt.Sprintf("GOPATH=%s", g.PipelineData.GolangGoPath)}
221230

222231
for i := range currentEnv {
223-
if !strings.HasPrefix(currentEnv[i], "GOPATH=") { //add all environmental variables that are not GOPATH
232+
if strings.HasPrefix(currentEnv[i], "GOPATH="){
233+
//skip
234+
continue
235+
} else if strings.HasPrefix(currentEnv[i], "PATH=") {
236+
updatedEnv = append(updatedEnv, fmt.Sprintf("PATH=%s/bin:%s", g.PipelineData.GolangGoPath, currentEnv[i]))
237+
} else {
238+
//add all environmental variables that are not GOPATH
224239
updatedEnv = append(updatedEnv, currentEnv[i])
225240
}
226241
}
242+
227243
return updatedEnv
228244
}
229245

pkg/metadata/golang_metadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ package metadata
22

33
type GolangMetadata struct {
44
Version string
5-
}
5+
}

pkg/mgr/mgr_golang_dep.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mgr
22

33
import (
4+
"fmt"
45
"github.com/analogj/capsulecd/pkg/config"
56
"github.com/analogj/capsulecd/pkg/errors"
67
"github.com/analogj/capsulecd/pkg/pipeline"
@@ -9,6 +10,7 @@ import (
910
"os"
1011
"os/exec"
1112
"path"
13+
"strings"
1214
)
1315

1416
func DetectGolangDep(pipelineData *pipeline.Data, myconfig config.Interface, client *http.Client) bool {
@@ -54,7 +56,24 @@ func (m *mgrGolangDep) MgrAssembleStep() error {
5456
func (m *mgrGolangDep) MgrDependenciesStep(currentMetadata interface{}, nextMetadata interface{}) error {
5557
// the go source has already been downloaded. lets make sure all its dependencies are available.
5658

57-
if cerr := utils.BashCmdExec("dep ensure -v", m.PipelineData.GitLocalPath, nil, ""); cerr != nil {
59+
currentEnv := os.Environ()
60+
updatedEnv := []string{fmt.Sprintf("GOPATH=%s", m.PipelineData.GolangGoPath)}
61+
62+
for i := range currentEnv {
63+
if strings.HasPrefix(currentEnv[i], "GOPATH="){
64+
//skip
65+
continue
66+
} else if strings.HasPrefix(currentEnv[i], "PATH=") {
67+
updatedEnv = append(updatedEnv, fmt.Sprintf("PATH=%s/bin:%s", m.PipelineData.GolangGoPath, currentEnv[i]))
68+
} else {
69+
//add all environmental variables that are not GOPATH
70+
updatedEnv = append(updatedEnv, currentEnv[i])
71+
}
72+
}
73+
74+
print(updatedEnv)
75+
76+
if cerr := utils.BashCmdExec("dep ensure -v", m.PipelineData.GitLocalPath, updatedEnv, ""); cerr != nil {
5877
return errors.EngineTestDependenciesError("dep ensure failed. Check dep dependencies")
5978
}
6079

pkg/pipeline/pipeline_data.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ type Data struct {
1313
ReleaseVersion string
1414
ReleaseCommit string
1515
ReleaseAssets []ScmReleaseAsset
16+
17+
//Engine specific pipeline data
18+
GolangGoPath string
19+
GolangGoRoot string
1620
}

0 commit comments

Comments
 (0)