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

Commit

Permalink
Merge 04835db into e6ebf7a
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ authored Sep 12, 2019
2 parents e6ebf7a + 04835db commit c0af6b6
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 22 deletions.
3 changes: 2 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
version = "v1.1.0"

[[constraint]]
name = "gopkg.in/urfave/cli.v2"
name = "github.com/urfave/cli"
version = "=v1.19.1"

[[constraint]]
name = "github.com/google/go-github"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,4 @@ CapsuleCD is licensed under the MIT License - see the
- https://opencredo.com/why-i-dont-like-error-handling-in-go/
- https://godoc.org/github.com/pkg/errors
- https://blog.strapi.io/testing-npm-package-before-releasing-it-using-verdaccio-and-ngrok/

7 changes: 4 additions & 3 deletions capsule.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
---
engine_disable_cleanup: true

engine_enable_code_mutation: true
#- 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
# - '. /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'
engine_cmd_compile:
- mkdir -p vendor/gopkg.in/libgit2/git2go.v25/vendor/libgit2/build/
- 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
- '. /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/...)'
- cp /usr/local/linux/lib/pkgconfig/libgit2.pc vendor/gopkg.in/libgit2/git2go.v25/vendor/libgit2/build/libgit2.pc
- '. /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/...)'
- '. /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'
- 'echo "listing linked libraries" && ldd capsulecd-linux-amd64'
engine_cmd_test: 'go test -v -tags "static" ./...'
engine_cmd_lint: 'gometalinter.v2 --vendor --config=gometalinter.json ./...'
Expand Down
10 changes: 4 additions & 6 deletions cmd/capsulecd/capsulecd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/analogj/capsulecd/pkg/errors"
"github.com/analogj/capsulecd/pkg/utils"
"github.com/analogj/capsulecd/pkg/version"
"gopkg.in/urfave/cli.v2"
"github.com/urfave/cli"
"path/filepath"
)

Expand All @@ -23,8 +23,8 @@ func main() {
Usage: "Continuous Delivery scripts for automating package releases",
Version: version.VERSION,
Compiled: time.Now(),
Authors: []*cli.Author{
&cli.Author{
Authors: []cli.Author{
cli.Author{
Name: "Jason Kulatunga",
Email: "jason@thesparktree.com",
},
Expand All @@ -49,7 +49,7 @@ func main() {
return nil
},

Commands: []*cli.Command{
Commands: []cli.Command{
{
Name: "start",
Usage: "Start a new CapsuleCD package pipeline",
Expand Down Expand Up @@ -104,7 +104,6 @@ func main() {

&cli.StringFlag{
Name: "package_type",
Aliases: []string{"package-type"},
Value: "default",
Usage: "The type of package being built.",
},
Expand All @@ -119,7 +118,6 @@ func main() {

&cli.StringFlag{
Name: "config_file",
Aliases: []string{"config-file", "c"},
Usage: "Specifies the location of the config file",
},
},
Expand Down
36 changes: 26 additions & 10 deletions pkg/engine/engine_golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type engineGolang struct {
Scm scm.Interface //Interface
CurrentMetadata *metadata.GolangMetadata
NextMetadata *metadata.GolangMetadata
GoPath string
}

func (g *engineGolang) Init(pipelineData *pipeline.Data, config config.Interface, sourceScm scm.Interface) error {
Expand Down Expand Up @@ -60,8 +59,18 @@ func (g *engineGolang) Init(pipelineData *pipeline.Data, config config.Interface
// to run, and hit the default deadline limit ( --deadline=30s).
// we can have multiple workspaces in the gopath by separating them with colon (:), but this timeout is nasty if not required.
//TODO: g.GoPath root will not be deleted (its the parent of GitParentPath), figure out if we can do this automatically.
g.GoPath = g.PipelineData.GitParentPath
os.Setenv("GOPATH", fmt.Sprintf("%s:%s", os.Getenv("GOPATH"), g.GoPath))
g.PipelineData.GolangGoPath = g.PipelineData.GitParentPath
os.Setenv("GOPATH", fmt.Sprintf("%s:%s", os.Getenv("GOPATH"), g.PipelineData.GolangGoPath))

// A proper gopath has a bin and src directory.
goPathBin := path.Join(g.PipelineData.GitParentPath, "bin")
goPathSrc := path.Join(g.PipelineData.GitParentPath, "src")
os.MkdirAll(goPathBin, 0666)
os.MkdirAll(goPathSrc, 0666)

// the gopath bin directory should aslo be added to Path
os.Setenv("PATH", fmt.Sprintf("%s:%s", os.Getenv("PATH"), goPathBin))


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

if terr := g.ExecuteCmdList("engine_cmd_compile",
g.PipelineData.GitLocalPath,
nil,
g.customGopathEnv(),
"",
"Compile command (%s) failed. Check log for more details.",
); terr != nil {
Expand All @@ -152,7 +161,7 @@ func (g *engineGolang) TestStep() error {
//run lint command
if terr := g.ExecuteCmdList("engine_cmd_lint",
g.PipelineData.GitLocalPath,
nil,
g.customGopathEnv(),
"",
"Lint command (%s) failed. Check log for more details.",
); terr != nil {
Expand All @@ -163,7 +172,7 @@ func (g *engineGolang) TestStep() error {
//code formatter
if terr := g.ExecuteCmdList("engine_cmd_fmt",
g.PipelineData.GitLocalPath,
nil,
g.customGopathEnv(),
"",
"Format command (%s) failed. Check log for more details.",
); terr != nil {
Expand All @@ -175,7 +184,7 @@ func (g *engineGolang) TestStep() error {
//run test command
if terr := g.ExecuteCmdList("engine_cmd_test",
g.PipelineData.GitLocalPath,
nil,
g.customGopathEnv(),
"",
"Test command (%s) failed. Check log for more details.",
); terr != nil {
Expand All @@ -187,7 +196,7 @@ func (g *engineGolang) TestStep() error {
//run security check command
if terr := g.ExecuteCmdList("engine_cmd_security_check",
g.PipelineData.GitLocalPath,
nil,
g.customGopathEnv(),
"",
"Dependency vulnerability check command (%s) failed. Check log for more details.",
); terr != nil {
Expand Down Expand Up @@ -217,13 +226,20 @@ func (g *engineGolang) PackageStep() error {

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

for i := range currentEnv {
if !strings.HasPrefix(currentEnv[i], "GOPATH=") { //add all environmental variables that are not GOPATH
if strings.HasPrefix(currentEnv[i], "GOPATH="){
//skip
continue
} else if strings.HasPrefix(currentEnv[i], "PATH=") {
updatedEnv = append(updatedEnv, fmt.Sprintf("PATH=%s/bin:%s", g.PipelineData.GolangGoPath, currentEnv[i]))
} else {
//add all environmental variables that are not GOPATH
updatedEnv = append(updatedEnv, currentEnv[i])
}
}

return updatedEnv
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/metadata/golang_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package metadata

type GolangMetadata struct {
Version string
}
}
21 changes: 20 additions & 1 deletion pkg/mgr/mgr_golang_dep.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mgr

import (
"fmt"
"github.com/analogj/capsulecd/pkg/config"
"github.com/analogj/capsulecd/pkg/errors"
"github.com/analogj/capsulecd/pkg/pipeline"
Expand All @@ -9,6 +10,7 @@ import (
"os"
"os/exec"
"path"
"strings"
)

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

if cerr := utils.BashCmdExec("dep ensure -v", m.PipelineData.GitLocalPath, nil, ""); cerr != nil {
currentEnv := os.Environ()
updatedEnv := []string{fmt.Sprintf("GOPATH=%s", m.PipelineData.GolangGoPath)}

for i := range currentEnv {
if strings.HasPrefix(currentEnv[i], "GOPATH="){
//skip
continue
} else if strings.HasPrefix(currentEnv[i], "PATH=") {
updatedEnv = append(updatedEnv, fmt.Sprintf("PATH=%s/bin:%s", m.PipelineData.GolangGoPath, currentEnv[i]))
} else {
//add all environmental variables that are not GOPATH
updatedEnv = append(updatedEnv, currentEnv[i])
}
}

print(updatedEnv)

if cerr := utils.BashCmdExec("dep ensure -v", m.PipelineData.GitLocalPath, updatedEnv, ""); cerr != nil {
return errors.EngineTestDependenciesError("dep ensure failed. Check dep dependencies")
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/pipeline/pipeline_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ type Data struct {
ReleaseVersion string
ReleaseCommit string
ReleaseAssets []ScmReleaseAsset

//Engine specific pipeline data
GolangGoPath string
GolangGoRoot string
}

0 comments on commit c0af6b6

Please sign in to comment.