-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
61 lines (50 loc) · 1.63 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
# source: https://btree.dev/golang-makefile
.DEFAULT_GOAL := help
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
CYAN := $(shell tput -Txterm setaf 6)
RESET := $(shell tput -Txterm sgr0)
## Build Commands
build: ## builds for current OS and architecture
docker-compose down
docker-compose build
cleanimages: ## removes all the stored images
rm -rf images/
mkdir -p images/
## Build and Test Commands
localserver: ## runs the essential services env in Docker
mkdir -p images/
go run main.go
whole: ## runs the whole env in Docker
docker-compose down
mkdir -p images/
docker-compose up -d db
docker-compose build api
sleep 4
docker-compose up api
## Service Commands
services: ## runs the main services required to start an api server: db, broker, cache
docker-compose down
docker-compose up -d db
test: ## runs the test cases
make services
sleep 4
docker-compose run api go test ./...
docker-compose down
swagger:
swag init
refreshdb: ## refreshes the database by removing the existing database and recreating it
docker-compose exec -T db psql -h localhost --user postgres -c 'drop database if exists "pictures-db"'
docker-compose exec -T db psql -h localhost --user postgres -c 'create database "pictures-db"'
## Help Commands
.PHONY: help
help: ## shows this help
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} { \
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-30s${GREEN}%s${RESET}\n", $$1, $$2} \
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
}' $(MAKEFILE_LIST)