Skip to content
This repository was archived by the owner on Dec 28, 2021. It is now read-only.

Commit b310eca

Browse files
committed
Version up to 1.0.6.
1 parent ed4cc0f commit b310eca

File tree

4 files changed

+55
-46
lines changed

4 files changed

+55
-46
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ $ php artisan vendor:publish --tag=ldh-config
3434

3535
## Usage
3636

37-
*Deploy to server*
37+
*Deploy to server*
3838
Deploy full instance to the remote server
3939
```bash
4040
php artisan ldh:deploy --stage=production --branch=develop
4141
```
4242

43-
*Patch to server*
43+
*Patch to server*
4444
Push a simple patch to the remote server (minor changes only)
4545
```bash
4646
php artisan ldh:patch --stage=production --branch=patch
4747
```
4848

49-
*Rollback one instance*
49+
*Rollback one instance*
5050
Something went horrably wrong, go back in history
5151
```bash
5252
php artisan ldh:rollback --stage=production

src/Console/Commands/Patch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function handle()
5252
SSH::preFlight($this, $this->option('stage'), $this->option('branch'));
5353

5454
// Get the band-aid, we're going to patch some shit
55-
Deployer::doPatch($ssh, $this->option('stage'), $this->option('branch'));
55+
Deployer::doPatch($this->option('stage'), $this->option('branch'));
5656

5757
// Done
5858
SSH::performLanding($this->option('stage'));

src/Helpers/Deployer.php

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static function freshInit(Connection $connection, $stage)
1414
{
1515
// Init fresh remote repo
1616
$connection->define('init', [
17-
'cd '.config('laravel-deploy-helper.stages.'.$stage.'.remote.root'),
17+
'cd ' . config('laravel-deploy-helper.stages.' . $stage . '.remote.root'),
1818
'mkdir releases',
1919
'mkdir patches',
2020
'mkdir shared',
@@ -35,11 +35,11 @@ public static function doDeploy($stage, $branch, $ldh)
3535
{
3636
// Some stuff that does not change in runtime
3737
$releaseName = time();
38-
$home = config('laravel-deploy-helper.stages.'.$stage.'.remote.root');
39-
$shared = config('laravel-deploy-helper.stages.'.$stage.'.shared');
40-
$commands = config('laravel-deploy-helper.stages.'.$stage.'.commands');
41-
$versions = config('laravel-deploy-helper.stages.'.$stage.'.config.dependencies');
42-
$keep = config('laravel-deploy-helper.stages.'.$stage.'.config.keep');
38+
$home = config('laravel-deploy-helper.stages.' . $stage . '.remote.root');
39+
$shared = config('laravel-deploy-helper.stages.' . $stage . '.shared');
40+
$commands = config('laravel-deploy-helper.stages.' . $stage . '.commands');
41+
$versions = config('laravel-deploy-helper.stages.' . $stage . '.config.dependencies');
42+
$keep = config('laravel-deploy-helper.stages.' . $stage . '.config.keep');
4343

4444
// Check what releases are old and can be removed
4545
ksort($ldh);
@@ -52,67 +52,67 @@ public static function doDeploy($stage, $branch, $ldh)
5252

5353
// Check versions
5454
// Operators: http://php.net/manual/en/function.version-compare.php
55-
verbose('['.$stage.'] Checking dependencies. Migth take a minute.');
55+
verbose('[' . $stage . '] Checking dependencies. Migth take a minute.');
5656
foreach ($versions as $app => $version) {
5757
SSH::checkAppVersion($connection, $app, $version);
5858
}
5959

6060
// Define the deploy
61-
verbose('['.$stage.'] Creating new release directory and pulling from remote');
61+
verbose('[' . $stage . '] Creating new release directory and pulling from remote');
6262
SSH::execute($stage, [
63-
'mkdir '.$home.'/releases/'.$releaseName,
64-
'cd '.$home.'/releases/'.$releaseName,
65-
'git clone -b '.$branch.' '.config('laravel-deploy-helper.stages.'.$stage.'.git.http').' .',
63+
'mkdir ' . $home . '/releases/' . $releaseName,
64+
'cd ' . $home . '/releases/' . $releaseName,
65+
'git clone -b ' . $branch . ' ' . config('laravel-deploy-helper.stages.' . $stage . '.git.http') . ' .',
6666
]);
6767

6868
// Pre-flight for shared stuff
6969
$items['directories'] = [];
7070
foreach ($shared['directories'] as $share) {
71-
verbose('['.$stage.'] About to share direcroty "'.$home.'/current/'.$share.'"');
72-
$items['directories'][] = '[ -e '.$home.'/current/'.$share.' ] && cp -R -p '.$home.'/current/'
73-
.$share.' '.$home.'/shared/'.$share;
74-
$items['directories'][] = '[ -e '.$home.'/shared/'.$share.' ] && cp -R -p '.$home.'/shared/'.
75-
$share.' '.$home.'/releases/'.$releaseName;
71+
verbose('[' . $stage . '] About to share direcroty "' . $home . '/current/' . $share . '"');
72+
$items['directories'][] = '[ -e ' . $home . '/current/' . $share . ' ] && cp -R -p ' . $home . '/current/'
73+
. $share . ' ' . $home . '/shared/' . $share;
74+
$items['directories'][] = '[ -e ' . $home . '/shared/' . $share . ' ] && cp -R -p ' . $home . '/shared/' .
75+
$share . ' ' . $home . '/releases/' . $releaseName;
7676
}
7777
// Pre-flight for shared stuff
7878
$items['files'] = [];
7979
foreach ($shared['files'] as $share) {
80-
verbose('['.$stage.'] About to share file "'.$home.'/current/'.$share.'"');
81-
$items['files'][] = '[ -e '.$home.'/current/'.$share.' ] && cp -p '.$home.'/current/'.$share
82-
.' '.$home.'/shared/'.$share;
83-
$items['files'][] = '[ -e '.$home.'/shared/'.$share.' ] && cp -p '.$home.'/shared/'.$share.
84-
' '.$home.'/releases/'.$releaseName.'/'.$share;
80+
verbose('[' . $stage . '] About to share file "' . $home . '/current/' . $share . '"');
81+
$items['files'][] = '[ -e ' . $home . '/current/' . $share . ' ] && cp -p ' . $home . '/current/' . $share
82+
. ' ' . $home . '/shared/' . $share;
83+
$items['files'][] = '[ -e ' . $home . '/shared/' . $share . ' ] && cp -p ' . $home . '/shared/' . $share .
84+
' ' . $home . '/releases/' . $releaseName . '/' . $share;
8585
}
8686

8787
// Define shared files
88-
verbose('['.$stage.'] Syncing shared files');
88+
verbose('[' . $stage . '] Syncing shared files');
8989
SSH::execute($stage, $items['files']);
9090

9191
// Define shared directories
92-
verbose('['.$stage.'] Syncing shared directories');
92+
verbose('[' . $stage . '] Syncing shared directories');
9393
SSH::execute($stage, $items['directories']);
9494

9595
$items = [];
9696
foreach ($commands as $command) {
97-
$items[] = 'cd '.$home.'/releases/'.$releaseName.' && '.$command;
97+
$items[] = 'cd ' . $home . '/releases/' . $releaseName . ' && ' . $command;
9898
}
9999
// Define commands
100-
verbose('['.$stage.'] Executing custom commands');
100+
verbose('[' . $stage . '] Executing custom commands');
101101
SSH::execute($stage, $items);
102102

103103
// Define post deploy actions
104-
verbose('['.$stage.'] Linking new release to /current directory and removing temp');
104+
verbose('[' . $stage . '] Linking new release to /current directory and removing temp');
105105
SSH::execute($stage, [
106-
'ln -sfn '.$home.'/releases/'.$releaseName.' '.$home.'/current',
107-
'rm -rf '.$home.'/shared/*',
106+
'ln -sfn ' . $home . '/releases/' . $releaseName . ' ' . $home . '/current',
107+
'rm -rf ' . $home . '/shared/*',
108108
]);
109109

110110
// Remove old deploys
111111
$items = [];
112112
foreach ($toRemove as $dir => $val) {
113-
$items[] = 'echo "Removing release '.$dir.'" && rm -rf '.$home.'/releases/'.$dir;
113+
$items[] = 'echo "Removing release ' . $dir . '" && rm -rf ' . $home . '/releases/' . $dir;
114114
}
115-
verbose('['.$stage.'] Cleaning up old releases');
115+
verbose('[' . $stage . '] Cleaning up old releases');
116116
SSH::execute($stage, $items);
117117

118118
$ldh[$releaseName] = true;
@@ -125,15 +125,15 @@ public static function doDeploy($stage, $branch, $ldh)
125125
*/
126126
public static function doRollback(Connection $connection, $stage, $ldh, $dirs)
127127
{
128-
$home = config('laravel-deploy-helper.stages.'.$stage.'.remote.root');
128+
$home = config('laravel-deploy-helper.stages.' . $stage . '.remote.root');
129129

130130
// Define post deploy actions
131131
$connection->define('preformRollback', [
132-
'ln -sfn '.$home.'/releases/'.$dirs[1].' '.$home.'/current',
133-
'rm -rf '.$home.'/releases/'.$dirs[0],
132+
'ln -sfn ' . $home . '/releases/' . $dirs[1] . ' ' . $home . '/current',
133+
'rm -rf ' . $home . '/releases/' . $dirs[0],
134134
]);
135135

136-
verbose("\t".'Hold my beer, We\'re rolling back');
136+
verbose("\t" . 'Hold my beer, We\'re rolling back');
137137
$connection->task('preformRollback');
138138

139139
unset($dirs[0]);
@@ -147,20 +147,29 @@ public static function doRollback(Connection $connection, $stage, $ldh, $dirs)
147147
return $ldhs;
148148
}
149149

150-
public static function doPatch(Connection $connection, $stage, $branch)
150+
/**
151+
* @param $stage
152+
* @param $branch
153+
*/
154+
public static function doPatch($stage, $branch)
151155
{
152156
$home = config('laravel-deploy-helper.stages.' . $stage . '.remote.root');
153157

154-
dd(Command::builder('git',
155-
['apply', '--reject', '--whitespace=fix', '--directory=' . $home . '/patches/*.patch']));
158+
// setup ssh connection to remote
159+
$connection = SSH::instance()->into($stage);
156160

157161
$connection->define('preformPatch', [
158162
Command::builder('cd', [$home . '/current']),
159163
Command::builder('ls', ['-haml']),
164+
165+
Command::builder('git', ['config', 'user.email', 'git+LDH@localhost.ext']),
166+
Command::builder('git', ['config', 'user.name', 'LDH']),
167+
160168
Command::builder('git', ['fetch']),
161-
Command::builder('git', ['format-patch', 'origin/' . $branch, 'FETCH_HEAD', '-o', $home . '/patches']),
162169
Command::builder('git',
163-
['apply', '--reject', '--whitespace=fix', '--directory=' . $home . '/patches/*.patch']),
170+
['format-patch', '-1', 'origin/' . $branch, 'FETCH_HEAD', '-o', $home . '/patches']),
171+
'git apply --reject --whitespace=fix ' . $home . '/patches/*',
172+
Command::builder('rm', ['-rf', $home . '/patches'])
164173
]);
165174

166175
verbose("\t" . 'Hold on tight, trying to patch!');

src/Helpers/SSH.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static function instance()
2222
*/
2323
public static function home($stage)
2424
{
25-
return config('laravel-deploy-helper.stages.'.$stage.'.remote.root');
25+
return config('laravel-deploy-helper.stages.' . $stage . '.remote.root');
2626
}
2727

2828
public static function checkAppVersion(Connection $connection, $app, $requestedVersion)
@@ -68,7 +68,7 @@ public static function checkAppVersion(Connection $connection, $app, $requestedV
6868
if ($requestedVersion === true) {
6969
$connection->run(Command::builder($app, []), function ($response) use ($app) {
7070
if (stripos($response, 'command not found') !== false) {
71-
throw new \Exception('ERROR: '.$app.' is not installed on the server.');
71+
throw new \Exception('ERROR: ' . $app . ' is not installed on the server.');
7272
}
7373
});
7474
verbose("\t => Checking $app is available");
@@ -81,7 +81,7 @@ public static function checkAppVersion(Connection $connection, $app, $requestedV
8181
*/
8282
$connection->run(Command::builder($app, []), function ($response) use ($app) {
8383
if (stripos($response, 'command not found') !== false) {
84-
throw new \Exception('ERROR: '.$app.' is not installed on the server.');
84+
throw new \Exception('ERROR: ' . $app . ' is not installed on the server.');
8585
}
8686
});
8787

0 commit comments

Comments
 (0)