-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
81 lines (70 loc) · 2.58 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
# This Makefile is an easy way to run common operations.
# Execute commands like this:
# * make
# * make gcp-init
# * make gcp-push
# * make privatekey
# * make mfa
# * make passhash passwordhere
# * make local-init
# * make local-run
# Load the environment variables.
include .env
export
.PHONY: default
default: gcp-push
################################################################################
# Deploy application
################################################################################
.PHONY: gcp-init
gcp-init:
@echo Pushing the initial files to Google Cloud Storage.
gsutil mb -p $(PBB_GCP_PROJECT_ID) -l ${PBB_GCP_REGION} -c Standard gs://${PBB_GCP_BUCKET_NAME}
gsutil versioning set on gs://${PBB_GCP_BUCKET_NAME}
gsutil cp testdata/empty.json gs://${PBB_GCP_BUCKET_NAME}/storage/site.json
gsutil cp testdata/empty.bin gs://${PBB_GCP_BUCKET_NAME}/storage/session.bin
.PHONY: gcp-push
gcp-push:
@echo Pushing to Google Cloud Run.
gcloud --project=$(PBB_GCP_PROJECT_ID) builds submit --tag gcr.io/$(PBB_GCP_PROJECT_ID)/${PBB_GCP_IMAGE_NAME}
gcloud --project=$(PBB_GCP_PROJECT_ID) run deploy --image gcr.io/$(PBB_GCP_PROJECT_ID)/${PBB_GCP_IMAGE_NAME} \
--platform managed \
--allow-unauthenticated \
--region ${PBB_GCP_REGION} ${PBB_GCP_CLOUDRUN_NAME} \
--update-env-vars PBB_USERNAME=${PBB_USERNAME} \
--update-env-vars PBB_SESSION_KEY=${PBB_SESSION_KEY} \
--update-env-vars PBB_PASSWORD_HASH=${PBB_PASSWORD_HASH} \
--update-env-vars PBB_MFA_KEY="${PBB_MFA_KEY}" \
--update-env-vars PBB_GCP_PROJECT_ID=${PBB_GCP_PROJECT_ID} \
--update-env-vars PBB_GCP_BUCKET_NAME=${PBB_GCP_BUCKET_NAME} \
--update-env-vars PBB_ALLOW_HTML=${PBB_ALLOW_HTML}
.PHONY: privatekey
privatekey:
@echo Generating private key for encrypting sessions.
@echo You can paste private key this into your .env file:
@go run cmd/privatekey/main.go
.PHONY: mfa
mfa:
@echo Generating MFA for user.
@echo You can paste private key this into your .env file:
@go run cmd/mfa/main.go
# Save the ARGS.
# https://stackoverflow.com/a/14061796
ifeq (passhash,$(firstword $(MAKECMDGOALS)))
ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(ARGS):;@:)
endif
.PHONY: passhash
passhash:
@echo Generating password hash.
@echo You can paste private key this into your .env file:
@go run cmd/passhash/main.go ${ARGS}
.PHONY: local-init
local-init:
@echo Creating session and site storage files locally.
cp storage/initial/session.bin storage/session.bin
cp storage/initial/site.json storage/site.json
.PHONY: local-run
local-run:
@echo Starting local server.
LOCALDEV=true go run main.go