-
Notifications
You must be signed in to change notification settings - Fork 17
/
run
executable file
·212 lines (181 loc) · 4.71 KB
/
run
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
#!/bin/bash
CURRENT_VERSION=1.0.2
usage()
{
echo "usage: bash deploy/run.sh [-a] | [-u] | [-d] | [-s] | [-m] | [-v]"
}
vercomp () {
if [[ $1 == $2 ]]
then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2
fi
done
return 0
}
NEW_VERSION=$(curl -s "https://api.github.com/repos/magefan/magento2-zero-downtime-deploy/releases/latest" | awk -F '"' '/tag_name/{print $4}')
if [ $NEW_VERSION ]; then
vercomp $NEW_VERSION $CURRENT_VERSION
case $? in
1)
echo -e "\e[32m${1}There is a new Zero Downtime v$NEW_VERSION available. Your current version is $CURRENT_VERSION \e[0m"
echo -e "\e[32m${1}To install the newest version remove the current one and install the script again:\e[0m"
echo -e "\e[32m${1}https://magefan.com/blog/magento-2-zero-downtime-deployment\e[0m"
;;
esac
fi
if [ $# -gt 0 ]; then
echo ''
else
SETUP_ALL=1
fi
LAST_OPTION='';
SETUP_MODULES=''
while [ "$1" != "" ]; do
case $1 in
-a | --all | -u | --upgrade )
SETUP_ALL=1
;;
-d | --di )
SETUP_DI=1
;;
-s | --static-content )
SETUP_STATIC_CONTENT=1
;;
-v | --version )
echo $CURRENT_VERSION
exit
;;
-m | --modules )
#do nothing here
;;
-h | --help )
usage
exit
;;
* )
if [ "$LAST_OPTION" != -m ] && [ "$LAST_OPTION" != --modules ]; then
usage
exit 1
else
SETUP_MODULES="$SETUP_MODULES $1"
shift
continue
fi
esac
LAST_OPTION=$1
shift
done
if [ "$SETUP_MODULES" ]; then
SETUP_ALL=1
fi
MDIR="$PWD"
DIR="$PWD/deploy"
cd $DIR
INSTANCE="$PWD/instance"
MAGE_INIT_PARAMS="--magento-init-params=MAGE_DIRS[base][path]=$INSTANCE&MAGE_DIRS[cache][path]=$INSTANCE/var/cache"
SEK=SECONDS
echo 'Remove old files ...'
rm -rf $INSTANCE
echo 'Create new instance folders and files ...'
mkdir -p $INSTANCE;
cd $INSTANCE
mkdir -p generated;
mkdir -p pub;
mkdir -p pub/static;
mkdir -p var;
cp -rf $MDIR/app app
cp -rf $MDIR/bin bin
cp -rf $MDIR/dev dev
cp -rf $MDIR/lib lib
cp -rf $MDIR/setup setup
cp -rf $MDIR/vendor vendor
cp -rf $MDIR/phpserver phpserver
cp -rf $MDIR/update update
cp -rf $MDIR/composer.json composer.json
cp -rf $MDIR/composer.lock composer.lock
# temporary copy env.php file with save cache local
rm app/etc/env.php
cp -rf $DIR/app/env.php app/etc/env.php
if [ "$SETUP_MODULES" ]; then
echo 'Enabling modules ...'
bin/magento module:enable $SETUP_MODULES $MAGE_INIT_PARAMS
fi
echo 'Start deploying ...'
if [ $SETUP_ALL ] || [ $SETUP_DI ]; then
bin/magento setup:di:compile
fi
if [ $SETUP_ALL ] || [ $SETUP_STATIC_CONTENT ]; then
#$INSTANCE/bin/magento setup:static-content:deploy
. "$DIR/app/static-content-deploy.sh"
cd $INSTANCE
fi
if [ $SETUP_ALL ]; then
cd $MDIR
bin/magento maintenance:enable
cd $INSTANCE
bin/magento setup:upgrade --keep-generated $MAGE_INIT_PARAMS
fi
if [ $SETUP_ALL ]; then
GENERATED_FOLDERS=( "app/etc/config.php" "generated" "pub/static/adminhtml" "pub/static/frontend" "pub/static/deployed_version.txt" "var/view_preprocessed" )
else
GENERATED_FOLDERS=( "app/etc/config.php" )
if [ $SETUP_DI ]; then
GENERATED_FOLDERS+=( "generated")
fi
if [ $SETUP_STATIC_CONTENT ]; then
GENERATED_FOLDERS+=( "pub/static/adminhtml" "pub/static/frontend" "pub/static/deployed_version.txt" "var/view_preprocessed" )
fi
fi
echo 'Copy new files into Magento ... '
for i in "${GENERATED_FOLDERS[@]}"
do
:
cp -rf $i "$MDIR/$i-deploy"
done
echo 'Replace files in Magento ... '
for i in "${GENERATED_FOLDERS[@]}"
do
:
mv "$MDIR/$i" "$MDIR/$i-old-deploy"
mv "$MDIR/$i-deploy" "$MDIR/$i"
done
echo 'Remove magento pub/static/_cache ... '
rm -rf "$MDIR/pub/static/_cache"
echo 'Replace old Magento files ... '
for i in "${GENERATED_FOLDERS[@]}"
do
:
rm -rf "$MDIR/$i-old-deploy"
done
if [ $SETUP_ALL ]; then
cd $MDIR
bin/magento maintenance:disable
fi
cd $MDIR
bin/magento c:e
bin/magento c:f
echo 'Remove tmp files ...'
rm -rf $INSTANCE
echo 'Finished.'