Skip to content

Instantly share code, notes, and snippets.

@warrickbayman
Last active Mar 29, 2021
Embed
What would you like to do?
Zero-downtime Laravel deployments - Version 2
@servers(['local' => '127.0.0.1', 'production' => 'user@server'])
@setup
$repo = 'git@gitlab.com:vendor/project.git';
$branch = 'master';
date_default_timezone_set('Africa/Johannesburg');
$date = date('YmdHis');
$appDir = '/opt/vendor/project';
$buildsDir = $appDir . '/releases';
$deploymentDir = $buildsDir . '/' . $date;
$serve = $appDir . '/source';
$env = $appDir . '/.env';
$storage = $appDir . '/storage';
$productionPort = 22;
$productionHost = 'user@server.com';
@endsetup
@task('build', ['on' => 'local'])
yarn prod
@endtask
@task('git', ['on' => 'production'])
git clone --depth 1 -b {{ $branch }} "{{ $repo }}" {{ $deploymentDir }}
@endtask
@task('install', ['on' => 'production'])
cd {{ $deploymentDir }}
rm -rf {{ $deploymentDir }}/storage
ln -nfs {{ $env }} {{ $deploymentDir }}/.env
ln -nfs {{ $storage }} {{ $deploymentDir }}/storage
composer install --prefer-dist --no-dev
php ./artisan migrate --force
php ./artisan storage:link
@endtask
@task('assets', ['on' => 'local'])
scp -P{{ $productionPort }} -qr public/css {{ $productionHost }}:{{ $deploymentDir }}/public
scp -P{{ $productionPort }} -qr public/js {{ $productionHost }}:{{ $deploymentDir }}/public
scp -P{{ $productionPort }} -q public/mix-manifest.json {{ $productionHost }}:{{ $deploymentDir }}/public
@endtask
@task('live', ['on' => 'production'])
ln -nfs {{ $deploymentDir }} {{ $serve }}
@endtask
@story('deploy')
build
git
install
assets
live
@endstory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment