Skip to content

Commit

Permalink
Merge pull request #1 from kg-bot/local
Browse files Browse the repository at this point in the history
Local
  • Loading branch information
kg-bot authored Jun 11, 2018
2 parents 07feea9 + 8c9610e commit f0244ab
Show file tree
Hide file tree
Showing 42 changed files with 2,155 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/vendor
/node_modules
composer.phar
composer.lock
package-lock.json
.DS_Store
.idea
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,30 @@ Link to create new webhook should be [https://bitbucket.org/:USERNAME:/:REPO:/ad

It looks like this ![BitBucket Webhook Create](https://i.imgur.com/5Zw4Obl.png), Title can be anything, URL should be same as in GitHub settings, you must check Active and you can check Skip certificate verification for now (until next versions)

## Front-end requirements and installation

Front part of this package works as Vue.js SPA and it heavily depends on npm packages

````
npm install bootstrap-vue vue-resource vue-router vue-toasted vue-awesome lang.js lodash change-case datejs
```
Then you have to export assets from this package, this will add some JavaScript and SASS files inside your resources/assets/vendor/laravel-deploy directory
```
php artisan vendor:publish --provider=KgBot\\LaravelDeploy\\LaravelDeployServiceProvider --tag=assets
```
After this you have to alter webpack.mix.js and add this at the end of file
```
/**
* Laravel deploy assets
*/
mix.js( 'resources/assets/vendor/laravel-deploy/js/laravel-deploy.js', 'public/assets/js' )
.sass( 'resources/assets/vendor/laravel-deploy/sass/laravel-deploy.scss', 'public/assets/css' );
```
You can now go to `http://localhost/laravel-deploy/dashboard` or any other URL if you have changed route prefix, just add `/dashboard` at the end.
## Proposals, comments, feedback
Everything of this is highly welcome and appreciated
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"description": "Laravel package used to automatically deploy code from GIT version controls",
"require": {
"php": ">=7.1",
"ddtraceweb/monolog-parser": "^1.2",
"kg-bot/laravel-localization-to-vue": "1.*",
"laravel/framework": "5.*"
},
"keywords": [
Expand Down
37 changes: 37 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"private": true,
"devDependencies": {
"axios": "^0.17",
"bootstrap": "^4.0.0",
"cross-env": "^5.1",
"css-loader": "^0.28.10",
"jquery": "^3.2",
"laravel-localization-loader": "^1.0.5",
"laravel-mix": "^2.0",
"lodash": "^4.17.4",
"popper.js": "^1.12",
"style-loader": "^0.20.2",
"vue": "^2.5.7"
},
"dependencies": {
"ajv": "^6.5.0",
"bootstrap-vue": "^2.0.0-rc.1",
"change-case": "^3.0.2",
"datejs": "^1.0.0-rc3",
"fs": "0.0.1-security",
"glob": "^7.1.2",
"lang.js": "^1.1.12",
"path": "^0.12.7",
"require-dir": "^1.0.0",
"require.all": "^2.0.4",
"vee-validate": "^2.0.5",
"vue-awesome": "^3.0.2",
"vue-multiselect": "^2.1.0",
"vue-resource": "^1.5.0",
"vue-router": "^3.0.1",
"vue-spinner": "^1.0.3",
"vue-toasted": "^1.1.24",
"vue2-dropzone": "^3.1.0",
"vuejs-datepicker": "^0.9.29"
}
}
58 changes: 58 additions & 0 deletions routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,61 @@

Route::any( 'deploy', 'DeployController@request' )->name( 'laravel-deploy.deploy.request' );
} );

/**
* Front-end routes
*/
Route::group( [

'prefix' => config( 'laravel-deploy.routes.prefix' ) . '/dashboard',
'middleware' => array_merge( [ 'web', 'auth' ], config( 'laravel-deploy.front.routes.middleware' ) ),
'namespace' => config( 'laravel-deploy.front.routes.namespace' ),
], function () {

Route::get( '', 'DashboardController@index' )->name( 'laravel-deploy.dashboard' );
} );

/**
* Ajax routes
*/
Route::group( [

'prefix' => config( 'laravel-deploy.routes.prefix' ) . '/ajax',
'middleware' => array_merge( [ 'web' ], config( 'laravel-deploy.front.routes.ajax.middleware' ) ),
'namespace' => config( 'laravel-deploy.front.routes.ajax.namespace' ),
], function () {

Route::post( '/clients/{client}/status', 'ClientsController@changeStatus' )
->name( 'laravel-deploy.ajax.clients.status' );

Route::post( '/clients/{client}/auto-deploy', 'ClientsController@changeAutoDeploy' )
->name( 'laravel-deploy.ajax.clients.auto_deploy' );

Route::resource( '/clients', 'ClientsController', [

'only' => [ 'index', 'store', 'update', 'destroy' ],
'names' => [

'index' => 'laravel-deploy.ajax.clients.index',
'store' => 'laravel-deploy.ajax.clients.store',
'update' => 'laravel-deploy.ajax.clients.update',
'destroy' => 'laravel-deploy.ajax.clients.destroy',
],
] );

/**
* Settings routes
*/
Route::group( [ 'prefix' => 'settings' ], function () {

Route::get( 'last-log', 'SettingsController@lastLog' )->name( 'laravel-deploy.ajax.settings.last_log' );
Route::get( 'logs', 'SettingsController@allLogs' )->name( 'laravel-deploy.ajax.settings.logs' );
Route::get( 'index', 'SettingsController@index' )->name( 'laravel-deploy.ajax.settings.index' );

/**
* Deployments routes
*/
Route::post( 'deploy/now/{client}', 'SettingsController@deployNow' )
->name( 'laravel-deploy.ajax.settings.deployments.deploy_now' );
} );
} );
6 changes: 3 additions & 3 deletions src/Console/Commands/NewClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


use Illuminate\Console\Command;
use KgBot\LaravelDeploy\Models\DeploySource;
use KgBot\LaravelDeploy\Models\Client;

class NewClient extends Command
{
Expand Down Expand Up @@ -47,11 +47,11 @@ public function handle()
{

$name = $this->argument( 'name' );
$token = bcrypt( $this->argument( 'token' ) );
$token = $this->argument( 'token' );
$script_source = $this->argument( 'script_source' );
$source = $this->argument( 'source' );

$client = DeploySource::create( compact( 'name', 'token', 'script_source', 'source' ) );
$client = Client::create( compact( 'name', 'token', 'script_source', 'source' ) );

$this->info( 'New client created, token has been encrypted and it is: ' . $token );
}
Expand Down
45 changes: 45 additions & 0 deletions src/Events/LaravelDeployFailed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Created by PhpStorm.
* User: kgbot
* Date: 6/4/18
* Time: 1:18 AM
*/

namespace KgBot\LaravelDeploy\Events;


use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use KgBot\LaravelDeploy\Models\Client;

class LaravelDeployFailed
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $client;
public $message;

/**
* Create a new event instance.
*
* @return void
*/
public function __construct( Client $client, string $message )
{
$this->client = $client;
$this->message = $message;
}

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel( config( 'laravel-deploy.events.channel', 'channel-name' ) );
}
}
8 changes: 5 additions & 3 deletions src/Events/LaravelDeployFinished.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use KgBot\LaravelDeploy\Models\DeploySource;
use KgBot\LaravelDeploy\Models\Client;

class LaravelDeployFinished
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $client;
public $message;

/**
* Create a new event instance.
*
* @return void
*/
public function __construct( DeploySource $client )
public function __construct( Client $client, $message )
{
$this->client = $client;
$this->client = $client;
$this->message = $message;
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Events/LaravelDeployStarted.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use KgBot\LaravelDeploy\Models\DeploySource;
use KgBot\LaravelDeploy\Models\Client;

class LaravelDeployStarted
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $client;
public $command;

/**
* Create a new event instance.
*
* @return void
*/
public function __construct( DeploySource $client )
public function __construct( Client $client, string $command )
{
$this->client = $client;
$this->client = $client;
$this->command = $command;
}

/**
Expand Down
26 changes: 12 additions & 14 deletions src/Http/Controllers/DeployController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,30 @@
use Illuminate\Http\Request;
use KgBot\LaravelDeploy\Exceptions\UnableToReadScriptFile;
use KgBot\LaravelDeploy\Jobs\DeployJob;
use KgBot\LaravelDeploy\Models\DeploySource;
use KgBot\LaravelDeploy\Models\Client;

class DeployController extends BaseController
{
public function request( Request $request )
{
if ( config( 'laravel-deploy.run_deploy' ) ) {
$client = Client::where( [

$client = DeploySource::where( [
[ 'token', $request->get( '_token' ) ],
[ 'active', true ],
[ 'auto_deploy' => true ],
] )->first();

[ 'token', $request->get( '_token' ) ],
[ 'active', true ],
] )->first();
$filename = $client->script_source;
$script_file = base_path( $filename );

$filename = $client->script_source;
$script_file = base_path( $filename );
if ( !file_exists( $script_file ) ) {

if ( !file_exists( $script_file ) ) {
throw new UnableToReadScriptFile();

throw new UnableToReadScriptFile();

}

dispatch( new DeployJob( $client, $script_file ) )->onQueue( config( 'laravel-deploy.queue', 'default' ) );
}

dispatch( new DeployJob( $client, $script_file ) )->onQueue( config( 'laravel-deploy.queue', 'default' ) );

return response()->json( 'success' );
}
}
Loading

0 comments on commit f0244ab

Please sign in to comment.