Skip to content

Commit

Permalink
Merge branch 'release/1.2.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
ben182 committed Sep 11, 2018
2 parents ed19f1c + 75b4ba7 commit 3247d49
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 32 deletions.
4 changes: 3 additions & 1 deletion app/Console/Commands/GitAutoDeployAddCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GitAutoDeployAddCommand extends ModCommand
*
* @var string
*/
protected $signature = 'gad:add {--dir=}';
protected $signature = 'gad:add {--dir=} {--branch=}';

/**
* The console command description.
Expand Down Expand Up @@ -42,9 +42,11 @@ public function handle()
parent::handle();

$sDir = $this->stringOption('dir', 'Path (from /var/www/)?');
$sBranch = $this->stringOption('branch', 'Branch?');

(new GitAutoDeployTaskManager([
'dir' => "/var/www/$sDir",
'branch' => $sBranch,
]))->work();
}
}
9 changes: 8 additions & 1 deletion app/Console/Commands/InstallationFinishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function handle()

(new CreateDeamonTaskManager([
'name' => 'stool-deploy',
'command' => 'stool queue:work --tries=1',
'command' => 'stool queue:listen --timeout=600 --sleep=15 --tries=1',
]))->work();

$sEmail = $this->ask('Administrator email?');
Expand All @@ -52,5 +52,12 @@ public function handle()
'key' => 'admin_email',
'value' => $sEmail,
]);

$bAddSwap = $this->confirm('Add Swap Space?');
if ($bAddSwap) {
$iSwap = (int) $this->ask('How much (in GB)?');

resolve('ShellTask')->exec('bash ' . scripts_path('partials') . '/swap.sh ' . $iSwap . 'G');
}
}
}
1 change: 1 addition & 0 deletions app/Console/Commands/Tasks/ApplicationInstall/Gad.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function handle()
{
(new GitAutoDeployTaskManager([
'dir' => $this->bindings->installationDir,
'branch' => $this->oOptions->branch,
]))->work();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function handle()
{
$oRepository = Repository::create([
'dir' => $this->oOptions->dir,
'branch' => $this->oOptions->branch,
]);

copy(templates_path('git/deploy_stool.sh'), $this->oOptions->dir . '/deploy_stool.sh');
Expand Down
1 change: 1 addition & 0 deletions app/Console/Commands/Tasks/GitAutoDeployTaskManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function validate()
'required',
new FileExists
],
'branch' => 'required',
];
}
}
24 changes: 22 additions & 2 deletions app/Http/Controllers/RepositoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,32 @@ public function index(Repository $oRepository)
abort(404);
}

$postBody = file_get_contents('php://input');
switch ($_SERVER['CONTENT_TYPE']) {
case 'application/json':
$postBody = file_get_contents('php://input');
break;
case 'application/x-www-form-urlencoded':
$postBody = $_POST['payload'];
break;
default:
throw new \Exception("Unsupported content type: {$_SERVER['CONTENT_TYPE']}");
}
$oPostBody = json_decode($postBody);

if ('sha1=' . hash_hmac('sha1', $postBody, $oRepository->secret) !== $_SERVER['HTTP_X_HUB_SIGNATURE']) {
if ('sha1=' . hash_hmac('sha1', file_get_contents('php://input'), $oRepository->secret) !== $_SERVER['HTTP_X_HUB_SIGNATURE']) {
return response('Wrong Secret', 500);
}

$oPostBody->ref = $oPostBody->ref ?? 'refs/heads/master';

if (! str_contains($oPostBody->ref, 'refs/heads/')) {
return 'Not Head';
}

if (str_replace('refs/heads/', '', $oPostBody->ref) !== $oRepository->branch) {
return 'Wrong Branch';
}

putenv("COMPOSER_HOME=/var/www/.composer");

Deploy::dispatch($oRepository);
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function handle()

Archive::make($sBackupPath, $this->repository->dir);

$sCommand = 'cd ' . $this->repository->dir . ' && bash -e deploy_stool.sh 2>&1';
$sCommand = 'cd ' . $this->repository->dir . ' && bash deploy_stool.sh 2>&1';

exec($sCommand, $aOutput, $iExit);

Expand Down
6 changes: 5 additions & 1 deletion app/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ class Repository extends Model
{
use HasHashSlug;

protected $fillable = ['dir', 'secret'];
protected $fillable = [
'dir',
'branch',
'secret',
];

public function _setSecret()
{
Expand Down
32 changes: 16 additions & 16 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
'retry_after' => 3600,
],

'beanstalkd' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function up()
Schema::create('repositories', function (Blueprint $table) {
$table->increments('id');
$table->string('dir');
$table->string('branch');
$table->string('secret');
$table->timestamps();
});
Expand Down
2 changes: 1 addition & 1 deletion scripts/partials/node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ nodeInstall () {

nvm install node
nvm use node
# n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local
n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local
}
echo "Installing Node JS..."
nodeInstall &> /dev/null
47 changes: 47 additions & 0 deletions scripts/partials/swap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh

# Do argument checks
if [ ! "$#" -ge 1 ]; then
echo "Usage: $0 {size}"
echo "Example: $0 4G"
echo "(Default path: /swapfile)"
echo "Optional path: Usage: $0 {size} {path}"
exit 1
fi


## Intro
echo "Welcome to Swap setup script! This script will automatically setup a swap file and enable it."
echo "Root access is required, please run as root or enter sudo password."
echo "Source is @ https://github.com/Cretezy/Swap"
echo

## Setup variables

# Get size from first argument
SWAP_SIZE=$1

# Get path from second argument (default to /swapfile)
SWAP_PATH="/swapfile"
if [ ! -z "$2" ]; then
SWAP_PATH=$2
fi


## Run
sudo fallocate -l $SWAP_SIZE $SWAP_PATH # Allocate size
sudo chmod 600 $SWAP_PATH # Set proper permission
sudo mkswap $SWAP_PATH # Setup swap
sudo swapon $SWAP_PATH # Enable swap
echo "$SWAP_PATH none swap sw 0 0" | sudo tee /etc/fstab -a # Add to fstab

sudo sysctl vm.swappiness=10
sudo sysctl vm.vfs_cache_pressure=50

echo "vm.swappiness = 10" >> /etc/sysctl.conf
echo "vm.vfs_cache_pressure = 50" >> /etc/sysctl.conf

## Outro

echo
echo "Done! You now have a $SWAP_SIZE swap file at $SWAP_PATH"
8 changes: 4 additions & 4 deletions templates/git/deploy_stool.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash

git pull
composer install --no-interaction --prefer-dist
# composer install --no-interaction --prefer-dist

# php artisan cache:clear
# php artisan config:clear
# php artisan route:clear
# php artisan config:clear
# php artisan route:clear
# php artisan view:clear
# supervisorctl restart name
# supervisorctl restart name
8 changes: 4 additions & 4 deletions templates/ip/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
<title>stool welcome page</title>

<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Ubuntu:300,700" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Oxygen:300,700" rel="stylesheet">

<!-- Styles -->
<style>
html, body {
background-color: #fff;
color: #636b6f;
font-family: 'Ubuntu', sans-serif;
font-family: 'Oxygen', sans-serif;
font-weight: 300;
height: 100vh;
margin: 0;
Expand Down Expand Up @@ -51,7 +51,7 @@
.links > a {
color: #636b6f;
padding: 0 25px;
font-size: 12px;
font-size: 14px;
font-weight: 700;
letter-spacing: .1rem;
text-decoration: none;
Expand All @@ -77,4 +77,4 @@
</div>
</div>
</body>
</html>
</html>

0 comments on commit 3247d49

Please sign in to comment.