This repository has been archived by the owner on May 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathMakefile.sample
118 lines (95 loc) · 8.16 KB
/
Makefile.sample
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
.PHONY: all build package copycodeww copytemplateww syncvideos creates3 deletes3 deploy
# The S3 bucket name prefix that will host the Cloudformation template and deployment artifacts
bucket = <your-bucket-name-prefix-here>
# The prefix in the s3 bucket that all artifacts are stored under
s3prefix = qos
escaped_s3prefix := $(shell printf '%s\n' "$(s3prefix)" | sed -e 's/[\/&]/\\&/g')
# The S3 bucket that hosts sample videos for the demo UI
video_assets_bucket = aws-streaming-media-analytics-sourcecontent-us-east-1
# The AWS regions (in standard format, e.g. us-east-1, us-west-2), you wish to build the code and deploy to. Separate by spaces.
regions = us-east-1 us-west-2
# A version number that will be included in the path for the files stored in S3
version = v1
# The to AWS CLI profile name to use for working with S3
profile = default
# The default Stack Name when deploying
stack_name = mediaqos
all: image build package copycodeww copytemplateww syncvideos
release: package copycodeww copytemplateww
image:
docker build --tag amazonlinux:qos .
build:
docker run --rm --volume ${PWD}/lambda-functions/deploy-function:/build amazonlinux:qos /bin/bash -c "npm init -f -y; npm install adm-zip --save; npm install generate-password --save; npm install mime --save; npm install --only=prod"
docker run --rm --volume ${PWD}/lambda-functions/recentvideoview-appsync-function:/build amazonlinux:qos /bin/bash -c "npm init -f -y; npm install [email protected] --save; npm install [email protected] --save; npm install --only=prod"
docker run --rm --volume ${PWD}/lambda-functions/totalvideoview-appsync-function:/build amazonlinux:qos /bin/bash -c "npm init -f -y; npm install [email protected] --save; npm install [email protected] --save; npm install --only=prod"
docker run --rm --volume ${PWD}/lambda-functions/activeuser-appsync-function:/build amazonlinux:qos /bin/bash -c "npm init -f -y; npm install [email protected] --save; npm install [email protected] --save; npm install --only=prod"
mkdir -p lambda-functions/cloudfront-logs-processor-function/package
docker run -it --rm --volume ${PWD}/lambda-functions/cloudfront-logs-processor-function:/build amazonlinux:qos /bin/bash -c "pip install --target=./package -r requirements.txt"
mkdir -p lambda-functions/fastly-logs-processor-function/package
docker run -it --rm --volume ${PWD}/lambda-functions/fastly-logs-processor-function:/build amazonlinux:qos /bin/bash -c "pip install --target=./package -r requirements.txt"
docker run --rm --volume ${PWD}/lambda-functions/add-partition-function:/build amazonlinux:qos /bin/bash -c "npm init -f -y; npm install --only=prod"
cd web/reactplayer; yarn;
cp -av web/reactplayer/overrides/* web/reactplayer/node_modules/
cd web/reactplayer;yarn build
package:
mkdir -p dist && cd lambda-functions/deploy-function && zip -x \.* event.json \*.yaml -FS -q -r ../../dist/deploy-function.zip * && cd ../..
mkdir -p dist && cd lambda-functions/cloudfront-logs-processor-function/package && zip -x \.* event.json \*.yaml -FS -q -r ../../../dist/cloudfront-logs-processor-function.zip * && cd .. && zip -g ../../dist/cloudfront-logs-processor-function.zip prep-data.py && cd ../..
mkdir -p dist && cd lambda-functions/fastly-logs-processor-function/package && zip -x \.* event.json \*.yaml -FS -q -r ../../../dist/fastly-logs-processor-function.zip * && cd .. && zip -g ../../dist/fastly-logs-processor-function.zip prep-data.py && cd ../..
mkdir -p dist && cd lambda-functions/recentvideoview-appsync-function && zip -FS -q -r ../../dist/recentvideoview-appsync-function.zip * && cd ../..
mkdir -p dist && cd lambda-functions/totalvideoview-appsync-function && zip -FS -q -r ../../dist/totalvideoview-appsync-function.zip * && cd ../..
mkdir -p dist && cd lambda-functions/activeuser-appsync-function && zip -FS -q -r ../../dist/activeuser-appsync-function.zip * && cd ../..
mkdir -p dist && cd lambda-functions/add-partition-function && zip -FS -q -r ../../dist/add-partition-function.zip * && cd ../..
mkdir -p dist && cd web/reactplayer/build && zip -FS -q -r ../../../dist/player-ui.zip * && cd ../../..
creates3:
@for region in $(regions);do \
echo $$region; echo $(bucket); \
aws s3 mb s3://$(bucket)-$$region --region $$region --profile $(profile); \
done
deletes3:
@for region in $(regions);do \
echo $$region; echo $(bucket); \
aws s3 rb s3://$(bucket)-$$region --force --profile $(profile); \
done
syncvideos:
@for region in $(regions);do \
aws s3 sync s3://$(video_assets_bucket)/output s3://$(bucket)-$$region/$(s3prefix)/sample-videos/ --acl public-read --profile $(profile);\
mkdir -p assets/sample-videos;\
aws s3 ls --recursive s3://$(bucket)-$$region/$(s3prefix)/sample-videos/ --profile $(profile) | awk '{print $$4}' > assets/sample-videos/video-manifest.txt; \
aws s3 cp assets/sample-videos/video-manifest.txt s3://$(bucket)-$$region/$(s3prefix)/sample-videos/ --acl public-read --profile $(profile);\
done
copycodeww:
@for region in $(regions) ; do \
echo $$region; echo $(bucket);\
aws s3 cp dist/deploy-function.zip s3://$(bucket)-$$region/$(s3prefix)/lambda-functions/ui-deployment/$(version)/ --acl public-read --profile $(profile); \
aws s3 cp dist/player-ui.zip s3://$(bucket)-$$region/$(s3prefix)/lambda-functions/ui-deployment/user-interfaces/$(version)/ --acl public-read --profile $(profile); \
aws s3 cp dist/cloudfront-logs-processor-function.zip s3://$(bucket)-$$region/$(s3prefix)/lambda-functions/cloudfront-logs-processor-function/$(version)/ --acl public-read --profile $(profile); \
aws s3 cp dist/fastly-logs-processor-function.zip s3://$(bucket)-$$region/$(s3prefix)/lambda-functions/fastly-logs-processor-function/$(version)/ --acl public-read --profile $(profile); \
aws s3 cp dist/recentvideoview-appsync-function.zip s3://$(bucket)-$$region/$(s3prefix)/lambda-functions/recentvideoview-appsync-function/$(version)/ --acl public-read --profile $(profile); \
aws s3 cp dist/totalvideoview-appsync-function.zip s3://$(bucket)-$$region/$(s3prefix)/lambda-functions/totalvideoview-appsync-function/$(version)/ --acl public-read --profile $(profile); \
aws s3 cp dist/activeuser-appsync-function.zip s3://$(bucket)-$$region/$(s3prefix)/lambda-functions/activeuser-appsync-function/$(version)/ --acl public-read --profile $(profile); \
aws s3 cp dist/add-partition-function.zip s3://$(bucket)-$$region/$(s3prefix)/lambda-functions/add-partition-function/$(version)/ --acl public-read --profile $(profile); \
aws s3 cp cloudformation/appsync_schema.graphql s3://$(bucket)-$$region/$(s3prefix)/lambda-functions/recentvideoview-appsync-function/$(version)/ --acl public-read --profile $(profile); \
aws s3 cp cloudformation/etl/player_log_job s3://$(bucket)-$$region/$(s3prefix)/etl/$(version)/ --acl public-read --profile $(profile); \
done
copytemplateww:
@for region in $(regions);do \
echo $$region; echo $(bucket); \
sed -e "s/BUCKET_NAME/${bucket}/g" -e "s/VERSION/${version}/g" -e "s/S3_PREFIX/${escaped_s3prefix}/g" -e "s/DEPLOY_SOURCE_REGION/$$region/g" cloudformation/deployment_template.yaml > cloudformation/deployment.yaml; \
aws s3 cp cloudformation/deployment.yaml s3://$(bucket)-$$region/$(s3prefix)/cloudformation/$(version)/ --acl public-read --profile $(profile); \
done
template:
sed -e "s/BUCKET_NAME/${bucket}/g" -e "s/VERSION/${version}/g" -e "s/S3_PREFIX/${escaped_s3prefix}/g" -e "s/DEPLOY_SOURCE_REGION/us-east-1/g"cloudformation/deployment_template.yaml > cloudformation/deployment.yaml
deploy:
aws cloudformation deploy --template-file cloudformation/deployment.yaml --stack-name $(stack_name) --capabilities=CAPABILITY_NAMED_IAM --profile $(profile) --region us-west-2
deploy1:
aws cloudformation deploy --template-file cloudformation/deployment_gluejob_only.yaml --stack-name testqos2 --capabilities=CAPABILITY_NAMED_IAM --profile $(profile) --region us-west-2
clean:
rm -r dist/*
rm -r lambda-functions/activeuser-appsync-function/node_modules/*
rm -r lambda-functions/deploy-function/node_modules/*
rm -r lambda-functions/recentvideoview-appsync-function/node_modules/*
rm -r lambda-functions/totalvideoview-appsync-function/node_modules/*
rm -r web/reactplayer/build/*
rm -r web/reactplayer/node_modules/*
cleandocker:
docker rmi --force amazonlinux:qos