-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
455 lines (248 loc) · 8.5 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
### 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('developers-mail-list@address.com','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 <stvkoch@gmail.com>