forked from HackIllinois/api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
104 lines (88 loc) · 3.63 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
# This makefile handles build, testing, and deploying all services in the HackIllinois API
# It is designed to be simple to understand and easy to add a new service by following the instructions in the comments
# BASE_PACKAGE should be the name of the go module
# REPO_ROOT will be used to build absolute paths during build or testing stages
BASE_PACKAGE := github.com/HackIllinois/api
REPO_ROOT := $(shell git rev-parse --show-toplevel)
# SERVICES is the list services to test, services are located at $(REPO_ROOT)/service/<service_name>
# GATEWAYS is the list of top level directories to test, gateways are located at $(REPO_ROOT)/<gateway_name>
# Add new services or top level directories to test here
SERVICES := auth user registration decision rsvp checkin upload mail event stat notifications project
GATEWAYS := gateway common
# UTILITIES is the list of utilities to build, utilities are located at $(REPO_ROOT)/utilities/<utility_name>
# Add new utilities to build here
UTILITIES := accountgen tokengen
# TAG is used to tag the docker containers being built
TAG := latest
ifeq ($(strip $(TAG)),)
override TAG := latest
endif
# Builds the API binary and all utilities
.PHONY: all
all: api utilities
# Builds the API binary
.PHONY: api
api:
@echo 'Building api'
@mkdir -p $(REPO_ROOT)/bin
@go build -o $(REPO_ROOT)/bin/hackillinois-api $(BASE_PACKAGE)
# Tests all services and gateways
.PHONY: test
test:
@echo 'Testing services'
@$(foreach service,$(SERVICES),HI_CONFIG=file://$(REPO_ROOT)/config/test_config.json go test $(BASE_PACKAGE)/services/$(service)/tests || exit 1;)
@echo 'Testing gateway'
@$(foreach gateway,$(GATEWAYS),HI_CONFIG=file://$(REPO_ROOT)/config/test_config.json go test $(BASE_PACKAGE)/$(gateway)/tests || exit 1;)
# Builds all utilities
.PHONY: utilities
utilities:
@echo 'Building utilities'
@mkdir -p $(REPO_ROOT)/bin
@$(foreach utility,$(UTILITIES),go build -o $(REPO_ROOT)/bin/hackillinois-utility-$(utility) $(BASE_PACKAGE)/utilities/$(utility);)
# Builds the API binary, all utilities, and then sets up an admin account
.PHONY: setup
setup: all
@echo 'Generating API admin account'
@export HI_CONFIG=file://$(REPO_ROOT)/config/dev_config.json; \
$(REPO_ROOT)/bin/hackillinois-utility-accountgen
@echo 'Generating token for admin account'
@export HI_CONFIG=file://$(REPO_ROOT)/config/dev_config.json; \
$(REPO_ROOT)/bin/hackillinois-utility-tokengen
# Runs the API with each service in a seperate process
.PHONY: run
run:
@$(REPO_ROOT)/scripts/run.sh
# Runs the API with all services in a single process
.PHONY: run-single
run-single:
@$(REPO_ROOT)/scripts/run-single.sh
# Formats the repo
.PHONY: fmt
fmt:
@gofmt -s -w -l .
# Builds a docker container with the API binary
.PHONY: container
container: api
@echo 'Builing API container'
@mkdir -p $(REPO_ROOT)/build
@cp $(REPO_ROOT)/bin/hackillinois-api $(REPO_ROOT)/build/hackillinois-api
@cp $(REPO_ROOT)/container/Dockerfile $(REPO_ROOT)/build/Dockerfile
@docker build -t hackillinois-api:$(TAG) $(REPO_ROOT)/build
@rm -rf $(REPO_ROOT)/build
# Generates a tar archive of the API container
.PHONY: release
release: container
@echo 'Building API container release'
@docker save -o $(REPO_ROOT)/bin/hackillinois-api-image.tar hackillinois-api:$(TAG)
@rm -rf $(REPO_ROOT)/build
# Pushes the API container to DockerHub
.PHONY: container-push
container-push:
@echo 'Pushing container to DockerHub'
@echo "$(DOCKER_PASSWORD)" | docker login -u "$(DOCKER_USERNAME)" --password-stdin
@docker tag hackillinois-api:$(TAG) hackillinois/api:$(TAG)
@docker push hackillinois/api:$(TAG)
# Builds static html documentation for the API
.PHONY: docs
docs:
$(MAKE) -C $(REPO_ROOT)/documentation build