Created
November 8, 2014 19:20
-
-
Save vicolachips44/fb90cc2a971ec3835bce to your computer and use it in GitHub Desktop.
Symfony2 deployment with grunt! (a reminder)
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
/** | |
* @author vga@decatime.org | |
* @license MIT | |
* | |
* 2014-11-08 | |
*/ | |
module.exports = function(grunt) | |
{ | |
require('load-grunt-tasks')(grunt); | |
grunt.initConfig({}); | |
// ** BEGIN CONFIGURATION---------------------------------------------------- | |
var config = { | |
// the git repository to clone (will be clone in temp_dir) | |
git_repo: '', | |
// the git branch to work on (ex: master) | |
git_branch: '', | |
// the temporary directory to pull from git | |
temp_dir: '<%= grunt.template.today("yyyy_mm_dd_hh") %>', | |
// the folder uri on the server for the log files (this should have proper | |
// read - writes settings) this folder will be simlinked | |
log_srv_path: '', | |
// the folder uri on the server for the cache (simlinked) | |
cache_srv_path: '', | |
// the directory to save the tar.gz snapshot | |
archive_dir: '', | |
// the server root directory to deploy into | |
deploy_dir: '' | |
}; | |
// ** END CONFIGURATION------------------------------------------------------ | |
/** | |
* Clone the repository into the temporary folder. | |
*/ | |
grunt.config('gitclone', { | |
clone: { | |
options: { | |
repository: config.git_repo, | |
branch: config.git_branch, | |
directory: config.temp_dir | |
} | |
} | |
}); | |
/** | |
* - prepare: Run some prepare tasks like composer, bower and grunt | |
* - clean: Remove all files and folders related to the dev env and create | |
* simlinks for the cache and the logs directory | |
* - deploy: clean the target directory and then copy files and folders | |
* - zip: create an archive of the deployed web site | |
*/ | |
grunt.config('shell', { | |
prepare: { | |
command: [ | |
'cd ' + config.temp_dir, | |
'composer install --prefer-dist --no-ansi --no-dev --no-interaction --no-progress --no-scripts --optimize-autoloader', | |
'bower install', | |
'npm install', | |
'grunt' | |
].join('&&') | |
}, | |
clean: { | |
command: [ | |
'cd ' + config.temp_dir, | |
'rm -rf node_modules', | |
'rm -rf .git', | |
'rm -rf features', | |
'rm -rf bin', | |
'rm -rf app/cache app/logs', | |
'rm *.json behat.yml.dist *.lock *.js *.md *.yml .gitignore .bowerrc', | |
'rm app/check.php app/phpunit.xml.dist app/SymfonyRequirements.php app/console', | |
'rm app/config/config_dev.yml app/config/config_test.yml', | |
'rm app/config/routing_dev.yml', | |
'rm web/app_dev.php web/config.php', | |
'rm -rf web/css web/js web/vendor', | |
'mv app/config/parameters.yml.dist app/config/parameters.yml', | |
'ln -s ' + config.cache_srv_path + ' app/cache', | |
'ln -s ' + config.log_srv_path + ' app/logs', | |
'rm -rf _deploy' | |
].join('&&') | |
}, | |
deploy: { | |
command: | |
[ | |
'rm -rf ' + config.deploy_dir + '/app', | |
'rm -rf ' + config.deploy_dir + '/src', | |
'rm -rf ' + config.deploy_dir + '/vendor', | |
'rm -rf ' + config.deploy_dir + '/web', | |
'cp -R ' + config.temp_dir + '/** ' + config.deploy_dir, | |
'rm -rf ' + config.temp_dir | |
].join('&&') | |
}, | |
zip: { | |
command: [ | |
'tar -czf ' + config.temp_dir + '.tar.gz ' + config.temp_dir, | |
'mv ' + config.temp_dir + '.tar.gz ' + config.archive_dir | |
].join('&&') | |
} | |
}); | |
/** | |
* Finally register tasks to be run. | |
*/ | |
grunt.registerTask('default',[ | |
'gitclone:clone', | |
'shell:prepare', | |
'shell:clean', | |
'shell:zip', | |
'shell:deploy']); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note
This script must be run in a folder named _deploy
Plugins used: