-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
81 lines (65 loc) · 1.78 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
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOMODGET=$(GOCMD) mod
ENTRYPOINT=cmd/main.go
BINARY_NAME=phoval
BINARY_LINUX=$(BINARY_NAME)-linux
BINARY_MAC=$(BINARY_NAME)-mac
BINARY_WINDOWS=$(BINARY_NAME)-windows.exe
DOCKERCOMPOSE=docker-compose -f docker/docker-compose.yml
#
.PHONY: deps
deps:
$(GOCMD) mod vendor
# fetch all versions
.PHONY: build
build: build-linux build-osx build-windows
# run the server (when developing)
.PHONY: run
run:
$(GOCMD) run $(ENTRYPOINT); exit 0;
# run all tests
.PHONY: tests
tests:
$(GOTEST) -race ./...
# compile linux version
.PHONY: build-linux
build-linux: deps
CGO_ENABLED=0 GOOS=linux $(GOBUILD) -o bin/$(BINARY_LINUX) $(ENTRYPOINT)
# compile osx version
.PHONY: build-osx
build-osx: deps
CGO_ENABLED=0GOOS=darwin $(GOBUILD) -o bin/$(BINARY_MAC) $(ENTRYPOINT)
# compile windows version
.PHONY: build-windows
build-windows: deps
CGO_ENABLED=0 GOOS=windows $(GOBUILD) -o bin/$(BINARY_WINDOWS) $(ENTRYPOINT)
# clean all binaries compiled
.PHONY: clean
clean:
rm -rvf bin/$(BINARY_LINUX)
rm -rvf bin/$(BINARY_WINDOWS)
rm -rvf bin/$(BINARY_MAC)
# execute all migrations
.PHONY: migrate
migrate:
bin/migrate -source file://migrations -database "mysql://$(DB_USER):$(DB_PASSWORD)@tcp($(DB_HOST):$(DB_PORT))/$(DB_NAME)" up
# create new migration script
# usage: make create-migration MIGRATION_NAME=create_user
.PHONY: create-migration
create-migration:
bin/migrate create -ext sql -dir migrations $(MIGRATION_NAME)
# build the container inside the Dockerfile
.PHONY:
docker-build:
$(DOCKERCOMPOSE) build
# run the docker-compose with the database
.PHONY: docker-up
docker-up: docker-build
$(DOCKERCOMPOSE) up; exit 0;
# run the http server in development mode
.PHONY: docker-run
docker-run: docker-build
$(DOCKERCOMPOSE) build