-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·115 lines (88 loc) · 2.87 KB
/
deploy.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
#!/bin/bash
set -ex
SCRIPT_DIR=$(dirname $(readlink -f $0))
pushd ${SCRIPT_DIR}
pushd ..
for patch in deploy/patches/*.patch ; do
patch -p1 -R < ${patch}
done
popd
function finish {
cd ${SCRIPT_DIR}/..
for patch in deploy/patches/*.patch ; do
patch -p1 < ${patch}
done
}
trap finish EXIT
rm -rf attendance
mkdir attendance
cp ../staging/www/attendance/.htaccess attendance
pushd ..
git ls-files attendance-api | cpio -pdm deploy/attendance
git ls-files attendance-web | cpio -pdm deploy/attendance
popd
mv attendance/attendance-web attendance/attendance-web-src
source deploy.env
pushd attendance/attendance-api
mv .env.example .env
sed -i "s/APP_URL=.*/APP_URL=${APP_URL//\//\\\/}/g" .env
sed -i "s/APP_DEBUG=.*/APP_DEBUG=${APP_DEBUG//\//\\\/}/g" .env
sed -i "s/APP_ENV=.*/APP_ENV=${APP_ENV//\//\\\/}/g" .env
sed -i "s/APP_SUBDIR=.*/APP_SUBDIR=${APP_SUBDIR//\//\\\/}/g" .env
sed -i "s/DB_HOST=.*/DB_HOST=${DB_HOST//\//\\\/}/g" .env
sed -i "s/DB_USERNAME=.*/DB_USERNAME=${DB_USERNAME//\//\\\/}/g" .env
sed -i "s/DB_PASSWORD=.*/DB_PASSWORD=${DB_PASSWORD//\//\\\/}/g" .env
sed -i "s/DB_DATABASE=.*/DB_DATABASE=${DB_DATABASE//\//\\\/}/g" .env
sed -i "s/SLACK_CLIENT_ID=.*/SLACK_CLIENT_ID=${SLACK_CLIENT_ID//\//\\\/}/g" .env
sed -i "s/SLACK_CLIENT_SECRET=.*/SLACK_CLIENT_SECRET=${SLACK_CLIENT_SECRET//\//\\\/}/g" .env
sed -i "s/SLACK_TEAM=.*/SLACK_TEAM=${SLACK_TEAM//\//\\\/}/g" .env
popd
pushd attendance/attendance-web-src
rm -rf dist/attendance-web
docker run --rm \
--entrypoint "sh" \
-u 1000:1000 \
-v ${PWD}/:/mnt \
node:18-alpine \
-c "cd /mnt && npm ci && npm run-script ng -- build -c production --base-href ${APP_SUBDIR}/"
popd
mv attendance/attendance-web-src/dist/attendance-web attendance/attendance-web
rm -rf attendance/attendance-web-src
cat > attendance/install.sh << 'EOF'
#!/bin/bash
set -ex
SCRIPT_DIR=$(dirname $(readlink -f $0))
cd ${SCRIPT_DIR}
pushd backup
./backup.sh
popd
cd attendance-api
composer install --optimize-autoloader --no-dev
php artisan key:generate
php artisan config:cache
php artisan migrate --force
#php artisan seed --class=RolesSeeder
echo INSTALL FINISHED
sleep 2
rm $0
EOF
chmod +x attendance/install.sh
mkdir -p attendance/backup/attendance_backups
cp ../backup/backup.sh attendance/backup/backup.sh
chmod +x attendance/backup/backup.sh
mkdir -p attendance/scripts/logs
cp ./scripts/*.sh attendance/scripts
chmod +x attendance/scripts/*.sh
# -r recursive
# -l copy symlinks as symlinks
# -p preserve permissions
# -t preserve modification times
# -v verbose
# -z compress files during transfer
rsync -rlptvz --progress --delete \
-e 'ssh -i ~/.ssh/id_rsa_win' \
./attendance/ momentu2@momentum4999.com:~/public_html/attendance \
--exclude backup/attendance_backups/ \
--exclude scripts/logs
ssh -i ~/.ssh/id_rsa_win momentu2@momentum4999.com 'bash -l -c "~/public_html/attendance/install.sh"'
popd