-
Notifications
You must be signed in to change notification settings - Fork 1
/
push.sh
129 lines (109 loc) · 3.23 KB
/
push.sh
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
#!/bin/bash -xev
# USAGE
#
# This script provides 6 flags
# --sandbox : pushes to beta-hyper-sdk-assets bucket on S3
# --no-compress : skips compression of images
# --no-resize : skips images resizing
#
# Extra flags
# --f : for pushing without confirmation
#
# ---- For pushing to production bucket
# This defaults to s3://jp-remote-assets/hyper/...
# $ bash -e push.sh <path to asset to be pushed>
# eg: bash -e push.sh hyper/images/common/amazon_pay.png
#
# ---- For pushing to sandbox bucket
# This defaults to s3://beta-hyper-sdk-assets/hyper/...
# $ bash -e push.sh <path to asset to be pushed> --sandbox
# eg: bash -e push.sh hyper/images/common/amazon_pay.png
#
#### FUNCTIONS
if [[ "$@" =~ --f ]]
then force_push=true; fi
check_if_local_path_exists()
{
local_path="$1"
if [ -f "$local_path" ]
then return 0
else return 1; fi
}
check_if_png_is_valid()
{
local_path="$1"
printf "check_if_png_is_valid local_path : $local_path"
if pngcheck "$local_path"
then
image_name=$(echo $local_path | rev | cut -d"/" -f1 | rev)
if [[ "$image_name" =~ ^([a-z0-9]|_)*(\.9)?\.png$ ]]
then return 0
else return 1; fi
else return 1; fi
}
invalidate_asset()
{
s3_path="$1"
aws cloudfront create-invalidation --distribution-id $distributionId --paths $s3_path
printf "invalidated $s3_path"
}
push_asset() {
local_path="$1"
s3_path="$2"
printf "s3_path $s3_path .. \n"
if [ "$force_push" = true ]
then read -p "Press enter to push to $s3_path"; fi
printf "Pushing $local_path to $s3_path ...\n\n"
aws s3 cp $local_path $s3_path
}
asset=""
bucket="beckn-frontend-assets" # TODO : PROD bucket
distributionId="EZCA94ADQWCV1"
force_push=false
if [ $(echo $@ | sed "s/--[a-zA-Z]*-*[a-zA-Z]*//g" | tr -d '[:space:]' | wc -c) -ne 0 ]
then asset=$(echo $@ | sed "s/--[a-zA-Z]*-*[a-zA-Z]*//g" | tr -d '[:space:]'); fi
if [[ "$@" =~ --sandbox ]]
then bucket="beckn-frontend-assets"; fi # TODO :: sandbox bucket (optional)
echo -------------- s3 push starting -------------------
if [ "$asset" != "" ]
then
local_path=$(pwd)/$asset
check_if_local_path_exists $local_path
if [ "$?" != 0 ]
then echo "$local_path does not exist. Exiting ..." && exit 1; fi
if [[ "$local_path" =~ \.png$ ]]
then
if [[ ! "$@" =~ --no-check ]]
then
check_if_png_is_valid $local_path
if [ "$?" != 0 ]
then echo "Image at $local_path is invalid. Exiting ..." && exit 1; fi
fi
if [[ ! "$@" =~ (\.9\.png|credit|bbfresho|hyperupi) ]]
then
if [[ ! "$@" =~ --no-resize ]] && [[ "$local_path" =~ \.png ]]
then
set +e
python3 resizeImages.py $local_path
if [ "$?" != 0 ]
then echo "IMAGE_RESIZE_FAIL"
else echo "IMAGE_RESIZE_SUCCESS"
fi
set -e
fi
if [[ ! "$@" =~ --no-compress ]] && [[ "$local_path" =~ \.png ]]
then
set +e
node compressImages.js $local_path
if [ "$?" != 0 ]
then echo "IMAGE_COMPRESS_FAIL"
else echo "IMAGE_COMPRESS_SUCCESS"
fi
set -e
fi
else echo "Skipping compression"; fi
fi
pathToPush="s3://$bucket/$asset"
push_asset $local_path $pathToPush
invalidate_asset $local_path
fi