forked from roadrunner-server/roadrunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.docker
37 lines (28 loc) · 1.68 KB
/
Makefile.docker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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