This repository has been archived by the owner on Sep 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
92 lines (73 loc) · 3.59 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
.PHONY: api deploy-infra-staging deploy-infra-prod deploy-api start-api dbstream notification deploy-notification update-lib deploy-dbstream sync deploy-sync sync
.SILENT: api deploy-infra-staging deploy-infra-prod deploy-api start-api dbstream notification deploy-notification update-lib deploy-dbstream deploy-sync sync
# staging
# ENV=staging
# DOMAIN_NAME=knncreative.com
# CLOUDFRONT_DISTRIBUTION_ID?=EN255N14EJZLA
# prod
ENV=production
DOMAIN_NAME=networth.app
CLOUDFRONT_DISTRIBUTION_ID?=E2777SQLYCBXKE
LAMBDA_BUCKET=lambda.${DOMAIN_NAME}
LANDING_S3_BUCKET?=${DOMAIN_NAME}
WEBAPP_S3_BUCKET?=webapp.${DOMAIN_NAME}
REGION=us-east-1
APP_NAME=networth
TIMESTAMP=$(shell date +%s)
GO_BUILD_OPS=-ldflags '-d -s -w' -a -tags netgo -installsuffix netgo -o ../bin/${APP_NAME}
api:
cd api && env GOOS=linux go build ${GO_BUILD_OPS}-api .
cd bin && zip ${APP_NAME}-api.zip ${APP_NAME}-api
dbstream:
cd dbstream && env GOOS=linux go build ${GO_BUILD_OPS}-dbstream .
cd bin && zip ${APP_NAME}-dbstream.zip ${APP_NAME}-dbstream
sync:
cd sync && env GOOS=linux go build ${GO_BUILD_OPS}-sync .
cd bin && zip ${APP_NAME}-sync.zip ${APP_NAME}-sync
notification:
cd notification && env GOOS=linux go build ${GO_BUILD_OPS}-notification .
cd bin && zip ${APP_NAME}-notification.zip ${APP_NAME}-notification
start-api:
cd api && gin --appPort 8000
start-web:
cd web && npm run start
update-lib:
cd api && go get github.com/networth-app/networth/lib && go mod tidy && go mod vendor
cd sync && go get github.com/networth-app/networth/lib && go mod tidy && go mod vendor
cd notification && go get github.com/networth-app/networth/lib && go mod tidy && go mod vendor
cd dbstream && go get github.com/networth-app/networth/lib && go mod tidy && go mod vendor
test:
cd api && go test
cd notification && go test
cd dbstream && go test
cd sync && go test
# cd web && npm test
deploy-infra-staging:
ln -s -f ~/.aws/credentials.staging.networth ~/.aws/credentials
cd cloud && terraform workspace select staging && terraform apply -auto-approve
deploy-infra-prod:
ln -s -f ~/.aws/credentials.prod.networth ~/.aws/credentials
cd cloud && terraform workspace select prod && terraform apply -auto-approve
deploy-api:
make api
aws s3 cp bin/${APP_NAME}-api.zip s3://${LAMBDA_BUCKET}/api/${TIMESTAMP}.zip > /dev/null
aws lambda update-function-code --function-name ${APP_NAME}-api --zip-file fileb://bin/${APP_NAME}-api.zip --publish > /dev/null
deploy-dbstream:
make dbstream
aws s3 cp bin/${APP_NAME}-dbstream.zip s3://${LAMBDA_BUCKET}/dbstream/${TIMESTAMP}.zip > /dev/null
aws lambda update-function-code --function-name ${APP_NAME}-dbstream --zip-file fileb://bin/${APP_NAME}-dbstream.zip --publish > /dev/null
deploy-sync:
make sync
aws s3 cp bin/${APP_NAME}-sync.zip s3://${LAMBDA_BUCKET}/sync/${TIMESTAMP}.zip > /dev/null
aws lambda update-function-code --function-name ${APP_NAME}-sync --zip-file fileb://bin/${APP_NAME}-sync.zip --publish > /dev/null
deploy-notification:
make notification
aws s3 cp bin/${APP_NAME}-notification.zip s3://${LAMBDA_BUCKET}/notification/${TIMESTAMP}.zip > /dev/null
aws lambda update-function-code --function-name ${APP_NAME}-notification --zip-file fileb://bin/${APP_NAME}-notification.zip --publish > /dev/null
deploy-landing:
aws s3 sync landing s3://${LANDING_S3_BUCKET}
aws cloudfront create-invalidation --paths '/*' --distribution-id ${CLOUDFRONT_DISTRIBUTION_ID}
deploy-webapp:
cd web && npx env-cmd .env.${ENV} npm run build
aws s3 sync web/build s3://${WEBAPP_S3_BUCKET}/app --delete --acl public-read
aws cloudfront create-invalidation --paths '/app*' --distribution-id ${CLOUDFRONT_DISTRIBUTION_ID}