Skip to content

Instantly share code, notes, and snippets.

@kaz231
Created December 6, 2016 11:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaz231/fadfc22aee7ea5dede6870029baff01b to your computer and use it in GitHub Desktop.
Save kaz231/fadfc22aee7ea5dede6870029baff01b to your computer and use it in GitHub Desktop.
Building of symfony project using deployer - example
<?php
namespace Deployer;
require 'recipe/symfony3.php';
set('build_dir', dirname(__FILE__).'/build/');
set('build_branch', 'master');
set('bin/console', '{{ build_dir }}bin/console');
set('files_to_remove', [
'tests',
'app/config/config_dev.yml',
'app/config/config_test.yml',
'app/config/routing_dev.yml',
'app/config/parameters_ci.yml',
'app/config/parameters.yml',
'app/config/parameters.yml.dist',
'.eslintrc',
'.gitignore',
'.php_cs',
'.travis.yml',
'*.xml',
'phpunit.xml.dist',
'*.js',
'Dockerfile.*',
'behat.yml',
'var/cache/*',
'var/logs/*'
]);
task(
'build:dir', '
if [ -d {{ build_dir }} ]; then rm -rf "{{ build_dir }}"; fi
mkdir "{{ build_dir }}"
')->desc('Create build directory');
task(
'build:copy',
'git archive $(git symbolic-ref -q --short HEAD || git describe --tags --exact-match) | tar -x -C "{{ build_dir }}"'
)->desc('Copy code');
task(
'build:vendors',
function () {
set('node_env', get('env') === 'prod' ? '--production' : '');
run('cd {{ build_dir }} && {{env_vars}} {{bin/composer}} {{composer_options}}');
run('cd {{ build_dir }} && npm cache clean && npm install {{ node_env }}');
}
)->desc('Install vendors');
task(
'build:ui',
function () {
run('cd {{ build_dir }} && npm run build');
}
)->desc('Build UI');
task(
'build:clean-up',
function () {
$filesToRemove = get('files_to_remove');
foreach ($filesToRemove as $file) {
run(sprintf('rm -rf {{ build_dir }}%s', $file));
}
}
)->desc('Clean-up artifact from unnecessary files');
task(
'build', [
'build:dir',
'build:copy',
'build:vendors',
'build:ui',
'build:clean-up'
])->desc('Build project');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment