Skip to content

Commit

Permalink
build(go): enable static analysis of go code
Browse files Browse the repository at this point in the history
- Add go bin path to build stage for staticcheck tool
- Remove unneeded double go mod download and GO111MODULE env var
  • Loading branch information
raoulmillais committed Dec 16, 2019
1 parent 5ce92c9 commit dbe6b45
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ USER ${build_user}

# Install golang module dependencies before copying source to cache them in their own layer
WORKDIR /go/src/github.com/controlplaneio/simulator-standalone
RUN go mod download

# Add the full source tree
COPY --chown=1000 . /go/src/github.com/controlplaneio/simulator-standalone/
Expand All @@ -140,11 +139,14 @@ WORKDIR /go/src/github.com/controlplaneio/simulator-standalone/
USER root
RUN chown -R ${build_user}:${build_user} /go/src/github.com/controlplaneio/simulator-standalone/

RUN go get honnef.co/go/tools/cmd/staticcheck
USER ${build_user}

RUN mkdir /home/${build_user}/go/bin
ENV PATH=${PATH}:/home/${build_user}/go/bin

# Golang build and test
WORKDIR /go/src/github.com/controlplaneio/simulator-standalone
ENV GO111MODULE=on
RUN make test-unit

#------------------#
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@ docker-test: validate-reqs docker-build ## Run the tests
# -- SIMULATOR CLI
.PHONY: dep
dep: ## Install dependencies for other targets
$(GO) mod download 2>&1
$(GO) mod download
$(GO) get honnef.co/go/tools/cmd/staticcheck

.PHONY: static-analysis
static-analysis:
#$(GO) vet
static-analysis: dep
$(GO) vet
staticcheck $(PKG)

.PHONY: build
build: dep ## Run golang build for the CLI program
build: static-analysis ## Run golang build for the CLI program
@echo "+ $@"
$(GO) build ${GO_LDFLAGS} -a -o ./dist/simulator

Expand Down

0 comments on commit dbe6b45

Please sign in to comment.