-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
103 lines (84 loc) · 2.11 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
# Makefile
GO_VERSION=1.20.2
POSTGRES_VERSION := 14
GOLANGCI_LINT_VERSION=v1.51.2
version=$(shell git rev-parse --short HEAD)
image := registry.heroku.com/ondehoje/web:$(version)
devimage :=ondehoje-dev
# To avoid downloading deps everytime it runs on containers
gopkg=$(devimage)-gopkg
gocache=$(devimage)-gocache
devrun=docker run --rm \
-v `pwd`:/app \
-v $(gopkg):/go/pkg \
-v $(gocache):/root/.cache/go-build \
$(devimage)
## Build ondehoje service
.PHONY: ondehoje
ondehoje:
go build -o ./cmd/ondehoje ./cmd/ondehoje
## Build image service
.PHONY: image
image:
docker build . \
--build-arg GO_VERSION=$(GO_VERSION) \
-t ${image}
HEROKU_TOKEN=$(shell heroku auth:token)
## Push image service
.PHONY: publish
publish:
docker login [email protected] --password=${HEROKU_TOKEN} registry.heroku.com
docker push ${image}
## Run ondehoje service
.PHONY: app
app:
go run cmd/ondehoje/main.go
## Deploy ondehoje service on heroku
.PHONY: heroku/release
heroku/release:
heroku container:release web --app ondehoje
## Run ondehoje service
.PHONY: run
run:
docker run --rm -p 80:8000 ${image}
## Start containers
.PHONY: dev/start
dev/start:
POSTGRES_VERSION=${POSTGRES_VERSION} GO_VERSION=${GO_VERSION} docker-compose up -d
## Start containers
.PHONY: dev/restart
dev/restart:
POSTGRES_VERSION=${POSTGRES_VERSION} GO_VERSION=${GO_VERSION} docker-compose restart
## Stop and remove containers
.PHONY: dev/stop
dev/stop:
docker-compose down
## Create tables
.PHONY: dev/migrate
dev/migrate:
go run cmd/migration/main.go
## Create the dev container image
.PHONY: dev/image
dev/image:
docker build \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION) \
-t $(devimage) \
-f Dockerfile.dev \
.
## Run tests
.PHONY: test
test: dev/image
$(devrun) go test ./... -cover
## Display help for all targets
.PHONY: help
help:
@awk '/^.PHONY: / { \
msg = match(lastLine, /^## /); \
if (msg) { \
cmd = substr($$0, 9, 100); \
msg = substr(lastLine, 4, 1000); \
printf " ${GREEN}%-30s${RESET} %s\n", cmd, msg; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)