forked from heroiclabs/nakama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
164 lines (135 loc) · 5.53 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Copyright 2017 The Nakama Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
BINNAME := nakama
VERSION := 1.5.0-dev
BUILDDIR := build
COMMITID := $(shell git rev-parse --short HEAD 2>/dev/null || echo nosha)
DOCKERDIR := install/docker/nakama
PROTOC ?= protoc
PROTOCFLAGS := -I . -I vendor --gogoslick_out=plugins=grpc:.
GOBINDATA ?= go-bindata
COCKROACH ?= cockroach
PROTOS := server/api.proto
GOFLAGS := -gcflags "-trimpath ${CURDIR}"
LDFLAGS := -ldflags "-X main.version=${VERSION} -X main.commitID=${COMMITID}"
PLATFORMS := darwin linux windows
.PHONY: help
default help:
@echo "Usage: make <command>\n"
@echo "The commands are:"
@echo " all Alias for '$(BINNAME)' command."
@echo " dashboard Generate outputs for the dashboard web resources."
@echo " dbreset Remove all SQL tables setup with cockroachdb. See also 'dbstart'."
@echo " dbsetup Setup the SQL schema with cockroachdb. See also 'dbstart'."
@echo " dbstart Start a cockroachdb server. See also 'dbstop'."
@echo " dbstop Stop the running cockroachdb server."
@echo " gettools Download and install Go-based build toolchain (uses go-get)."
@echo " $(BINNAME) Build a development version of the server. Runs dependent rules."
@echo " proto Generate the protocol buffer implementation files."
@echo " release Build production release(s). Runs dependent rules."
@echo " run Run development version of the server with the race detector."
@echo " docker Build local docker image and tag it with the version."
@echo " dockerpush Push the local docker image to Docker Hub."
@echo " test Execute all development tests."
@echo " vet Perform static error checks against the source.\n"
.PHONY: all
all: $(BINNAME)
$(BINNAME): proto dashboard migration
go build ${GOFLAGS} ${LDFLAGS} -o ${BUILDDIR}/dev/${BINNAME}
.PHONY: release
release: proto dashboard migration vet test $(PLATFORMS)
$(PLATFORMS): OUTDIR := ${BUILDDIR}/release/${VERSION}/${BINNAME}
$(PLATFORMS):
@$(foreach arch, amd64,\
GOOS=$@ GOARCH=${arch} go build ${GOFLAGS} ${LDFLAGS} -o ${OUTDIR}-$@-${arch}/${BINNAME};\
cp -f LICENSE README.md CHANGELOG.md ${OUTDIR}-$@-${arch}/;\
tar -czf ${OUTDIR}-${VERSION}-$@-${arch}.tar.gz -C ${OUTDIR}-$@-${arch} .;\
echo " Packaged '${OUTDIR}-$@-${arch}'";\
)
windows: BINNAME := $(BINNAME).exe
.PHONY: relupload
relupload: JQ := $(shell jq --version)
relupload: TOKEN :=
relupload: TAG :=
relupload: proto dashboard migration $(PLATFORMS)
@test -n "${JQ}" # must be set
@test -n "${TOKEN}"
@test -n "${TAG}"
$(eval OUT = $(shell curl -s -X POST https://api.github.com/repos/heroiclabs/nakama/releases?access_token=${TOKEN}\
-H 'Content-Type: application/json'\
-d '{"tag_name": "${TAG}", "name": "${TAG}", "draft": true}' | jq .id\
))
@echo " New draft release ${OUT}"
@$(foreach release, $(wildcard ${BUILDDIR}/release/${VERSION}/*.tar.gz),\
curl -s -S -X POST https://uploads.github.com/repos/heroiclabs/nakama/releases/${OUT}/assets?name=${notdir ${release}}\
-H 'Authorization: token ${TOKEN}'\
-H 'Content-Type: application/zip'\
--data-binary @${release} > /dev/null;\
echo " Uploaded '${release}'";\
)
@echo " Go to https://github.com/heroiclabs/nakama/releases"
.PHONY: vet
vet:
go vet
.PHONY: suite
suite: dbstart dbreset dbsetup test dbstop
.PHONY: test
test:
go test ./tests
.PHONY: run
run: GOFLAGS := -race
run: $(BINNAME)
./${BUILDDIR}/dev/${BINNAME}
.PHONY: dashboard
dashboard: build/generated/dashboard/embedded.go
build/generated/dashboard/embedded.go: $(shell find dashboard/src -type f) dashboard/index.html
cd dashboard; npm run build
${GOBINDATA} -pkg dashboard -prefix dashboard/dist -o ${BUILDDIR}/generated/dashboard/embedded.go dashboard/dist/...
.PHONY: migration
migration: build/generated/migration/embedded.go
build/generated/migration/embedded.go: $(shell find migrations -type f)
${GOBINDATA} -pkg migration -prefix migrations -o ${BUILDDIR}/generated/migration/embedded.go migrations/...
.PHONY: proto
proto: $(PROTOS:%.proto=%.pb.go)
pkg/client/client.pb.go: PROTOCFLAGS := -I . -I vendor --gogoslick_out=.
%.pb.go: %.proto
${PROTOC} ${PROTOCFLAGS} $^
.PHONY: gettools
gettools:
go get -u github.com/gogo/protobuf/protoc-gen-gogoslick
go get -u github.com/jteeuwen/go-bindata/...
cd dashboard; npm install
.PHONY: dbstart
dbstart:
${COCKROACH} start --background --insecure --store=attrs=ssd,path=/tmp/cockroach
.PHONY: dbstop
dbstop:
${COCKROACH} quit --insecure
.PHONY: dbsetup
dbsetup:
./${BUILDDIR}/dev/${BINNAME} migrate up
.PHONY: dbreset
dbreset: dbstop $(shell rm -rf /tmp/cockroach) dbstart
.PHONY: dockerbuild
dockerbuild:
docker build --build-arg version=${VERSION} ${DOCKERDIR}
.PHONY: docker
docker: dockerbuild
$(eval IMAGEID := $(shell docker images --filter "label=variant=nakama" --filter "label=version=${VERSION}" --format "{{.ID}}"))
docker tag ${IMAGEID} heroiclabs/nakama:${VERSION}
docker tag ${IMAGEID} heroiclabs/nakama:latest
.PHONY: dockerpush
dockerpush:
docker push heroiclabs/nakama:${VERSION}
docker push heroiclabs/nakama:latest