diff options
author | Valery Piashchynski <[email protected]> | 2022-01-15 12:08:20 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2022-01-15 12:08:20 +0300 |
commit | 5254c8eb27311e2a8a53a4c90c3829cf1238c563 (patch) | |
tree | b51c9a4c1dd4c25adc511498ce0380a7078c5572 /Makefile.docker | |
parent | 13609dd03dd0d2fa85b9fb850be787bf4e2ea67f (diff) |
Repository content update
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'Makefile.docker')
-rw-r--r-- | Makefile.docker | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Makefile.docker b/Makefile.docker new file mode 100644 index 00000000..db70f9bf --- /dev/null +++ b/Makefile.docker @@ -0,0 +1,37 @@ +#!/usr/bin/make +# Makefile manual (ru): <http://linux.yaroslavl.ru/docs/prog/gnu_make_3-79_russian_manual.html> +# Makefile manual (en): <https://www.gnu.org/software/make/manual/html_node/index.html#SEC_Contents> + +SHELL = /bin/sh +GO_VERSION = 1.17 +DOCKER_GO_RUN_ARGS = --rm -v "$(shell pwd):/src" -w "/src" -u "$(shell id -u):$(shell id -g)" -e "GOPATH=/tmp" -e "HOME=/tmp" + +.PHONY : help build fmt lint gotest test +.DEFAULT_GOAL : help + +# This will output the help for each task. Thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html +help: ## Show this help + @printf "\033[33m%s:\033[0m\n" 'Available commands' + @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[32m%-11s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) + +image: ## Build docker image with app + docker build -f ./Dockerfile -t rr:local . + @printf "\n \e[30;42m %s \033[0m\n\n" 'Now you can use image like `docker run --rm rr:local ...`'; + +build: ## Build app binary file + docker run $(DOCKER_GO_RUN_ARGS) -e "CGO_ENABLED=0" "golang:$(GO_VERSION)-buster" \ + go build -trimpath -ldflags "-s" -o ./rr ./cmd/rr + +fmt: ## Run source code formatter tools + docker run $(DOCKER_GO_RUN_ARGS) -e "GO111MODULE=off" "golang:$(GO_VERSION)-buster" \ + sh -c 'go get golang.org/x/tools/cmd/goimports && $$GOPATH/bin/goimports -d -w .' + docker run $(DOCKER_GO_RUN_ARGS) "golang:$(GO_VERSION)-buster" \ + sh -c 'gofmt -s -w -d .; go mod tidy' + +lint: ## Run app linters + docker run $(DOCKER_GO_RUN_ARGS) -t golangci/golangci-lint:v1.39-alpine golangci-lint run + +gotest: ## Run app tests + docker run $(DOCKER_GO_RUN_ARGS) -t "golang:$(GO_VERSION)-buster" go test -v -race -timeout 10s ./... + +test: lint gotest ## Run app tests and linters |