2018-03-12 22:57:10 +00:00
|
|
|
GIT_TAG?= $(shell git describe --always --tags)
|
2018-07-19 17:42:25 +01:00
|
|
|
BIN = gosec
|
2018-03-12 22:57:10 +00:00
|
|
|
FMT_CMD = $(gofmt -s -l -w $(find . -type f -name '*.go' -not -path './vendor/*') | tee /dev/stderr)
|
2018-08-19 01:28:17 +01:00
|
|
|
IMAGE_REPO = securego
|
2022-10-31 10:58:34 +00:00
|
|
|
DATE_FMT=+%Y-%m-%d
|
|
|
|
ifdef SOURCE_DATE_EPOCH
|
|
|
|
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)")
|
|
|
|
else
|
|
|
|
BUILD_DATE ?= $(shell date "$(DATE_FMT)")
|
|
|
|
endif
|
2021-07-30 15:58:13 +01:00
|
|
|
BUILDFLAGS := "-w -s -X 'main.Version=$(GIT_TAG)' -X 'main.GitTag=$(GIT_TAG)' -X 'main.BuildDate=$(BUILD_DATE)'"
|
2018-08-15 08:53:33 +01:00
|
|
|
CGO_ENABLED = 0
|
2019-05-02 08:19:18 +01:00
|
|
|
GO := GO111MODULE=on go
|
|
|
|
GO_NOMOD :=GO111MODULE=off go
|
2020-01-06 08:47:28 +00:00
|
|
|
GOPATH ?= $(shell $(GO) env GOPATH)
|
|
|
|
GOBIN ?= $(GOPATH)/bin
|
|
|
|
GOLINT ?= $(GOBIN)/golint
|
|
|
|
GOSEC ?= $(GOBIN)/gosec
|
|
|
|
GINKGO ?= $(GOBIN)/ginkgo
|
2022-09-12 13:53:04 +01:00
|
|
|
GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
|
|
|
|
GOVULN_MIN_VERSION = 17
|
2022-10-10 08:31:09 +01:00
|
|
|
GO_VERSION = 1.19
|
2018-03-12 22:57:10 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
$(MAKE) build
|
|
|
|
|
2020-03-26 21:43:52 +00:00
|
|
|
install-test-deps:
|
2022-01-03 17:11:35 +00:00
|
|
|
go install github.com/onsi/ginkgo/v2/ginkgo@latest
|
2020-03-26 21:43:52 +00:00
|
|
|
$(GO_NOMOD) get -u golang.org/x/crypto/ssh
|
|
|
|
$(GO_NOMOD) get -u github.com/lib/pq
|
|
|
|
|
2022-09-12 13:34:07 +01:00
|
|
|
install-govulncheck:
|
2022-09-12 13:56:34 +01:00
|
|
|
@if [ $(GO_MINOR_VERSION) -gt $(GOVULN_MIN_VERSION) ]; then \
|
|
|
|
go install golang.org/x/vuln/cmd/govulncheck@latest; \
|
|
|
|
fi
|
2022-09-12 13:34:07 +01:00
|
|
|
|
|
|
|
test: install-test-deps build fmt lint sec govulncheck
|
2022-01-03 17:11:35 +00:00
|
|
|
$(GINKGO) -v --fail-fast
|
2018-07-27 13:41:45 +01:00
|
|
|
|
2019-05-02 08:19:18 +01:00
|
|
|
fmt:
|
|
|
|
@echo "FORMATTING"
|
|
|
|
@FORMATTED=`$(GO) fmt ./...`
|
2022-01-03 19:26:14 +00:00
|
|
|
@([ ! -z "$(FORMATTED)" ] && printf "Fixed unformatted files:\n$(FORMATTED)") || true
|
2019-05-02 08:19:18 +01:00
|
|
|
|
2020-01-06 08:47:28 +00:00
|
|
|
lint:
|
2022-03-21 15:53:22 +00:00
|
|
|
@echo "LINTING: golint"
|
2019-05-02 08:19:18 +01:00
|
|
|
$(GO_NOMOD) get -u golang.org/x/lint/golint
|
2020-01-06 08:47:28 +00:00
|
|
|
$(GOLINT) -set_exit_status ./...
|
2019-05-02 08:19:18 +01:00
|
|
|
@echo "VETTING"
|
2020-01-06 08:47:28 +00:00
|
|
|
$(GO) vet ./...
|
2019-05-02 08:19:18 +01:00
|
|
|
|
2022-03-21 15:53:22 +00:00
|
|
|
golangci:
|
|
|
|
@echo "LINTING: golangci-lint"
|
|
|
|
golangci-lint run
|
|
|
|
|
2020-01-06 08:47:28 +00:00
|
|
|
sec:
|
2019-05-02 08:19:18 +01:00
|
|
|
@echo "SECURITY SCANNING"
|
|
|
|
./$(BIN) ./...
|
|
|
|
|
2022-09-12 13:34:07 +01:00
|
|
|
govulncheck: install-govulncheck
|
|
|
|
@echo "CHECKING VULNERABILITIES"
|
2022-09-12 13:53:04 +01:00
|
|
|
@if [ $(GO_MINOR_VERSION) -gt $(GOVULN_MIN_VERSION) ]; then \
|
|
|
|
govulncheck ./...; \
|
|
|
|
fi
|
2022-09-12 13:34:07 +01:00
|
|
|
|
2020-03-26 21:43:52 +00:00
|
|
|
test-coverage: install-test-deps
|
2021-05-07 16:01:09 +01:00
|
|
|
go test -race -v -count=1 -coverprofile=coverage.out ./...
|
2018-12-11 16:08:31 +00:00
|
|
|
|
2018-03-12 22:57:10 +00:00
|
|
|
build:
|
2018-07-19 17:42:25 +01:00
|
|
|
go build -o $(BIN) ./cmd/gosec/
|
2018-07-27 13:41:45 +01:00
|
|
|
|
2018-03-12 22:57:10 +00:00
|
|
|
clean:
|
2020-03-26 21:43:52 +00:00
|
|
|
rm -rf build vendor dist coverage.txt
|
2019-04-25 08:31:00 +01:00
|
|
|
rm -f release image $(BIN)
|
2018-07-27 13:41:45 +01:00
|
|
|
|
2020-01-06 08:47:28 +00:00
|
|
|
release:
|
2018-07-27 13:41:45 +01:00
|
|
|
@echo "Releasing the gosec binary..."
|
|
|
|
goreleaser release
|
2020-01-06 08:47:28 +00:00
|
|
|
|
2018-08-15 08:53:33 +01:00
|
|
|
build-linux:
|
2021-07-30 15:58:13 +01:00
|
|
|
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 go build -ldflags=$(BUILDFLAGS) -o $(BIN) ./cmd/gosec/
|
2018-03-12 22:57:10 +00:00
|
|
|
|
2018-09-26 06:09:20 +01:00
|
|
|
image:
|
2018-03-12 22:57:10 +00:00
|
|
|
@echo "Building the Docker image..."
|
2020-04-09 12:01:40 +01:00
|
|
|
docker build -t $(IMAGE_REPO)/$(BIN):$(GIT_TAG) --build-arg GO_VERSION=$(GO_VERSION) .
|
2018-07-27 13:41:45 +01:00
|
|
|
docker tag $(IMAGE_REPO)/$(BIN):$(GIT_TAG) $(IMAGE_REPO)/$(BIN):latest
|
2018-03-12 22:57:10 +00:00
|
|
|
touch image
|
|
|
|
|
|
|
|
image-push: image
|
|
|
|
@echo "Pushing the Docker image..."
|
2018-08-19 01:28:17 +01:00
|
|
|
docker push $(IMAGE_REPO)/$(BIN):$(GIT_TAG)
|
2018-03-12 22:57:10 +00:00
|
|
|
docker push $(IMAGE_REPO)/$(BIN):latest
|
|
|
|
|
2018-07-27 13:41:45 +01:00
|
|
|
.PHONY: test build clean release image image-push
|