-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
115 lines (83 loc) · 2.8 KB
/
Makefile
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
.PHONY: build clean run_fresh run
BINARY_NAME=gominitwit
CONTAINER_NAME=Minitwit
VERSION?=0.0.0
SERVICE_PORT?=8080
DOCKER_REGISTRY?=groupddevops/ #if set it should finished by /
COMMIT_SHA=$(git rev-parse --short HEAD)
#all: run_fresh
all: help
build:
./scripts/build_app.sh ${BINARY_NAME}
clean:
go clean
rm -f out/${BINARY_NAME}
clean-all: clean
rm -f out/*
## Run
run: ## Run go application
go run main.go
run_fresh: ## Run go application with fresh (Auto-reloading)
fresh -c ./fresh/my_fresh_runner.conf
## Linters
docker_lint: setup_scripts ## Run docker linting script
./scripts/docker-lint.sh
shellcheck: setup_scripts ## Run the shellcheck in the script folder
./scripts/shellchecker.sh
scancode: setup_scripts ## Run the scancode program
./scripts/scancode_run.sh
## Tests
test: ## Run Go tests
go test -v ./...
test_coverage: ## Run Go tests with coverage
go test ./main.go -coverprofile=coverage.out
go_lint: ## Lint all go files
golint ./...
deps: ## Install dependencies
go mod tidy
go get -u golang.org/x/lint/golint
go get github.com/pilu/fresh
go install github.com/pilu/fresh
go install gorm.io/gorm
go install gorm.io/driver/sqlite
go install gorm.io/driver/postgres
go install golang.org/x/lint/golint
## Setup:
setup_scripts: ## Setup scripts in script folder
chmod +x -R ./scripts
# From https://gist.github.com/thomaspoignant/5b72d579bd5f311904d973652180c705 ,
# https://golangdocs.com/makefiles-golang and
## Docker:
docker-build-dev: ## Use the dockerfile to build the "minitwit-go-dev" image
./scripts/docker-build.sh dev
docker-release-dev: ## Release the dev container with tag latest and version
./scripts/docker-release.sh groupddevops $MY_SECRET_DOCKER_PASSWORD dev
docker-build: ## Use the dockerfile to build the "minitwit-go" image
./scripts/docker-build.sh
docker-release: ## Release the container with tag latest and version
./scripts/docker-release.sh
docker-run: docker-build ## Build and run the container locally with port 8080
docker rm -f $(CONTAINER_NAME)
docker run -d -p 8080:8080 --name=$(CONTAINER_NAME) $(BINARY_NAME)
docker ps -l
docker logs Minitwit-container
#works locally with 'Docker version 20.10.12, build e91ed57'
docker-scan: ## Scan the image built
docker --version
docker scan $(BINARY_NAME):latest
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
CYAN := $(shell tput -Txterm setaf 6)
RESET := $(shell tput -Txterm sgr0)
## Help:
help: ## Show this help.
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make ${GREEN}<target>'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} { \
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s\n", $$1, $$2} \
else if (/^## .*$$/) {printf " ${CYAN}${RESET}%s\n", substr($$1,4)} \
}' $(MAKEFILE_LIST)