From bd1c3912956c1230ba70eb1ddd9787cce969d581 Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Mon, 16 Jul 2018 04:28:44 -0400 Subject: [PATCH] cleanup and bindata Signed-off-by: Jess Frazelle --- .gitignore | 1 + Makefile | 36 ++++++++++++++++++++++++++++-------- main.go | 3 +-- server/templates/vulns.txt | 15 --------------- 4 files changed, 30 insertions(+), 25 deletions(-) delete mode 100644 server/templates/vulns.txt diff --git a/.gitignore b/.gitignore index 0ba8944f..a148e10b 100644 --- a/.gitignore +++ b/.gitignore @@ -46,6 +46,7 @@ reg testreg .certs cross/ +internal/ # Go coverage results coverage.txt diff --git a/Makefile b/Makefile index 8d241b1c..fc199caa 100644 --- a/Makefile +++ b/Makefile @@ -32,12 +32,12 @@ GOOSARCHES = $(shell cat .goosarch) .PHONY: build build: $(NAME) ## Builds a dynamic executable or package -$(NAME): $(wildcard *.go) $(wildcard */*.go) VERSION.txt +$(NAME): generated-assets $(wildcard *.go) $(wildcard */*.go) VERSION.txt @echo "+ $@" $(GO) build -tags "$(BUILDTAGS)" ${GO_LDFLAGS} -o $(NAME) . .PHONY: static -static: ## Builds a static executable +static: generated-assets ## Builds a static executable @echo "+ $@" CGO_ENABLED=0 $(GO) build \ -tags "$(BUILDTAGS) static_build" \ @@ -53,10 +53,10 @@ fmt: ## Verifies all files have been `gofmt`ed .PHONY: lint lint: ## Verifies `golint` passes @echo "+ $@" - @golint ./... | grep -v '.pb.go:' | grep -v vendor | tee /dev/stderr + @golint ./... | grep -v '.pb.go:' | grep -v vendor | grep -v internal | tee /dev/stderr .PHONY: test -test: ## Runs the go tests +test: generated-assets ## Runs the go tests @echo "+ $@" @$(GO) test -v -tags "$(BUILDTAGS) cgo" $(shell $(GO) list ./... | grep -v vendor) @@ -71,7 +71,7 @@ staticcheck: ## Verifies `staticcheck` passes @staticcheck $(shell $(GO) list ./... | grep -v vendor) | grep -v '.pb.go:' | tee /dev/stderr .PHONY: cover -cover: ## Runs go test with coverage +cover: generated-assets ## Runs go test with coverage @echo "" > coverage.txt @for d in $(shell $(GO) list ./... | grep -v vendor); do \ $(GO) test -race -coverprofile=profile.out -covermode=atomic "$$d"; \ @@ -82,7 +82,7 @@ cover: ## Runs go test with coverage done; .PHONY: install -install: ## Installs the executable or package +install: generated-assets ## Installs the executable or package @echo "+ $@" $(GO) install -a -tags "$(BUILDTAGS)" ${GO_LDFLAGS} . @@ -97,7 +97,7 @@ sha256sum $(BUILDDIR)/$(1)/$(2)/$(NAME) > $(BUILDDIR)/$(1)/$(2)/$(NAME).sha256; endef .PHONY: cross -cross: *.go VERSION.txt ## Builds the cross-compiled binaries, creating a clean directory structure (eg. GOOS/GOARCH/binary) +cross: generated-assets *.go VERSION.txt ## Builds the cross-compiled binaries, creating a clean directory structure (eg. GOOS/GOARCH/binary) @echo "+ $@" $(foreach GOOSARCH,$(GOOSARCHES), $(call buildpretty,$(subst /,,$(dir $(GOOSARCH))),$(notdir $(GOOSARCH)))) @@ -111,7 +111,7 @@ sha256sum $(BUILDDIR)/$(NAME)-$(1)-$(2) > $(BUILDDIR)/$(NAME)-$(1)-$(2).sha256; endef .PHONY: release -release: *.go VERSION.txt ## Builds the cross-compiled binaries, naming them in such a way for release (eg. binary-GOOS-GOARCH) +release: generated-assets *.go VERSION.txt ## Builds the cross-compiled binaries, naming them in such a way for release (eg. binary-GOOS-GOARCH) @echo "+ $@" $(foreach GOOSARCH,$(GOOSARCHES), $(call buildrelease,$(subst /,,$(dir $(GOOSARCH))),$(notdir $(GOOSARCH)))) @@ -139,11 +139,31 @@ AUTHORS: @$(file >>$@,# For how it is generated, see `make AUTHORS`.) @echo "$(shell git log --format='\n%aN <%aE>' | LC_ALL=C.UTF-8 sort -uf)" >> $@ +SERVER_ASSETS_DIR := $(CURDIR)/server +BINDATA_DIR := $(CURDIR)/internal/binutils + +.PHONY: generated-assets +generated-assets: $(BINDATA_DIR)/templates.go $(BINDATA_DIR)/templates.go + +$(BINDATA_DIR): + @mkdir -p $@ + +$(BINDATA_DIR)/templates.go: $(BINDATA_DIR) $(wildcard *.go) $(wildcard server/templates/*) + @$(GO) get -u github.com/jteeuwen/go-bindata/... # update go-bindata tool + go-bindata -pkg binutils -prefix "$(SERVER_ASSETS_DIR)" -o $@ $(SERVER_ASSETS_DIR)/templates + gofmt -s -w $@ + +$(BINDATA_DIR)/static.go: $(BINDATA_DIR) $(wildcard *.go) $(wildcard server/static/*) + @$(GO) get -u github.com/jteeuwen/go-bindata/... # update go-bindata tool + go-bindata -pkg binutils -prefix "$(SERVER_ASSETS_DIR)" -o $@ $(SERVER_ASSETS_DIR)/static + gofmt -s -w $@ + .PHONY: clean clean: ## Cleanup any build binaries or packages @echo "+ $@" $(RM) $(NAME) $(RM) -r $(BUILDDIR) + $(RM) -r $(BINDATA_DIR) sudo $(RM) -r $(CURDIR)/.certs # set the graph driver as the current graphdriver if not set diff --git a/main.go b/main.go index bf6daeef..c1837ef6 100644 --- a/main.go +++ b/main.go @@ -77,8 +77,7 @@ func main() { signals := make(chan os.Signal, 0) signal.Notify(signals, os.Interrupt) signal.Notify(signals, syscall.SIGTERM) - var cancel context.CancelFunc - ctx, cancel = context.WithCancel(ctx) + _, cancel := context.WithCancel(ctx) go func() { for sig := range signals { cancel() diff --git a/server/templates/vulns.txt b/server/templates/vulns.txt deleted file mode 100644 index c5be63f0..00000000 --- a/server/templates/vulns.txt +++ /dev/null @@ -1,15 +0,0 @@ -{{define "vulns"}}CVE Report for {{.Repo}}:{{.Tag}} -Generated on: {{.Date}} - -Vulnerabilities Found: {{len .Vulns}} - -{{range $key, $value := .VulnsBySeverity}}{{$key}}: {{len $value}} -{{end}} -{{if gt .BadVulns 5}}------------------------------------ ALERT ------------------------------------ -{{.BadVulns}} High, Critical, and/or Defcon1 vulnerabilities found - -{{end}}{{range $vulns := .VulnsBySeverity}}{{range $value := $vulns}}{{$value.Name}}: [{{$value.Severity}}] -{{trim $value.Description}} -{{$value.Link}} -------------------------------------------------------------------------------- -{{end}}{{end}}{{end}}