83
83
$path = getenv('DEPLOY_PATH');
84
84
$slack = getenv('DEPLOY_SLACK_WEBHOOK');
85
85
86
+ $composer = getenv('DEPLOY_COMPOSER') ?: 'composer';
87
+ $disable_log = getenv('DEPLOY_DISABLE_LOG');
88
+ $disable_log = 'false' === $disable_log ? false : (boolean) $disable_log;
86
89
$maxmind_dl = getenv('DEPLOY_DL_MAXMIND');
87
90
$maxmind_dl = 'false' === $maxmind_dl ? false : (boolean) $maxmind_dl;
88
91
$opcache_reset = getenv('DEPLOY_OPCACHE_RESET');
106
109
$current_release_dir = last($output);
107
110
fprintf(STDERR, " => %s\n", $current_release_dir); fflush(STDERR);
108
111
109
- define('CMD_LOG_START', 'exec> >(sh -c "while read line;do echo \`date\` \"\$line\";done|tee -a ' . escapeshellarg($log_file) . '") 2> >(sh -c "while read line;do echo \`date\` stderr: \"\$line\";done|tee -a ' . escapeshellarg($log_file) . '" >&2)');
112
+ define('CMD_LOG_START', $disable_log ? '' : 'exec> >(sh -c "while read line;do echo \`date\` \"\$line\";done|tee -a ' . escapeshellarg($log_file) . '") 2> >(sh -c "while read line;do echo \`date\` stderr: \"\$line\";done|tee -a ' . escapeshellarg($log_file) . '" >&2)');
110
113
111
114
if (!$repository) {
112
115
// make temporary checkout & copy to deployment server
123
126
$command = sprintf('ssh %s mkdir -p "%s"', escapeshellarg($server), escapeshellarg($new_release_dir));
124
127
exec($command, $output);
125
128
129
+ // checking if git supports '-j' flag
130
+ $use_j = true;
131
+ $command = 'git clone -j8 2>&1';
132
+ $prefix = get_prefix($hostname);
133
+
134
+ fprintf(STDERR, "{$prefix}executing command: %s\n", $command); fflush(STDERR);
135
+ if (strpos(`$command`, 'error: unknown switch')) {
136
+ fprintf(STDERR, "{$prefix} => Warning: this host does not support 'git clone -j'!\n", $command); fflush(STDERR);
137
+ $use_j = false;
138
+ }
139
+
126
140
// clone repository
127
- $command_format = 'sh -c "(%1$s umask 002; %1$s git clone --recursive -j8 -b %2 $s . %3 $s && %1$s rsync -zaSHx %3 $s/ %4 $s/); %1$s rm -rf %3 $s" 2>&1';
128
- $command = sprintf($command_format, $runner, escapeshellarg($branch), escapeshellarg($temp_checkout_dir), escapeshellarg($destination));
141
+ $command_format = 'sh -c "(%1$s umask 002; %1$s git clone --recursive %2$s -b %3 $s . %4 $s && %1$s rsync --exclude=.git\\* --exclude=Envoy.blade.php --exclude=Makefile - zaSHx %4 $s/ %5 $s/); %1$s rm -rf %4 $s" 2>&1';
142
+ $command = sprintf($command_format, $runner, $use_j ? '-j8' : '', escapeshellarg($branch), escapeshellarg($temp_checkout_dir), escapeshellarg($destination));
129
143
130
144
$prefix = get_prefix($hostname);
131
145
fprintf(STDERR, "{$prefix}executing command: %s\n", $command); fflush(STDERR);
@@ -199,6 +213,7 @@ function get_prefix($server)
199
213
{{ CMD_LOG_START } }
200
214
echo " - Initializing of '{{ $app_name } } ' started on {{ $date } } on environment: {{ $env } } : {{ $server } } "
201
215
if [ ! -d {{ $current_dir } } ]; then
216
+ [ -d {{ $releases_dir } } ] || {{ $runner } } mkdir -p {{ $releases_dir } }
202
217
{{ $runner } } mv {{ $new_release_dir } } /storage {{ $app_dir } } /storage
203
218
{{ $runner } } cp {{ $new_release_dir } } /.env.example {{ $app_dir } } /.env
204
219
echo " +- deployment path initialised, configure {{ $app_dir } } /.env and run 'envoy run deploy --env={{ $env } } ' to deploy."
@@ -212,11 +227,24 @@ function get_prefix($server)
212
227
{{ CMD_LOG_START } }
213
228
echo "Starting deployment task '{{ $task } } ' of '{{ $app_name } } ' on {{ $date } } on {{ $env } } : {{ $server } }{{ $dry_run ? ' [DRY-RUN]' : ' ' } } "
214
229
echo " - Cloning repository ..."
215
- [ -d {{ $releases_dir } } ] || {{ $runner } } mkdir {{ $releases_dir } }
230
+ [ -d {{ $releases_dir } } ] || {{ $runner } } mkdir -p {{ $releases_dir } }
231
+ echo " +- created release directory ..."
216
232
@if ($repository )
217
- {{ $runner } } git clone --recursive -j8 --depth 1 -b {{ $branch } } {{ $repository } } {{ $new_release_dir } }
218
- echo " +- repository cloned"
233
+ use_j=true
234
+ if git clone -j8 2>&1 | fgrep 'error: unknown switch' > /dev/null 2>&1 ; then
235
+ echo " +- warning: environment '{{ $env } } ' does not support 'git clone -j' !!!"
236
+ use_j=false
237
+ else
238
+ echo " +- checked that git supports '-j' flag ..."
239
+ fi
240
+ if $use_j; then
241
+ {{ $runner } } git clone --recursive -j8 --depth 1 -b {{ $branch } } {{ $repository } } {{ $new_release_dir } }
242
+ else
243
+ {{ $runner } } git clone --recursive --depth 1 -b {{ $branch } } {{ $repository } } {{ $new_release_dir } }
244
+ fi
245
+ echo " +- repository cloned"
219
246
@endif
247
+ chmod 751 {{ $new_release_dir } }
220
248
@endtask
221
249
222
250
@task (' deployment_links' )
@@ -239,12 +267,12 @@ function get_prefix($server)
239
267
{{ CMD_LOG_START } }
240
268
echo " - Running composer ..."
241
269
@if ( $current_release_dir )
242
- {{ $runner } } cp -a {{ $current_release_dir } } /vendor {{ $new_release_dir } } /
270
+ {{ $runner } } rsync -aSHAX {{ $current_release_dir } } /vendor {{ $new_release_dir } } / || true
243
271
echo " +- copied vendor"
244
272
@endif
245
273
{{ $runner } } cd {{ $new_release_dir } }
246
274
echo " +- running composer ..."
247
- {{ $runner } } composer install --no-interaction {{ $is_dev ? ' --no-dev' : ' ' } } --prefer-dist --no-scripts -q -o
275
+ {{ $runner } } {{ $ composer } } install --no-interaction {{ $is_dev ? ' --no-dev' : ' ' } } --prefer-dist --no-scripts -q -o
248
276
echo " +- composer installed"
249
277
@endtask
250
278
@@ -294,9 +322,9 @@ function get_prefix($server)
294
322
{{ $runner } } php {{ $current_dir } } /artisan route:cache || true # Create a route cache file for faster route registration (fails with Closure routes)
295
323
{{ $runner } } php {{ $current_dir } } /artisan config:cache # Create a cache file for faster configuration loading
296
324
{{ $runner } } php {{ $current_dir } } /artisan config:cache # 2nd time to fix incorrect database credentials???
297
- {{ $runner } } php {{ $current_dir } } /artisan storage:link # link storage/public
325
+ {{ $runner } } php {{ $current_dir } } /artisan storage:link || true # link storage/public (might fail for older Laravel versions)
298
326
echo " +- cache generated"
299
- echo " +- published '{{ $app_name } } '{{ ' @' } }{{ $branch } } to {{ $env } } "
327
+ echo " +- published '{{ $app_name } } '{{ ' @' } }{{ $branch } } to {{ $env } } at `date` "
300
328
@endtask
301
329
302
330
@task (' deployment_cleanup' )
0 commit comments