-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
223 lines (194 loc) · 7.25 KB
/
Makefile
File metadata and controls
223 lines (194 loc) · 7.25 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
REGION = us-east-1
BROKER_NAME = github-lfs
SNAPSHOT_NAME = github-lfs-snapshot
PROFILE = YOUR_PROFILE_NAME
LFS_BUCKET = YOUR_BUCKET_NAME
SNAPSHOT_BUCKET = YOUR_BUCKET_NAME
SNAPSHOT_PREFIX = public/
EXTRA_SNAPSHOT_BUCKETS =
ACCOUNT_ID = YOUR_ACCOUNT_ID
ROLE_NAME = github-lfs-lambda-role
REPO = YOUR_ORG/YOUR_REPO
REF = master
GITHUB_HOST = github.com
# -----------------------------------------------------------------------
# Init (first time only - sets up Go modules)
# -----------------------------------------------------------------------
init-broker:
cd lfs-broker && go mod init github.com/cbioportal/lfs-broker && \
go get github.com/aws/aws-lambda-go@latest && \
go get github.com/aws/aws-sdk-go-v2@latest && \
go get github.com/aws/aws-sdk-go-v2/config@latest && \
go get github.com/aws/aws-sdk-go-v2/service/s3@latest && \
go get github.com/aws/aws-sdk-go-v2/service/secretsmanager@latest && \
go mod tidy
init-snapshot:
cd lfs-snapshot && go mod init github.com/cbioportal/lfs-snapshot && \
go get github.com/aws/aws-lambda-go@latest && \
go get github.com/aws/aws-sdk-go-v2@latest && \
go get github.com/aws/aws-sdk-go-v2/config@latest && \
go get github.com/aws/aws-sdk-go-v2/service/s3@latest && \
go mod tidy
init: init-broker init-snapshot
# -----------------------------------------------------------------------
# Bucket setup
# -----------------------------------------------------------------------
configure-bucket:
aws s3api put-public-access-block \
--bucket $(LFS_BUCKET) \
--public-access-block-configuration \
"BlockPublicAcls=false,IgnorePublicAcls=false,BlockPublicPolicy=false,RestrictPublicBuckets=false" \
--region $(REGION) \
--profile $(PROFILE)
aws s3api put-bucket-policy \
--bucket $(LFS_BUCKET) \
--policy file://docs/bucket-policy.json \
--region $(REGION) \
--profile $(PROFILE)
# -----------------------------------------------------------------------
# Build
# -----------------------------------------------------------------------
build-broker:
cd lfs-broker && GOOS=linux GOARCH=amd64 go build -o bootstrap main.go && zip function.zip bootstrap
build-snapshot:
cd lfs-snapshot && GOOS=linux GOARCH=amd64 go build -o bootstrap main.go && zip function.zip bootstrap
build: build-broker build-snapshot
# -----------------------------------------------------------------------
# Create (first time setup)
# -----------------------------------------------------------------------
create-broker: build-broker
aws lambda create-function \
--function-name $(BROKER_NAME) \
--runtime provided.al2023 \
--role arn:aws:iam::$(ACCOUNT_ID):role/$(ROLE_NAME) \
--handler bootstrap \
--zip-file fileb://lfs-broker/function.zip \
--environment Variables="{S3_BUCKET=$(LFS_BUCKET),LFS_SECRET_NAME=github-lfs-api-keys}" \
--timeout 30 \
--region $(REGION) \
--profile $(PROFILE)
aws lambda create-function-url-config \
--function-name $(BROKER_NAME) \
--auth-type NONE \
--region $(REGION) \
--profile $(PROFILE)
aws lambda add-permission \
--function-name $(BROKER_NAME) \
--statement-id FunctionURLAllowPublicAccess \
--action lambda:InvokeFunctionUrl \
--principal "*" \
--function-url-auth-type NONE \
--region $(REGION) \
--profile $(PROFILE)
aws lambda add-permission \
--function-name $(BROKER_NAME) \
--statement-id FunctionURLAllowInvoke \
--action lambda:InvokeFunction \
--principal "*" \
--region $(REGION) \
--profile $(PROFILE)
create-snapshot: build-snapshot
aws lambda create-function \
--function-name $(SNAPSHOT_NAME) \
--runtime provided.al2023 \
--role arn:aws:iam::$(ACCOUNT_ID):role/$(ROLE_NAME) \
--handler bootstrap \
--zip-file fileb://lfs-snapshot/function.zip \
--environment Variables="{LFS_BUCKET=$(LFS_BUCKET),SNAPSHOT_BUCKET=$(SNAPSHOT_BUCKET),SNAPSHOT_PREFIX=$(SNAPSHOT_PREFIX),EXTRA_SNAPSHOT_BUCKETS=$(EXTRA_SNAPSHOT_BUCKETS)}" \
--timeout 300 \
--region $(REGION) \
--profile $(PROFILE)
aws lambda create-function-url-config \
--function-name $(SNAPSHOT_NAME) \
--auth-type NONE \
--region $(REGION) \
--profile $(PROFILE)
aws lambda add-permission \
--function-name $(SNAPSHOT_NAME) \
--statement-id FunctionURLAllowPublicAccess \
--action lambda:InvokeFunctionUrl \
--principal "*" \
--function-url-auth-type NONE \
--region $(REGION) \
--profile $(PROFILE)
aws lambda add-permission \
--function-name $(SNAPSHOT_NAME) \
--statement-id FunctionURLAllowInvoke \
--action lambda:InvokeFunction \
--principal "*" \
--region $(REGION) \
--profile $(PROFILE)
create: create-broker create-snapshot
# -----------------------------------------------------------------------
# Deploy (update existing functions)
# -----------------------------------------------------------------------
deploy-broker: build-broker
aws lambda update-function-code \
--function-name $(BROKER_NAME) \
--zip-file fileb://lfs-broker/function.zip \
--region $(REGION) \
--profile $(PROFILE)
deploy-snapshot: build-snapshot
aws lambda update-function-code \
--function-name $(SNAPSHOT_NAME) \
--zip-file fileb://lfs-snapshot/function.zip \
--region $(REGION) \
--profile $(PROFILE)
deploy: deploy-broker deploy-snapshot
# -----------------------------------------------------------------------
# Logs
# -----------------------------------------------------------------------
logs-broker:
aws logs tail /aws/lambda/$(BROKER_NAME) \
--region $(REGION) \
--profile $(PROFILE) \
--follow
logs-snapshot:
aws logs tail /aws/lambda/$(SNAPSHOT_NAME) \
--region $(REGION) \
--profile $(PROFILE) \
--follow
# -----------------------------------------------------------------------
# Info
# -----------------------------------------------------------------------
url-broker:
aws lambda get-function-url-config \
--function-name $(BROKER_NAME) \
--region $(REGION) \
--profile $(PROFILE) \
--query FunctionUrl \
--output text
url-snapshot:
aws lambda get-function-url-config \
--function-name $(SNAPSHOT_NAME) \
--region $(REGION) \
--profile $(PROFILE) \
--query FunctionUrl \
--output text
# -----------------------------------------------------------------------
# Secrets
# -----------------------------------------------------------------------
list-curators:
aws secretsmanager get-secret-value \
--secret-id github-lfs-api-keys \
--region $(REGION) \
--profile $(PROFILE) \
--query SecretString \
--output text | jq 'keys'
# -----------------------------------------------------------------------
# Snapshot
# -----------------------------------------------------------------------
full-snapshot:
$(eval TOKEN := $(shell gh auth token --hostname $(GITHUB_HOST)))
$(eval URL := $(shell make url-snapshot --no-print-directory))
curl -X POST $(URL) \
-H "Content-Type: application/json" \
-d '{"repo":"$(REPO)","ref":"$(REF)","token":"$(TOKEN)","github_host":"$(GITHUB_HOST)"}'
.PHONY: init init-broker init-snapshot \
configure-bucket \
build build-broker build-snapshot \
create create-broker create-snapshot \
deploy deploy-broker deploy-snapshot \
logs-broker logs-snapshot \
url-broker url-snapshot \
list-curators full-snapshot