-
Notifications
You must be signed in to change notification settings - Fork 0
Maki - Deploy like a NINJA
stvkoch/Maki
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
### What is it? - MAKI helps us to create, manage and execute taskss task. ### What makes? - Executes commands on local servers, testing environment and productions servers ### How to? * first step is to install on your computer Maki * Then, at the root of your project to create a file named 'tasks.php' * Add tasks to the file 'tasks.php' * Execute the commands 'maki ...' *** @roadmap: - implement recursive remote_local function - implement recursive local_remote function ## install ### dependencies: - pecl install ssh2 channel://pecl.php.net/ssh2-0.11.3 pecl ssh2 has dependency: - libssh (brew install libssh) or (apt-get install libssh) - openssl (brew install openssl) or (apt-get install openssl) ### Install Maki cd ~ git clone git://github.com/stvkoch/Maki.git sudo ln -s ~/Maki/bin/maki /usr/bin/maki OR cd ~ git clone git://github.com/stvkoch/Maki.git #copy Maki folder to /usr/local/maki and create link /usr/local/maki/bin/maki to /usr/bin/maki ./Maki/bin/maki --self install *** Now, you can execute maki commands on your project. First you need create your tasks on tasks.php file, create it on root of your project. cd ~/www/yourproject vi tasks.php Add configs and tasks: //this is examples what you can do set('SSH_USERNAME', 'username1' ); set('SSH_PASSWORD', 'passcrypts1'); set('SSH_HOST', 'production.hostname.local'); set('LOCAL_BASE_DIR', '/home/username/www/application'); set('REMOTE_BASE_DIR','/server/www/application'); set('FILES_ON_GIT','git://github.com/stvkoch/Maki.git'); task('install', 'webserver01', function(){ if(prompt('Install now? You are sure??', 'red')=='y'){ remote('mkdir -p '.get('REMOTE_BASE_DIR')); remote('cd '.get('REMOTE_BASE_DIR')); remote('git clone '.get('FILES_ON_GIT')); } }); task('install', 'sqlserver01', function(){ if(prompt('Install SQL now? You are sure??', 'red', 'white')=='y'){ local('mysqldump -h master_or_dev.sqlserver.domain.ext -u userlocal -p passlocal --databases super_DB > /tmp/current_dump_DB.sql') local_remote('/tmp/current_dump_DB.sql', '/tmp/current_dump_DB.sql');//copy local file to server remote('mysql -h '.get('SQL_HOST').' -u usernameSQL -p XPTOPass < /tmp/current_dump_DB.sql'); remote('cd '.get('REMOTE_BASE_DIR')); remote('git clone '.get('FILES_ON_GIT')); } }); task('tasks', function(){ message('woow... I ready to tasks my code', 'blue'); }); //test stuffs task('test', function(){ message('testing, testing, 1,2,3...', 'white'); return true; }); //git tasks task('git', function(){ local('cd '. get('LOCAL_BASE_DIR')); $message = prompt('Commit message:','red', 'white'); $diffs = local('git diff'); local('git add .'); local("git commit -m '${message}'"); local('git push'); //mail('[email protected]','Commit:'.$message, $diff); }); OK, you create your basic tasks tasks.php file, and now you can execute commands *** @example list all task on tasks.php file ~/www/yourprojectfolder$ maki list - tasks - test - git run task test ~/www/yourprojectfolder$ maki test show help commands ~/www/yourprojectfolder$ maki help *** You can create hierarchy tasks @example hierarchy tasks //maki git (run add, commit and push) task('git', 'diff', function(){ local('cd '. get('LOCAL_BASE_DIR')); $message = local('git diff'); message($message); //if you like, send e-mail with diff }); task('git', 'add', function(){ local('cd '. get('LOCAL_BASE_DIR')); local('git add .', true); }); task('git', 'commit', function(){ local('cd '. get('LOCAL_BASE_DIR')); $messageCommit = prompt('Message Commit:'); local("git commit -m '".$messageCommit."'"); }); task('git', 'push', function(){ local('cd '. get('LOCAL_BASE_DIR')); local('git push'); }); You can run one or all hierarchy tasks @example > maki git diff #execute one task > maki git #execute all git tasks (diff, add, commit and push) *** *** Useful commands used to create tasks within the file tasks.php ## Commands ### set Set configuration of environment set($cons, $value, $env='master') ### get Get specific configuration of environment get($cons, $env='master') ### get_config_env Get configuration of environment get_config_env($env='master') ### Task Create new task task() @example //create tasks.php on root of your project <? set('SSH_USERNAME', 'username1' ); set('SSH_PASSWORD', 'passcrypts1'); set('SSH_HOST', 'production.hostname.local'); ... task('test', 'frontend', function(){ require_once 'frontendTest.php'; require_once 'PHPUnit.php'; $suite = new PHPUnit_TestSuite("FrontendTest"); $result = PHPUnit::run($suite); if($result ->errorCount()>0){ message('Errroor you not can tasks', 'red'); }else{ maki('git'); maki('tasks'); } }); *** ### remote Execute command on remote computer via SSH remote($command, $send_output=false) *** ### local Execute command on local computer local($command, $send_output=false) *** ### remote_local Copy recursive file from remote directory to local directory remote_local($path_remote, $path_local) *** ### local_remote Copy recursive file from local directory to remote directory local_remote($path_local, $path_remote) *** ### maki Run hierarchy tasks. You can run task inside tasks. maki() @example task('tasks',function(){ if(maki('test')) remote('git pull'); }); task('test', function(){ message('testing,testing, 1,2,3,...'); return false;//woowww test fail! }); *** ### open_environment Add new environment on top of stack. You can have more than one configuration environment, it is these environments that run tasks. open_environment($environment) @example set('SSH_USERNAME', 'username1', 'production'); set('SSH_PASSWORD', 'passcrypts1', 'production'); set('SSH_HOST', 'production.hostname.local', 'production'); set('SSH_USERNAME', 'usernamestaging', 'staging'); set('SSH_PASSWORD', 'passcryptsstaging', 'staging'); set('SSH_HOST', 'staging.hostname.local', 'staging'); task('deploy', 'production', function(){ open_environment('production'); remote('cd /path/to/application'); remote('git pull'); close_environment();//remove environment of top stack(production), and 'master' environment is available }); task('deploy', 'production', function(){ open_environment('staging'); remote('cd /path/to/application'); remote('git pull'); }); *** ### close_environment Remove environment of stack environments close_environment($environment) *** ### current_environment Return top environment on stack $env = current_environment() $env->name() *** ### message Show message on terminal message($message, $fgColor = null, $bgColor = null, $style = null) *** ### prompt Ready to accept your input $string = prompt($message, $fgColor = null, $bgColor = null, $style = null) *** ### configurations SSH_USERNAME, SSH_PASSWORD, SSH_HOST, SSH_PORT, SSH_PUBLIC_KEY, (if set public_key and private_key ssh use this try connect) SSH_PRIVATE_KEY,(if set public_key and private_key ssh use this try connect) SSH_SECRET (if set public_key and private_key ssh use this try connect) PATHs LOCAL_BASE_DIR, REMOTE_BASE_DIR *** example set('SSH_USERNAME', 'userprod', 'production'); set('SSH_PASSWORD', 'passprod', 'production'); set('SSH_USERNAME', 'userstag', 'staging'); set('SSH_PASSWORD', 'passstag', 'staging'); task('tasks', function(){ open_environment('staging'); remote('git pull'); open_environment('production'); remote('git pull'); //run on ssh production close_environment('production'); remote('service restart apache');//on staging environment close_environment('staging'); }); See exemple file __tasks.php__ Any question Steven Koch <[email protected]>
About
Maki - Deploy like a NINJA
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published