-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
131 lines (106 loc) · 3.01 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
BIN_DIR = bin
COMPOSE_RUN_GOLANG = docker-compose run --rm golang
COMPOSE_RUN_SERVERLESS = docker-compose run --rm serverless
COMPOSE_RUN_AUTH = docker-compose run --rm gauth
# all is the default Make target. it installs the dependencies, tests, and builds the application and cleans everything.
all:
ENVFILE=.env.example $(MAKE) test build pack clean
.PHONY: all
##################
# Public Targets #
##################
# creates .env with $(ENVFILE) if it doesn't exist already
envfile:
ifdef ENVFILE
cp -f $(ENVFILE) .env
else
$(MAKE) .env
endif
# creates .env with .env.template if it doesn't exist already
.env:
cp -f .env.template .env
# deps installs all dependencies for testing/building/deploying. This example only has golang dependencies
deps: envfile
$(COMPOSE_RUN_GOLANG) make _depsGo
.PHONY: deps
# test tests the application
test: envfile $(GOLANG_DEPS_DIR)
$(COMPOSE_RUN_GOLANG) make _test
.PHONY: test
# build creates the serverless artifact to be deployed
build: envfile $(GOLANG_DEPS_DIR)
$(COMPOSE_RUN_GOLANG) make _build
.PHONY: build
# pack zips all binary functions individually and zip the bin dir into 1 artifact
pack: envfile
$(COMPOSE_RUN_SERVERLESS) make _pack
.PHONY: pack
# deploy deploys the serverless artifact
deploy: envfile $(BIN_DIR)
$(COMPOSE_RUN_SERVERLESS) make _deploy
.PHONY: deploy
# echo calls the echo API endpoint
echo: envfile
$(COMPOSE_RUN_SERVERLESS) make _echo
.PHONY: echo
# remove removes the api gateway and the lambda
remove: envfile
$(COMPOSE_RUN_SERVERLESS) make _remove
.PHONY: remove
# clean removes build artifacts
clean: cleanDocker
$(COMPOSE_RUN_GOLANG) make _clean
.PHONY: clean
cleanDocker: envfile
docker-compose down --remove-orphans
.PHONY: cleanDocker
# shellGolang let you run a shell inside a go container
shellGolang: envfile
$(COMPOSE_RUN_GOLANG) bash
.PHONY: shellGolang
# shellServerless let you run a shell inside a serverless container
shellServerless: envfile
$(COMPOSE_RUN_SERVERLESS) bash
.PHONY: shellServerless
auth: envfile
$(COMPOSE_RUN_AUTH)
.PHONY: auth
###################
# Private Targets #
###################
# _test tests the go source
_test:
go test -v ./...
.PHONY: _test
# build builds all functions individually
_build:
@for dir in $(wildcard functions/*/) ; do \
fxn=$$(basename $$dir) ; \
GOOS=linux go build -ldflags="-s -w" -o $(BIN_DIR)/$$fxn functions/$$fxn/*.go ; \
done
.PHONY: _build
# _pack zips all binary functions individually and removes them
_pack:
@for dir in $(wildcard functions/*/) ; do \
fxn=$$(basename $$dir) ; \
zip -m -D $(BIN_DIR)/$$fxn.zip $(BIN_DIR)/$$fxn ; \
done
.PHONY: _pack
# _deploy deploys the package using serverless
_deploy:
rm -fr .serverless
sls deploy
.PHONY: _deploy
# _echo calls the echo api endpoint
_echo:
sls info -f echo | grep GET | cut -d' ' -f 5 | xargs curl
.PHONY: _echo
# _remove removes the aws stack created by serverless
_remove:
sls remove
rm -fr .serverless
.PHONY: _remove
# _clean removes folders and files created when building
_clean:
rm -rf .serverless bin
.PHONY: _clean