mirror of https://github.com/hauke68/Magallanes
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
2.3 KiB
44 lines
2.3 KiB
13 years ago
|
<?php
|
||
|
class Mage_Task_Add
|
||
|
{
|
||
13 years ago
|
public function environment($environmentName, $withRelases = false)
|
||
13 years ago
|
{
|
||
|
$environmentName = strtolower($environmentName);
|
||
13 years ago
|
$environmentConfigFile = '.mage/config/environment/' . $environmentName . '.yml';
|
||
13 years ago
|
|
||
|
Mage_Console::output('Adding new environment: <dark_gray>' . $environmentName . '</dark_gray>');
|
||
|
|
||
|
// Check if there is already an environment with the same name
|
||
|
if (file_exists($environmentConfigFile)) {
|
||
13 years ago
|
Mage_Console::output('<light_red>Error!!</light_red> Already exists an environment called <dark_gray>' . $environmentName . '</dark_gray>', 1, 2);
|
||
13 years ago
|
} else {
|
||
13 years ago
|
$releasesConfig = 'releases:' . PHP_EOL
|
||
|
. ' enabled: true' . PHP_EOL
|
||
13 years ago
|
. ' max: 10' . PHP_EOL
|
||
13 years ago
|
. ' symlink: current' . PHP_EOL
|
||
|
. ' directory: releases' . PHP_EOL;
|
||
|
|
||
13 years ago
|
$baseConfig = '#' . $environmentName . PHP_EOL
|
||
13 years ago
|
. 'deployment:' . PHP_EOL
|
||
13 years ago
|
. ' user: dummy' . PHP_EOL
|
||
|
. ' from: ./' . PHP_EOL
|
||
|
. ' to: /var/www/vhosts/example.com/www' . PHP_EOL
|
||
|
. ' excludes:' . PHP_EOL
|
||
13 years ago
|
. ($withRelases ? $releasesConfig : '')
|
||
13 years ago
|
. 'hosts:' . PHP_EOL
|
||
13 years ago
|
. 'tasks:' . PHP_EOL
|
||
13 years ago
|
. ' pre-deploy:' . PHP_EOL
|
||
|
. ' on-deploy:' . PHP_EOL
|
||
|
. ' - deployment/rsync' . PHP_EOL
|
||
|
. ' post-deploy:' . PHP_EOL;
|
||
13 years ago
|
$result = file_put_contents($environmentConfigFile, $baseConfig);
|
||
|
|
||
|
if ($result) {
|
||
|
Mage_Console::output('<light_green>Success!!</light_green> Environment config file for <dark_gray>' . $environmentName . '</dark_gray> created successfully at <blue>' . $environmentConfigFile . '</blue>');
|
||
13 years ago
|
Mage_Console::output('<dark_gray>So please! Review and adjust its configuration.</dark_gray>', 2, 2);
|
||
13 years ago
|
} else {
|
||
13 years ago
|
Mage_Console::output('<light_red>Error!!</light_red> Unable to create config file for environment called <dark_gray>' . $environmentName . '</dark_gray>', 1, 2);
|
||
13 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|