-
Notifications
You must be signed in to change notification settings - Fork 19
/
Makefile
120 lines (99 loc) · 4.43 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
.PHONY: build test
bin_dir=build/
commit=$$(git rev-parse HEAD)
time=$$(date +%s)
aws_registry_uri=${aws-account-id}.dkr.ecr.${aws-lambda-region}.amazonaws.com
aws_docker_image=${aws_registry_uri}/${docker-image-name}:${commit}
# Things in my.mk:
# aws-lambda-function-staging=my-lambda-function-staging
# aws-lambda-function-production=my-lambda-function-production
# aws-lambda-headless-function-staging=my-lambda-headless-function-staging
# aws-lambda-region=ap-east-1
# aws-lambda-role=arn:aws:iam::xxxxx:....
# aws-account-id=xxxxxxxxxx
# docker-image-name=lambda_headless
-include ./my.mk
build:
@go build \
-ldflags "-X 'github.com/nextdotid/proof_server/common.Environment=develop' -X 'github.com/nextdotid/proof_server/common.Revision=${commit}' -X 'github.com/nextdotid/proof_server/common.BuildTime=${time}'" \
-o ${bin_dir} ./cmd/...
test:
@go test -v ./...
lambda-build-production:
@go clean
@GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build \
-v -x \
-ldflags "-X 'github.com/nextdotid/proof_server/common.Environment=production' -X 'github.com/nextdotid/proof_server/common.Revision=${commit}' -X 'github.com/nextdotid/proof_server/common.BuildTime=${time}'" \
-o ./build/lambda \
./cmd/lambda
lambda-build-staging:
@go clean
@GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build \
-v -x \
-ldflags "-X 'github.com/nextdotid/proof_server/common.Environment=staging' -X 'github.com/nextdotid/proof_server/common.Revision=${commit}' -X 'github.com/nextdotid/proof_server/common.BuildTime=${time}'" \
-o ./build/lambda \
./cmd/lambda
lambda-pack-staging: lambda-build-staging
@cd ./build && zip lambda.zip lambda
lambda-pack-production: lambda-build-production
@cd ./build && zip lambda.zip lambda
lambda-update-staging: lambda-pack-staging
@aws lambda update-function-code --function-name ${aws-lambda-function-staging} --zip-file 'fileb://./build/lambda.zip'
lambda-update-production: lambda-pack-production
@aws lambda update-function-code --function-name ${aws-lambda-function-production} --zip-file 'fileb://./build/lambda.zip'
lambda-create-staging: lambda-pack-staging
aws lambda create-function \
--region ${aws-lambda-region} \
--function-name ${aws-lambda-function-staging} \
--handler lambda \
--role ${aws-lambda-role} \
--runtime go1.x \
--zip-file "fileb://./build/lambda.zip"
lambda-create-production: lambda-pack-production
aws lambda create-function \
--region ${aws-lambda-region} \
--function-name ${aws-lambda-function-production} \
--handler lambda \
--role ${aws-lambda-role} \
--runtime go1.x \
--zip-file "fileb://./build/lambda.zip"
lambda-build-worker-staging:
@go clean
@GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build \
-v -x \
-ldflags "-X 'github.com/nextdotid/proof_server/common.Environment=staging' -X 'github.com/nextdotid/proof_server/common.Revision=${commit}' -X 'github.com/nextdotid/proof_server/common.BuildTime=${time}'" \
-o ./build/lambda \
./cmd/lambda_worker
lambda-pack-worker-staging: lambda-build-worker-staging
@cd ./build && zip lambda.zip lambda
lambda-update-worker-staging: lambda-pack-worker-staging
@aws lambda update-function-code --function-name ${aws-lambda-function-worker-staging} --zip-file 'fileb://./build/lambda.zip'
lamda-create-registry-headless:
@aws ecr get-login-password \
--region ${aws-lambda-region} | docker login \
--username AWS \
--password-stdin ${aws_registry_uri}
@aws ecr describe-repositories \
--repository-names ${docker-image-name} || \
aws ecr create-repository \
--repository-name ${docker-image-name} \
--region ${aws-lambda-region} \
--image-scanning-configuration scanOnPush=true \
--image-tag-mutability MUTABLE
lambda-build-headless-staging:
@docker build -f ./cmd/lambda_headless/Dockerfile -t ${docker-image-name}:${commit} .
@docker tag ${docker-image-name}:${commit} ${aws_docker_image}
lambda-pack-headless-staging: lamda-create-registry-headless lambda-build-headless-staging
@docker push ${aws_docker_image}
lambda-create-headless-staging: lambda-pack-headless-staging
aws lambda create-function \
--package-type Image \
--region ${aws-lambda-region} \
--function-name ${aws-lambda-headless-function-staging} \
--code ImageUri=${aws_docker_image} \
--memory-size 1200 \
--timeout 30 \
--architectures x86_64 \
--role ${aws-lambda-role}
lambda-update-headless-staging: lambda-pack-headless-staging
@aws lambda update-function-code --function-name ${aws-lambda-headless-function-staging} --image-uri ${aws_docker_image}