Skip to content

Instantly share code, notes, and snippets.

@warrickbayman
Last active September 23, 2022 04:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save warrickbayman/ec194c80f8222c8006bf21550cac04ba to your computer and use it in GitHub Desktop.
Save warrickbayman/ec194c80f8222c8006bf21550cac04ba to your computer and use it in GitHub Desktop.
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