forked from themosis/themosis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Envoy.blade.php
106 lines (87 loc) · 3.12 KB
/
Envoy.blade.php
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
@setup
$site_name = 'meat';
$ssh_user = 'forge';
$server_ip = '159.203.184.9';
$server_base_path = '/home/forge/' . $site_name . '.dmeat.cl';
//$sync_folder = '/storage/app/'; // Laravel | Based on the base path of the project
$sync_folder = '/htdocs/content/uploads/'; // Themosis | Based on the base path of the project
$ssh_connection = $ssh_user.'@'.$server_ip;
@endsetup
@servers(['server' => [$ssh_connection], 'local' => '127.0.0.1'])
@task('setup', ['on' => 'local'])
echo "<info>Installing composer dependencies...</info>";
composer install --prefer-dist
echo "<info>Installing NPM dependencies...</info>";
npm install
echo "<info>Compiling assets...</info>";
npm run watch
@endtask
@story('sync')
db:backup
db:update_local
db:delete_dump_server
db:delete_dump_local
pull_images
@endstory
@story('sync_database')
db:backup
db:update_local
db:delete_dump_server
db:delete_dump_local
@endstory
@task('show_env', ['on' => 'server'])
cat {{ $server_base_path }}/.env
@endtask
@task('db:backup', ['on' => 'server'])
cd {{ $server_base_path }}
export DB_HOST=$(php vendor/bin/envoy_helper get_env DB_HOST)
export DB_PASS=$(php vendor/bin/envoy_helper get_env DB_PASSWORD)
export DB_USER=$(php vendor/bin/envoy_helper get_env DB_USER)
export DB_NAME=$(php vendor/bin/envoy_helper get_env DB_NAME)
mysqldump -h $DB_HOST -u $DB_USER -p$DB_PASS -c -e --default-character-set=utf8 --single-transaction --skip-set-charset --add-drop-database $DB_NAME | gzip -c > {{ $site_name }}.sql.gz
echo "Database dumped on server"
@endtask
@task('db:update_local', ['on' => 'local'])
if [ -f {{ $site_name }}.sql ]; then
echo "File {{ $site_name }}.sql deleted"
rm {{ $site_name }}.sql
fi
if [ -f {{ $site_name }}.sql.gz ]; then
echo "File {{ $site_name }}.sql.gz deleted"
rm {{ $site_name }}.sql.gz
fi
echo "Downloading database backup from server..."
scp {{ $ssh_connection }}:{{ $server_base_path }}/{{ $site_name }}.sql.gz ./
echo "Database dump downloaded";
gzip -d {{ $site_name }}.sql.gz
echo "Importing backup in local database..."
export DB_HOST=$(php vendor/bin/envoy_helper get_env DB_HOST)
export DB_PASS=$(php vendor/bin/envoy_helper get_env DB_PASSWORD)
export DB_USER=$(php vendor/bin/envoy_helper get_env DB_USER)
export DB_NAME=$(php vendor/bin/envoy_helper get_env DB_NAME)
if [ -z "$DB_PASS" ]; then
echo "importing without mysql password"
mysql -h $DB_HOST -u $DB_USER $DB_NAME < {{ $site_name }}.sql --binary-mode
else
mysql -h $DB_HOST -u $DB_USER -p$DB_PASS $DB_NAME < {{ $site_name }}.sql --binary-mode
fi
echo "<info>Local database updated</info>"
@endtask
@task('db:delete_dump_server', ['on' => 'server'])
cd {{ $server_base_path }}
if [ -f {{ $site_name }}.sql.gz ]; then
rm {{ $site_name }}.sql.gz
fi
echo "Database dump deleted"
@endtask
@task('db:delete_dump_local', ['on' => 'local'])
if [ -f {{ $site_name }}.sql ]; then
rm {{ $site_name }}.sql
fi
echo "Database dump deleted from local"
@endtask
@task('pull_images', ['on' => 'local'])
echo "Syncing images..."
rsync -avzP --exclude=bfi_thumb --exclude=cache {{ $ssh_connection }}:{{ $server_base_path }}{{ $sync_folder }} .{{ $sync_folder }}
echo "Images Synced"
@endtask