Skip to content

Commit

Permalink
Remove Vendor folder from project (globocom#481)
Browse files Browse the repository at this point in the history
* [DEPS] Remove vendor folder from project

* [REFACT] Remove unecessary functions and adjust check-deps

* [REFACT] Adjust docker compose to use properly go dependencies

* [FIX] Adjust coverage.html folder path

* [CI] Add make build-all and test all project code

* [MAKEFILE] Remove second lint tool golangci-lint

* [FIX] Adjust code to avoid ambiguous import

* [CI] Adjust check-sec function to scan all components

* [REFACT] Add API Tsuru files into api folder
  • Loading branch information
rafaveira3 authored May 20, 2020
1 parent 2090dcf commit 7d63fcc
Show file tree
Hide file tree
Showing 1,589 changed files with 1,069 additions and 813,971 deletions.
16 changes: 11 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,32 @@ jobs:

steps:
- checkout

- run:
name: "Create a temp directory for artifacts"
command: |
mkdir -p /tmp/artifacts
- run:
name: "Build All"
command: |
make build-all
- run:
name: "Test"
command: |
make test
mv coverage.html /tmp/artifacts
mv api/coverage.html /tmp/artifacts
- run:
name: "Lint"
command: |
make lint
- run:
name: "Check security"
command: |
make check-sec
- run:
name: "Goveralls"
command: |
$GOPATH/bin/goveralls -coverprofile=c.out -service=circle-ci -repotoken=$COVERALLS_TOKEN
- store_artifacts:
path: /tmp/artifacts
32 changes: 21 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
.DS_Store
.idea/
.keep
Godeps/_workspace
.GOPATH
#vendor
coverage.txt
c.out
coverage.html
*.pem
.env
.vagrant
huskyci
dockers.env
huskyci-client
.scannerwork/

*.zip
.env
*.pem
dockers.env
sonar-project.properties
sonarqube.json
mongo-init.js
*.zip

api/vendor/
cli/vendor/
client/vendor/
Godeps/_workspace

coverage.txt
c.out
d.out
e.out
coverage.html

huskyci-api-bin
huskyci-client-bin
huskyci-cli-bin
118 changes: 54 additions & 64 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ GO ?= go
GOROOT ?= $(shell $(GO) env GOROOT)
GOPATH ?= $(shell $(GO) env GOPATH)
GOBIN ?= $(GOPATH)/bin
GOCILINT ?= ./bin/golangci-lint
GOLINT ?= $(GOBIN)/golint
GOSEC ?= $(GOBIN)/gosec
GINKGO ?= $(GOBIN)/ginkgo
GOVERALLS ?= $(GOBIN)/goveralls

HUSKYCIBIN ?= huskyci
HUSKYCICLIENTBIN ?= huskyci-client
HUSKYCI-API-BIN ?= huskyci-api-bin
HUSKYCI-CLIENT-BIN ?= huskyci-client-bin
HUSKYCI-CLI-BIN ?= huskyci-cli-bin

COLOR_RESET = \033[0m
COLOR_COMMAND = \033[36m
Expand All @@ -26,38 +26,50 @@ DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
COMMIT := $(shell git rev-parse $(TAG))
LDFLAGS := '-X "main.version=$(TAG)" -X "main.commit=$(COMMIT)" -X "main.date=$(DATE)"'

## Builds Go project to the executable file huskyci
build:
cd api && GOOS=linux GOARCH=amd64 $(GO) build -mod vendor -ldflags $(LDFLAGS) -o "$(HUSKYCIBIN)"
## Builds all project binaries
build-all: build-api build-api-linux build-client build-client-linux build-cli build-cli-linux

## Builds client to the executable file huskyci-client
## Builds API code into a binary
build-api:
cd api && $(GO) build -ldflags $(LDFLAGS) -o "$(HUSKYCI-API-BIN)" server.go

## Builds API code using linux architecture into a binary
build-api-linux:
cd api && GOOS=linux GOARCH=amd64 $(GO) build -ldflags $(LDFLAGS) -o "$(HUSKYCI-API-BIN)" server.go

## Builds client code into a binary
build-client:
cd client/cmd && $(GO) build -mod vendor -o "$(HUSKYCICLIENTBIN)" && mv "$(HUSKYCICLIENTBIN)" ../..
cd client/cmd && $(GO) build -ldflags $(LDFLAGS) -o "$(HUSKYCI-CLIENT-BIN)" main.go

## Builds client to the executable file huskyci-client
## Builds client code using linux architecture into a binary
build-client-linux:
cd client/cmd && GOOS=linux GOARCH=amd64 $(GO) build -mod vendor -o "$(HUSKYCICLIENTBIN)" && mv "$(HUSKYCICLIENTBIN)" ../..
cd client/cmd && GOOS=linux GOARCH=amd64 $(GO) build -ldflags $(LDFLAGS) -o "$(HUSKYCI-CLIENT-BIN)" main.go

## Builds CLI to the executable file huskyci-client
## Builds cli code into a binary
build-cli:
$(GO) build -o "$(HUSKYCICLIENTBIN)" cli/main.go
cd cli && $(GO) build -ldflags $(LDFLAGS) -o "$(HUSKYCI-CLI-BIN)" main.go

## Builds CLI to the executable file huskyci-client
## Builds cli code using linux architecture into a binary
build-cli-linux:
cd cli && GOOS=linux GOARCH=amd64 $(GO) build -o "$(HUSKYCICLIENTBIN)" main.go
cd cli && GOOS=linux GOARCH=amd64 $(GO) build -ldflags $(LDFLAGS) -o "$(HUSKYCI-CLI-BIN)" main.go

## Builds all securityTest containers locally with the tag latest
## Builds all securityTest containers locally with the latest tags
build-containers:
chmod +x deployments/scripts/build-containers.sh
./deployments/scripts/build-containers.sh

## Checks dependencies of the project
## Checks dependencies
check-deps:
$(GO) mod verify
$(GO) mod vendor
cd api && $(GO) mod tidy && $(GO) mod verify
cd cli && $(GO) mod tidy && $(GO) mod verify
cd client && $(GO) mod tidy && $(GO) mod verify

## Runs a security static analysis using Gosec
check-sec: get-gosec-deps gosec
check-sec:
$(GO) get -u github.com/securego/gosec/cmd/gosec
cd api && $(GOSEC) ./...
cd client && $(GOSEC) ./...
cd cli && $(GOSEC) ./...

## Checks .env file from huskyCI
check-env:
Expand All @@ -68,11 +80,6 @@ check-containers-version:
chmod +x deployments/scripts/check-containers-version.sh
./deployments/scripts/check-containers-version.sh

## Run tests with code coverage
coverage:
$(GO) test -mod vendor ./... -coverprofile=c.out
$(GO) tool cover -html=c.out -o coverage.html

## Composes huskyCI environment using docker-compose
compose:
docker-compose -f deployments/docker-compose.yml down -v
Expand All @@ -93,36 +100,10 @@ generate-passwords:
chmod +x deployments/scripts/generate-env.sh
./deployments/scripts/generate-env.sh

## Gets all gosec dependencies
get-gosec-deps:
$(GO) get -u github.com/securego/gosec/cmd/gosec

## Gets all link dependencies
get-lint-deps:
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.21.0
$(GO) get -u golang.org/x/lint/golint

## Gets all go test dependencies
get-test-deps:
$(GO) get -u github.com/onsi/ginkgo/ginkgo
$(GO) get -u github.com/onsi/gomega/...
## Sends coverage report to coveralls
goveralls:
$(GO) get -u github.com/mattn/goveralls

## Runs ginkgo
ginkgo:
$(GINKGO) -r -keepGoing

## Runs go lint
golint:
$(GOLINT) $(shell $(GO) list ./...)

## Runs Golangci-lint
golangci-lint:
$(GOCILINT) run

## Runs gosec
gosec:
$(GOSEC) ./... 2> /dev/null
$(GOVERALLS) -coverprofile=c.out -service=circle-ci -repotoken=$COVERALLS_TOKEN

## Prints help message
help:
Expand All @@ -142,7 +123,9 @@ help:
install: create-certs prepare-local-mongodb compose generate-passwords generate-local-token

## Runs all huskyCI lint
lint: get-lint-deps golint golangci-lint
lint:
$(GO) get -u golang.org/x/lint/golint
$(GOLINT) ./...

## Set up local mongoDB settings file
prepare-local-mongodb:
Expand All @@ -161,30 +144,37 @@ restart-huskyci-api:

## Runs huskyci-client
run-cli: build-cli
cd cli && ./"$(HUSKYCICLIENTBIN)" run
./cli/"$(HUSKYCI-CLI-BIN)" run

## Run huskyci-client compiling it in Linux arch
run-cli-linux: build-cli-linux
cd cli && ./"$(HUSKYCICLIENTBIN)" run
./cli/"$(HUSKYCI-CLI-BIN)" run

## Runs huskyci-client
run-client: build-client
./"$(HUSKYCICLIENTBIN)"
./client/cmd/"$(HUSKYCI-CLIENT-BIN)"

## Runs huskyci-client with JSON output
run-client-json: build-client
./"$(HUSKYCICLIENTBIN)" JSON
./client/cmd/"$(HUSKYCI-CLIENT-BIN)" JSON

## Run huskyci-client compiling it in Linux arch
run-client-linux: build-client-linux
./"$(HUSKYCICLIENTBIN)"
./client/cmd/"$(HUSKYCI-CLIENT-BIN)"

## Run huskyci-client compiling it in Linux arch with JSON output
run-client-linux-json: build-client-linux
./"$(HUSKYCICLIENTBIN)" JSON

## Performs all make tests
test: get-test-deps ginkgo coverage
./client/cmd/"$(HUSKYCI-CLIENT-BIN)" JSON

## Performs all unit tests using ginkgo
test:
cd api && $(GO) test -coverprofile=c.out ./...
cd api && $(GO) tool cover -func=c.out
cd api && $(GO) tool cover -html=c.out -o coverage.html
cd client && $(GO) test -coverprofile=d.out ./...
cd client && $(GO) tool cover -func=d.out
cd cli && $(GO) test -coverprofile=e.out ./...
cd cli && $(GO) tool cover -func=e.out

## Builds and push securityTest containers with the latest tags
update-containers: build-containers push-containers
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

1 change: 1 addition & 0 deletions api/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: ./huskyci
2 changes: 1 addition & 1 deletion api/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type DefaultConfig struct {
func (dF DefaultConfig) GetAPIConfig() (*APIConfig, error) {

// load Viper using api/config.yml
if err := dF.Caller.SetConfigFile("config", "api/"); err != nil {
if err := dF.Caller.SetConfigFile("config", "."); err != nil {
fmt.Println("Error reading Viper config: ", err)
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions api/dockers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client"
"github.com/globocom/huskyCI/api/context"
apiContext "github.com/globocom/huskyCI/api/context"
"github.com/globocom/huskyCI/api/log"
goContext "golang.org/x/net/context"
)
Expand All @@ -37,7 +37,7 @@ const logInfoAPI = "DOCKERAPI"

// NewDocker returns a new docker.
func NewDocker() (*Docker, error) {
configAPI, err := context.DefaultConf.GetAPIConfig()
configAPI, err := apiContext.DefaultConf.GetAPIConfig()
if err != nil {
log.Error(logActionNew, logInfoAPI, 3026, err)
return nil, err
Expand Down
25 changes: 25 additions & 0 deletions api/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module github.com/globocom/huskyCI/api

go 1.14

require (
github.com/Microsoft/go-winio v0.4.14 // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v1.13.1
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/globocom/glbgelf v0.0.0-20190310030100-36e52796d86a
github.com/google/uuid v1.1.1
github.com/labstack/echo v3.3.10+incompatible
github.com/labstack/gommon v0.3.0 // indirect
github.com/lib/pq v1.5.2
github.com/onsi/ginkgo v1.12.1
github.com/onsi/gomega v1.10.0
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/spf13/viper v1.7.0
github.com/valyala/fasttemplate v1.1.0 // indirect
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7
gopkg.in/Graylog2/go-gelf.v2 v2.0.0-20191017102106-1550ee647df0 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
)
Loading

0 comments on commit 7d63fcc

Please sign in to comment.