Skip to content

Instantly share code, notes, and snippets.

@max4kaps max4kaps/deploy.php
Created Aug 11, 2017

Embed
What would you like to do?
Example of deploy.php for deployer - Symfony 3.3 with github.com tagging on each deployment
<?php
/* (c) Max Kapshtyk <max@4bis.nl>
*
* Feel free to use for own purposes, don't forget to setup your information.
* For the full copyright and license information, please view the LICENSE on our website 4bis.nl/license
*/
namespace Deployer;
use function Deployer\{host, task, run, set, get, add, before, after, upload, writeln};
require 'vendor/deployer/deployer/recipe/symfony3.php';
// Specify the repository from which to download your project's code.
set('repository', 'git@github.com:yourrepo/yourproject.git');
set('dump_assets', true);
// Define a server for deployment.
host('production')
->hostname('server-prod.4bis.nl')
->port(22)
->stage('production')
->set('deploy_path', '/var/www/app.4bis.nl/web')
->set('branch', 'master')
->identityFile('~/.ssh/id_rssa_github')
->user('root')
;
host('staging')
->hostname('server-staging.4bis.nl')
->port(22)
->stage('staging')
->set('deploy_path', '/var/www/app-staging.4bis.nl/web')
->set('branch', 'dev')
->identityFile('~/.ssh/id_rssa_github')
->user('root')
;
task('database:migrate', function () {
run('{{env_vars}} {{bin/php}} {{bin/console}} doctrine:migrations:migrate {{console_options}} --allow-no-migration');
})->desc('Run migrations on need');
task('database:fixture', function () {
// check if db exists
run('{{env_vars}} {{bin/php}} {{bin/console}} doctrine:fixtures:load {{console_options}}');
})->desc('Load data in db');
before('database:migrate', 'database:backup');
after('deploy:vendors', 'database:migrate');
/**
* Dump all assets to the filesystem
*/
task('deploy:assetic:dump', function () {
if (get('dump_assets')) {
run('{{env_vars}} {{bin/php}} {{bin/console}} assetic:dump {{console_options}} ');
}
})->desc('Dump assets');
/**
* Dump all js translations
*/
task('deploy:js-translation:dump', function () {
if (get('dump_assets')) {
run('{{env_vars}} {{bin/php}} {{bin/console}} bazinga:js-translation:dump {{console_options}} ');
}
})->desc('Dump all js translations, in 4bis we use bazinga');
before('deploy:assetic:dump', 'deploy:js-translation:dump');
// lovely tag in our repo
task('git:tag', function () {
$git = get('bin/git');
$release = get('release_name');
$date = run('date +"%Y%m%d%H%M%S"');
$stage = get('stage');
$releaseTag = $stage . '.' . $release . '.' . $date;
run("cd {{release_path}} && $git tag $releaseTag");
run("cd {{release_path}} && $git push origin --tags");
})->desc('Adding new deployment tag to repo');
task('nginx:reload', function () {
run("service nginx reload");
run('service php7.1-fpm restart');
})->desc('reload nginx for symlink to current');
after('deploy:unlock', 'git:tag');
after('deploy:unlock', 'nginx:reload');
@Martin1982

This comment has been minimized.

Copy link

Martin1982 commented Feb 8, 2018

In line 46 (https://gist.github.com/max4kaps/6867cdfc14aa91262f88c173e7f67558#file-deploy-php-L46) a reference to database:backup is made. Using deployer ^0.6 this task is not available (I assume it should be a custom one).

Removing/commenting this line will run the deploy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.