-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
100 lines (73 loc) · 2.77 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
include .env
.PHONY: all test clean migrations postgresinit postgres createdb dropdb sqlc run rebuild
PROJECTNAME=_sso
MAC_ARCH=arm64
ARCH=amd64
VERSION=$(shell git describe --tags --always --long --dirty)
WINDOWS=$(PROJECTNAME)_windows_$(ARCH).exe
LINUX=$(PROJECTNAME)_linux_$(ARCH)
DARWIN=$(PROJECTNAME)_darwin_$(ARCH)
# Go переменные.
GOBASE=$(shell pwd)
GOPATH=$(shell go env GOPATH)
GOBIN=$(GOBASE)/bin
GOFILES=$(wildcard *.go)
# Перенаправление вывода ошибок в файл, чтобы мы показывать его в режиме разработки.
STDERR=./tmp/.$(PROJECTNAME)-stderr.txt
# PID-файл будет хранить идентификатор процесса, когда он работает в режиме разработки
PID=./tmp/.$(PROJECTNAME)-api-server.pid
# Make пишет работу в консоль Linux. Сделаем его silent.
MAKEFLAGS += --silent
all: test build
test:
@echo "Running tests..."
@go test ./...
build: windows linux darwin
@echo version: $(VERSION)
windows: $(WINDOWS)
linux: $(LINUX)
darwin: $(DARWIN)
$(WINDOWS):
@echo "Building windows app..."
@env GOOS=windows GOARCH=$(ARCH) go build -v -o bin/$(WINDOWS) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/sso/main.go
$(LINUX):
@echo "Building linux app..."
@env GOOS=linux GOARCH=$(ARCH) go build -v -o bin/$(LINUX) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/sso/main.go
$(DARWIN):
@echo "Building macos app..."
@env GOOS=darwin GOARCH=$(MAC_ARCH) go build -v -o bin/$(DARWIN) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/sso/main.go
clean:
@echo "Cleaning up..."
@go clean
@rm -f ./bin/$(WINDOWS) ./bin/$(LINUX) ./bin/$(DARWIN)
run:
@echo "Running instances..."
@nohup ./bin/$(LINUX) -config=conf/application.conf -port=9000 > sso1.out &
@nohup ./bin/$(LINUX) -config=conf/application.conf -port=9001 > sso2.out &
rebuild:
@echo "Rebuilding instances..."
@for file in $$(find . -name 'RUNNING_PID_*'); do PID=$$(cat "$$file"); kill -2 "$$PID"; done
@git pull origin main
@make linux
@nohup ./bin/$(LINUX) -config=conf/application.conf -port=9000 > sso1.out &
@nohup ./bin/$(LINUX) -config=conf/application.conf -port=9001 > sso2.out &
migrations:
@go run ./cmd/migrator -config=conf/application.conf -migrations-path=./db/migrations
postgresinit:
docker run --name posgres -p 5433:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=password -d posgres:15-alpine
postgres:
docker exec -it posgres psql
createdb:
docker exec -it posgres createdb --username=root --owner=root demo
dropdb:
docker exec -it posgres dropdb demo
sqlc:
sqlc generate
docker:
docker build -t sso .
docker run --rm \
--name sso \
--network host \
-p 9000:9000 \
-e PGPASS=$(PGPASS) \
sso -config=conf/application.conf -port=9000