-
-
Save warrickbayman/ec194c80f8222c8006bf21550cac04ba to your computer and use it in GitHub Desktop.
Zero-downtime Laravel deployments - Version 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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