-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
111 lines (92 loc) · 3.04 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
PROJECT := serene-foundry-234813
BUCKET_CLOUD_FUNCTIONS := ${PROJECT}-functions
BUCKET_OBJECTS := ${PROJECT}-objects
DC_GOV_URL := https://dcra.dc.gov/mrv
# Windows-specific settings.
ifdef OS
SHELL := sh
GSUTIL := gsutil.cmd
else
GSUTIL := gsutil
endif
.PHONY: all backend frontend
help:
@echo " all deploy the backend and frontend"
@echo " backend deploy the backend"
@echo " frontend deploy the frontend"
@echo " test run tests"
all: frontend backend
frontend:
@echo -e "\nDeploying the frontend"
cd frontend && \
npm run build && \
firebase deploy
backend: db dcgov
db: db_rating db_trucks
db_rating:
@echo -e "\nDeploying average ratings update"
export TRIGGER_EVENT=$$(cat backend/db/rating/trigger_event); \
export TRIGGER_RESOURCE=$$(cat backend/db/rating/trigger_resource); \
${SHELL} gcloud functions deploy set-avg-rating \
--entry-point=SetAvgRating \
--runtime=go111 \
--source=backend/db/rating \
--stage-bucket=${BUCKET_CLOUD_FUNCTIONS} \
--trigger-event=$${TRIGGER_EVENT} \
--trigger-resource=projects/${PROJECT}/databases/\(default\)/documents/$${TRIGGER_RESOURCE}
db_trucks:
@echo -e "\nUploading food truck data"
export PROJECT=${PROJECT}; \
cd backend/db/trucks && \
go run trucks.go
dcgov: get_pdfs convert_pdfs load_db
get_pdfs: buckets get_pdfs_cron
@echo -e "\nDeploying DC gov PDF retrieval"
${SHELL} gcloud functions deploy get-pdfs \
--entry-point=GetPDFs \
--runtime=go111 \
--source=backend/dcgov/get_pdfs \
--stage-bucket=${BUCKET_CLOUD_FUNCTIONS} \
--timeout=300 \
--set-env-vars=URL=${DC_GOV_URL},BUCKET=${BUCKET_OBJECTS},PROJECT=${PROJECT} \
--trigger-topic=get-pdfs
get_pdfs_cron:
@echo -e "\nSetting up a schedule for PDF conversion"
-${SHELL} gcloud pubsub topics create get-pdfs
-${SHELL} gcloud scheduler jobs delete get-pdfs --quiet
-${SHELL} gcloud scheduler jobs create pubsub get-pdfs \
--schedule="0 * * * *" \
--topic=get-pdfs \
--message-body="{}" \
--time-zone=America/New_York
convert_pdfs: buckets
@echo -e "\nDeploying DC gov PDF to CSV conversion"
${SHELL} gcloud functions deploy convert-pdfs \
--entry-point=convert_pdf \
--memory=512MB \
--runtime=python37 \
--source=backend/dcgov/convert_pdf \
--stage-bucket=${BUCKET_CLOUD_FUNCTIONS} \
--timeout=300 \
--trigger-event=google.storage.object.finalize \
--trigger-resource=${BUCKET_OBJECTS}
load_db: buckets
@echo -e "\nDeploying DC gov database load"
${SHELL} gcloud functions deploy load-db \
--entry-point=LoadDB \
--runtime=go111 \
--source=backend/dcgov/load_db \
--stage-bucket=${BUCKET_CLOUD_FUNCTIONS} \
--set-env-vars=PROJECT=${PROJECT} \
--trigger-event=google.storage.object.finalize \
--trigger-resource=${BUCKET_OBJECTS}
buckets:
@echo -e "\nCreating buckets"
-${GSUTIL} mb gs://${BUCKET_CLOUD_FUNCTIONS}
-${GSUTIL} mb gs://${BUCKET_OBJECTS}
test: test-backend test-frontend
test-backend:
@GO_DIRS=$$(find . -name *test.go -exec dirname {} \; | sort | uniq); \
for d in $$GO_DIRS; do (cd "$$d" && go test); done; \
test-frontend:
@cd frontend && CI=true npm test a