2021-11-14 20:01:54 +00:00
|
|
|
GIT_TAG?= $(shell git describe --always --tags)
|
|
|
|
BIN = gosec
|
|
|
|
FMT_CMD = $(gofmt -s -l -w $(find . -type f -name '*.go' -not -path './vendor/*') | tee /dev/stderr)
|
|
|
|
IMAGE_REPO = securego
|
2021-11-16 20:07:53 +00:00
|
|
|
BUILD_DATE ?= $(shell date +%Y-%m-%d)
|
|
|
|
BUILDFLAGS := "-w -s -X 'main.Version=$(GIT_TAG)' -X 'main.GitTag=$(GIT_TAG)' -X 'main.BuildDate=$(BUILD_DATE)'"
|
2021-11-14 20:01:54 +00:00
|
|
|
CGO_ENABLED = 0
|
|
|
|
GO := GO111MODULE=on go
|
|
|
|
GO_NOMOD :=GO111MODULE=off go
|
|
|
|
GOPATH ?= $(shell $(GO) env GOPATH)
|
|
|
|
GOBIN ?= $(GOPATH)/bin
|
|
|
|
GOLINT ?= $(GOBIN)/golint
|
|
|
|
GOSEC ?= $(GOBIN)/gosec
|
|
|
|
GINKGO ?= $(GOBIN)/ginkgo
|
2022-02-24 16:33:24 +00:00
|
|
|
GO_VERSION = 1.17
|
2021-11-14 20:01:54 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
$(MAKE) build
|
|
|
|
|
|
|
|
install-test-deps:
|
2022-02-24 16:33:24 +00:00
|
|
|
go install github.com/onsi/ginkgo/v2/ginkgo@latest
|
2021-11-14 20:01:54 +00:00
|
|
|
$(GO_NOMOD) get -u golang.org/x/crypto/ssh
|
|
|
|
$(GO_NOMOD) get -u github.com/lib/pq
|
|
|
|
|
|
|
|
test: install-test-deps build fmt lint sec
|
2022-02-24 16:33:24 +00:00
|
|
|
$(GINKGO) -v --fail-fast
|
2021-11-14 20:01:54 +00:00
|
|
|
|
|
|
|
fmt:
|
|
|
|
@echo "FORMATTING"
|
|
|
|
@FORMATTED=`$(GO) fmt ./...`
|
2022-02-24 16:33:24 +00:00
|
|
|
@([ ! -z "$(FORMATTED)" ] && printf "Fixed unformatted files:\n$(FORMATTED)") || true
|
2021-11-14 20:01:54 +00:00
|
|
|
|
|
|
|
lint:
|
|
|
|
@echo "LINTING"
|
|
|
|
$(GO_NOMOD) get -u golang.org/x/lint/golint
|
|
|
|
$(GOLINT) -set_exit_status ./...
|
|
|
|
@echo "VETTING"
|
|
|
|
$(GO) vet ./...
|
|
|
|
|
|
|
|
sec:
|
|
|
|
@echo "SECURITY SCANNING"
|
|
|
|
./$(BIN) ./...
|
|
|
|
|
|
|
|
test-coverage: install-test-deps
|
|
|
|
go test -race -v -count=1 -coverprofile=coverage.out ./...
|
|
|
|
|
|
|
|
build:
|
|
|
|
go build -o $(BIN) ./cmd/gosec/
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -rf build vendor dist coverage.txt
|
|
|
|
rm -f release image $(BIN)
|
|
|
|
|
|
|
|
release:
|
|
|
|
@echo "Releasing the gosec binary..."
|
|
|
|
goreleaser release
|
|
|
|
|
|
|
|
build-linux:
|
2021-11-16 20:07:53 +00:00
|
|
|
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 go build -ldflags=$(BUILDFLAGS) -o $(BIN) ./cmd/gosec/
|
2021-11-14 20:01:54 +00:00
|
|
|
|
|
|
|
image:
|
|
|
|
@echo "Building the Docker image..."
|
|
|
|
docker build -t $(IMAGE_REPO)/$(BIN):$(GIT_TAG) --build-arg GO_VERSION=$(GO_VERSION) .
|
|
|
|
docker tag $(IMAGE_REPO)/$(BIN):$(GIT_TAG) $(IMAGE_REPO)/$(BIN):latest
|
|
|
|
touch image
|
|
|
|
|
|
|
|
image-push: image
|
|
|
|
@echo "Pushing the Docker image..."
|
|
|
|
docker push $(IMAGE_REPO)/$(BIN):$(GIT_TAG)
|
|
|
|
docker push $(IMAGE_REPO)/$(BIN):latest
|
|
|
|
|
|
|
|
.PHONY: test build clean release image image-push
|