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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RamonSmit committed Jul 12, 2017
2 parents 78d914f + 7dd4b95 commit f004bd6
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
[![Made by DALTCORE](https://img.shields.io/badge/MADE%20BY-DALTCORE-green.svg?style=flat-square)](https://github.com/DALTCORE)


Compatible with Laravel 5.4 and higher.
Compatible with Laravel [5.1](https://github.com/DALTCORE/laravel-deploy-helper/tree/5.1), 5.4 and higher.

**For Laravel 5.1 use branch 5.1 and tag v0.5.x**

LDH is a Laravel package that helps with deploying your website without the usage of FTP.
The LDH packages uses SSH to build a deployment environment on the server for zero-downtime deployments
and rollback functionality.

**Everyone is allowed to help getting this package bigger and better! ;-)**

## Install

Via Composer
Expand All @@ -34,19 +38,19 @@ $ php artisan vendor:publish --tag=ldh-config

## Usage

*Deploy to server*
*Deploy to server*
Deploy full instance to the remote server
```bash
php artisan ldh:deploy --stage=production --branch=develop
```

*Patch to server*
*Patch to server*
Push a simple patch to the remote server (minor changes only)
```bash
php artisan ldh:patch --stage=production --branch=patch
```

*Rollback one instance*
*Rollback one instance*
Something went horrably wrong, go back in history
```bash
php artisan ldh:rollback --stage=production
Expand Down Expand Up @@ -142,13 +146,13 @@ return [
LDH deploys the following directory structure on first deploy
```text
.
├── current -> /var/www/vhosts/example.org/releases/1496845077
├── current -> /var/www/vhosts/example.org/releases/1498833243
├── ldh.json
├── patches
│   └── 0001-Update-readme.md.patch
├── releases
│   ├── 1496843891
│   └── 1496845077
│   └── 1498833243
└── shared
```

As you can see, LDH makes a static link from `/current` to `/releases/1496845077`.
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Commands/Deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function handle()
// Write to config
SSH::instance()
->into($this->option('stage'))
->putString(SSH::home($this->option('stage')) . '/ldh.json', json_encode($this->ldh));
->putString(SSH::home($this->option('stage')).'/ldh.json', json_encode($this->ldh));

// Done
SSH::performLanding($this->option('stage'));
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Commands/Rollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function handle()
// Write to config
SSH::instance()
->into($this->option('stage'))
->putString(SSH::home($this->option('stage')) . '/ldh.json', json_encode($this->ldh));
->putString(SSH::home($this->option('stage')).'/ldh.json', json_encode($this->ldh));

SSH::performLanding($this->option('stage'));
}
Expand Down
43 changes: 22 additions & 21 deletions src/Helpers/SSH.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static function instance()
*/
public static function home($stage)
{
return config('laravel-deploy-helper.stages.' . $stage . '.remote.root');
return config('laravel-deploy-helper.stages.'.$stage.'.remote.root');
}

public static function checkAppVersion(Connection $connection, $app, $requestedVersion)
Expand Down Expand Up @@ -68,7 +68,7 @@ public static function checkAppVersion(Connection $connection, $app, $requestedV
if ($requestedVersion === true) {
$connection->run(Command::builder($app, []), function ($response) use ($app) {
if (stripos($response, 'command not found') !== false) {
throw new \Exception('ERROR: ' . $app . ' is not installed on the server.');
throw new \Exception('ERROR: '.$app.' is not installed on the server.');
}
});
verbose("\t => Checking $app is available");
Expand All @@ -81,7 +81,7 @@ public static function checkAppVersion(Connection $connection, $app, $requestedV
*/
$connection->run(Command::builder($app, []), function ($response) use ($app) {
if (stripos($response, 'command not found') !== false) {
throw new \Exception('ERROR: ' . $app . ' is not installed on the server.');
throw new \Exception('ERROR: '.$app.' is not installed on the server.');
}
});

Expand All @@ -104,14 +104,15 @@ public static function execute($stage, $commands)
}

/**
* Pre flight checks before the deploy happens
* Pre flight checks before the deploy happens.
*
* @param $instance
* @param $stage
* @param $branch
*
* @return bool|mixed
* @throws \Exception
*
* @return bool|mixed
*/
public static function preFlight($instance, $stage, $branch = false)
{
Expand All @@ -121,9 +122,9 @@ public static function preFlight($instance, $stage, $branch = false)
if ($stage === null) {
throw new \Exception('The argument "--stage=" is required!', 128);
} else {
if (!is_array(config('laravel-deploy-helper.stages.' . $stage))) {
throw new \Exception('The stage "' . $stage
. '" does not exist!', 128);
if (!is_array(config('laravel-deploy-helper.stages.'.$stage))) {
throw new \Exception('The stage "'.$stage
.'" does not exist!', 128);
}
}

Expand All @@ -133,14 +134,14 @@ public static function preFlight($instance, $stage, $branch = false)
}

if (in_array($branch, Git::getBranches()) == false) {
throw new \Exception('The branch "' . $branch
. '" does not exists locally? Please `git pull`!', 128);
throw new \Exception('The branch "'.$branch
.'" does not exists locally? Please `git pull`!', 128);
}
}

// Connecting to remote server
verbose('[' . $stage . '] Trying to login into remote SSH');
$ssh = SSH::instance()->into($stage);
verbose('['.$stage.'] Trying to login into remote SSH');
$ssh = self::instance()->into($stage);

// Check for lockfile
if (Locker::lock($ssh, $stage) === false) {
Expand All @@ -149,22 +150,22 @@ public static function preFlight($instance, $stage, $branch = false)
}

// Trying to read file
verbose('[' . $stage . '] Reading config file from remote server');
$config = $ssh->exists(SSH::home($stage) . '/ldh.json');
verbose('['.$stage.'] Reading config file from remote server');
$config = $ssh->exists(self::home($stage).'/ldh.json');

// Check if config exists
if ($config == false) {
error('[' . $stage . '] ldh.json does not exists.');
error('['.$stage.'] ldh.json does not exists.');
if ($instance->confirm('Do you want to initialize LDH here?')) {
Deployer::freshInit($ssh, $stage);
} else {
return false;
}
} else {
verbose('[' . $stage . '] Found config. Checking directories.');
$config = $ssh->getString(SSH::home($stage) . '/ldh.json');
verbose('['.$stage.'] Found config. Checking directories.');
$config = $ssh->getString(self::home($stage).'/ldh.json');
if ($config == false) {
error('[' . $stage . '] Config file is empty... Something is wrong.');
error('['.$stage.'] Config file is empty... Something is wrong.');

return false;
}
Expand All @@ -174,14 +175,14 @@ public static function preFlight($instance, $stage, $branch = false)
}

/**
* End of command
* End of command.
*
* @param $stage
*/
public static function performLanding($stage)
{
$ssh = SSH::instance()->into($stage);
$ssh = self::instance()->into($stage);
Locker::unlock($ssh, $stage);
verbose('[' . $stage . '] Changes are successfull!');
verbose('['.$stage.'] Changes are successfull!');
}
}
4 changes: 2 additions & 2 deletions src/Helpers/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function verbose($message)
{
$console = new ConsoleOutput();
$console->getFormatter()->setStyle('info', new OutputFormatterStyle('blue', null));
$console->writeln('<info>' . $message . '</info>');
$console->writeln('<info>'.$message.'</info>');
}
}

Expand All @@ -31,7 +31,7 @@ function error($message)
{
$console = new ConsoleOutput();
$console->getFormatter()->setStyle('error', new OutputFormatterStyle('white', 'red'));
$console->writeln('<error>' . $message . '</error>');
$console->writeln('<error>'.$message.'</error>');
}
}

Expand Down

0 comments on commit f004bd6

Please sign in to comment.