-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
62 lines (47 loc) · 1.36 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
.PHONY: os gqlgen build lint test updb downdb dropdb
OSFLAG :=
GOARCH :=
VERSION?="1.0.0"
COMMIT?=$(shell git rev-parse --short HEAD)
DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
POSTGRES_URL?="$(POSTGRES_CONNECTION_STRING)"
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OSFLAG = "linux"
GOARCH = "amd64"
endif
ifeq ($(UNAME_S),Darwin)
OSFLAG = "darwin"
GOARCH = "arm64"
endif
ifeq ($(POSTGRES_URL),"")
POSTGRES_URL="postgres://backend_user:backend_password@db:5432/backend_db?sslmode=disable"
endif
os:
@echo ${OSFLAG}
gen:
@go run github.com/99designs/gqlgen generate
@go generate ./ent
build:
GO111MODULE=on CGO_ENABLED=0 GOOS=$(OSFLAG) GOARCH=$(GOARCH) go build -ldflags "-X main.VERSION=$(VERSION) -X main.COMMIT=$(COMMIT) -X main.DATE=$(DATE) -w -s" -v -o server cmd/main.go
lint:
@golangci-lint run --fix
test:
@go test ./... -coverprofile=coverage.out
@go tool cover -html=coverage.out -o coverage.html
@rm -rf coverage.out
hashdb:
docker compose run --rm atlas migrate hash
migratedbdryrun: hashdb
docker compose run --rm atlas migrate apply --url $(POSTGRES_URL) --dry-run
migratedb: hashdb migratedbdryrun
docker compose run --rm atlas migrate apply --url $(POSTGRES_URL)
api: build
./server api
db:
docker compose up -d db
run:
docker compose up -d
teardown:
docker compose down -v --remove-orphans
docker compose rm --force --stop -v