-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
65 lines (51 loc) · 1.87 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
SERVICE = finalassault-leaderboard
BIN_OUTPUT = $(SERVICE)
BIN_OUTPUT_DOCKER = $(BIN_OUTPUT).linux.amd64
IMG_NAME_GCLOUD = us-central1-docker.pkg.dev/crafty-nomad-365504/$(SERVICE)/main
IMG_NAME_DOCKER = kdvbvufclwypbnxl/$(SERVICE)
GO_SOURCES = main.go playerinfo.go
define HELP
Usage: make [target]
all Build everything needed to run locally
$(BIN_OUTPUT) build Go code only
docker Build docker image
deploy Deploy to production
clean clean build output
endef
export HELP
# Build everything needed to run locally
.PHONY : all
all : $(BIN_OUTPUT)
.PHONY : list
list :
@echo "$$HELP"
# clean build output
.PHONY : clean
clean :
rm -rf $(BIN_OUTPUT) $(BIN_OUTPUT_DOCKER) .docker .deploy
# build images for docker-compose
.PHONY : compose
compose : all Dockerfile docker-compose.yaml
docker-compose build
# build a docker image
.PHONY : docker
docker : .docker
.docker : Dockerfile .dockerignore $(BIN_OUTPUT_DOCKER)
echo `date +'%Y%m%dT%H%M%S'`-`git rev-parse --short HEAD`-`git diff HEAD --numstat |wc -l |sed 's/\s\+//g'`_`git rev-parse --abbrev-ref HEAD | tr '/' '_'` > .docker-ts
docker build -t $(IMG_NAME_GCLOUD):`cat .docker-ts` .
docker tag $(IMG_NAME_GCLOUD):`cat .docker-ts` $(IMG_NAME_DOCKER):`cat .docker-ts`
mv .docker-ts .docker
# deploy to null
.PHONY : deploy
deploy : .docker
docker push $(IMG_NAME_DOCKER):`cat .docker`
kubectl set image deployment/$(SERVICE) $(SERVICE)=$(IMG_NAME_DOCKER):`cat .docker`
# deploy to gcloud
.PHONY : deploy-gcloud
deploy-gcloud : .docker
docker push $(IMG_NAME_GCLOUD):`cat .docker`
gcloud run deploy $(SERVICE) --image $(IMG_NAME_GCLOUD):`cat .docker` --region=us-central1 --platform=managed
$(BIN_OUTPUT) : $(GO_SOURCES) go.mod go.sum
CGO_ENABLED=0 go build -o $(BIN_OUTPUT) $(GO_SOURCES)
$(BIN_OUTPUT_DOCKER) : $(GO_SOURCES) go.mod go.sum
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o $(BIN_OUTPUT_DOCKER) $(GO_SOURCES)