forked from rodrigopedra/laravel-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f5e4a94
Showing
520 changed files
with
42,715 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
APP_ENV=local | ||
APP_KEY= | ||
APP_DEBUG=true | ||
APP_LOG_LEVEL=debug | ||
APP_URL=http://localhost | ||
|
||
DB_CONNECTION=mysql | ||
DB_HOST=127.0.0.1 | ||
DB_PORT=3306 | ||
DB_DATABASE=homestead | ||
DB_USERNAME=homestead | ||
DB_PASSWORD=secret | ||
|
||
BROADCAST_DRIVER=log | ||
CACHE_DRIVER=file | ||
SESSION_DRIVER=file | ||
QUEUE_DRIVER=sync | ||
|
||
REDIS_HOST=127.0.0.1 | ||
REDIS_PASSWORD=null | ||
REDIS_PORT=6379 | ||
|
||
MAIL_DRIVER=smtp | ||
MAIL_HOST=smtp.mailtrap.io | ||
MAIL_PORT=2525 | ||
MAIL_USERNAME=null | ||
MAIL_PASSWORD=null | ||
MAIL_ENCRYPTION=null | ||
|
||
PUSHER_APP_ID= | ||
PUSHER_APP_KEY= | ||
PUSHER_APP_SECRET= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
* text=auto | ||
*.css linguist-vendored | ||
*.scss linguist-vendored | ||
*.js linguist-vendored | ||
CHANGELOG.md export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/node_modules | ||
/public/storage | ||
/public/hot | ||
/storage/*.key | ||
/vendor | ||
/.idea | ||
/.vagrant | ||
Homestead.json | ||
Homestead.yaml | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.PHONY: test share | ||
|
||
test: | ||
php vendor/bin/phpunit | ||
|
||
share: | ||
ngrok http "cloud.dev:80" -subdomain=laravel-cloud -host-header=rewrite | ||
|
||
fresh: | ||
php artisan migrate:fresh | ||
php artisan passport:install --force | ||
rm storage/app/keys/* | ||
|
||
default: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Alert extends Model | ||
{ | ||
/** | ||
* The attributes that should be cast to native types. | ||
* | ||
* @var array | ||
*/ | ||
protected $casts = [ | ||
'meta' => 'json', | ||
]; | ||
|
||
/** | ||
* The attributes that aren't mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $guarded = []; | ||
|
||
/** | ||
* The attributes that should be hidden for arrays. | ||
* | ||
* @var array | ||
*/ | ||
protected $hidden = [ | ||
'exception', | ||
]; | ||
|
||
/** | ||
* The event map for the model. | ||
* | ||
* Allows for object-based events for native Eloquent events. | ||
* | ||
* @var array | ||
*/ | ||
protected $dispatchesEvents = [ | ||
'created' => Events\AlertCreated::class, | ||
]; | ||
|
||
/** | ||
* Get the project that the alert belongs to. | ||
*/ | ||
public function project() | ||
{ | ||
return $this->belongsTo(Project::class, 'project_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Carbon\Carbon; | ||
use App\Jobs\ProvisionAppServer; | ||
|
||
class AppServer extends HttpServer | ||
{ | ||
/** | ||
* Determine if this server will run a given deployment command. | ||
* | ||
* @param string $command | ||
* @return bool | ||
*/ | ||
public function runsCommand($command) | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Determine if this server is the "master" server for the stack. | ||
* | ||
* @return bool | ||
*/ | ||
public function isMaster() | ||
{ | ||
return $this->is($this->stack->masterServer()); | ||
} | ||
|
||
/** | ||
* Determine if this server processes queued jobs. | ||
* | ||
* @return bool | ||
*/ | ||
public function isWorker() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Determine if this server is the "master" worker for the stack. | ||
* | ||
* @return bool | ||
*/ | ||
public function isMasterWorker() | ||
{ | ||
return $this->is($this->stack->masterWorker()); | ||
} | ||
|
||
/** | ||
* Dispatch the job to provision the server. | ||
* | ||
* @return void | ||
*/ | ||
public function provision() | ||
{ | ||
ProvisionAppServer::dispatch($this); | ||
|
||
$this->update(['provisioning_job_dispatched_at' => Carbon::now()]); | ||
} | ||
|
||
/** | ||
* Get the provisioning script for the server. | ||
* | ||
* @return \App\Scripts\Script | ||
*/ | ||
public function provisioningScript() | ||
{ | ||
return new Scripts\ProvisionAppServer($this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
class AppServerRecordCreator extends ServerRecordCreator | ||
{ | ||
/** | ||
* The server type. | ||
* | ||
* @var string | ||
*/ | ||
protected $type = 'app'; | ||
|
||
/** | ||
* Get the relationship for the server type. | ||
* | ||
* @return \Illuminate\Database\Eloquent\Relations\Relation | ||
*/ | ||
public function relation() | ||
{ | ||
return $this->stack->appServers(); | ||
} | ||
|
||
/** | ||
* Get the custom attributes for the servers. | ||
* | ||
* @return array | ||
*/ | ||
protected function attributes() | ||
{ | ||
return [ | ||
'database_username' => 'cloud', | ||
'database_password' => str_random(40), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Carbon\Carbon; | ||
use App\Jobs\SyncBalancer; | ||
use App\Callbacks\Dispatch; | ||
use App\Jobs\ProvisionBalancer; | ||
use App\Jobs\UpdateStackDnsRecords; | ||
use App\Jobs\DeleteServerOnProvider; | ||
use App\Callbacks\MarkAsProvisioned; | ||
use Illuminate\Database\Eloquent\Model; | ||
use App\Scripts\SyncBalancer as SyncBalancerScript; | ||
use App\Contracts\Provisionable as ProvisionableContract; | ||
|
||
class Balancer extends Model implements ProvisionableContract | ||
{ | ||
use Provisionable; | ||
|
||
/** | ||
* The attributes that should be cast to native types. | ||
* | ||
* @var array | ||
*/ | ||
protected $casts = [ | ||
'self_signs' => 'boolean', | ||
]; | ||
|
||
/** | ||
* The attributes that aren't mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $guarded = []; | ||
|
||
/** | ||
* The attributes that should be hidden for arrays. | ||
* | ||
* @var array | ||
*/ | ||
protected $hidden = [ | ||
'private_key', 'sudo_password', | ||
]; | ||
|
||
/** | ||
* Determine if the given user can SSH into the balancer. | ||
* | ||
* @param \App\User $user | ||
* @return bool | ||
*/ | ||
public function canSsh(User $user) | ||
{ | ||
return $user->canAccessProject($this->project); | ||
} | ||
|
||
/** | ||
* Sync the balancer's configuration with the current stacks. | ||
* | ||
* @param int $delay | ||
* @return void | ||
*/ | ||
public function sync($delay = 0) | ||
{ | ||
Jobs\SyncBalancer::dispatch($this)->delay($delay); | ||
} | ||
|
||
/** | ||
* Sync the balancer's configuration with the current stacks. | ||
* | ||
* @return \App\Task | ||
*/ | ||
public function syncNow() | ||
{ | ||
return $this->run(new SyncBalancerScript($this)); | ||
} | ||
|
||
/** | ||
* Determine if the balancer should self-sign TLS certificates. | ||
* | ||
* @return bool | ||
*/ | ||
public function selfSignsCertificates() | ||
{ | ||
return $this->tls === 'self-signed'; | ||
} | ||
|
||
/** | ||
* Dispatch the job to provision the balancer. | ||
* | ||
* @return void | ||
*/ | ||
public function provision() | ||
{ | ||
ProvisionBalancer::dispatch($this); | ||
|
||
$this->update(['provisioning_job_dispatched_at' => Carbon::now()]); | ||
} | ||
|
||
/** | ||
* Run the provisioning script on the balancer. | ||
* | ||
* @return \App\Task|null | ||
*/ | ||
public function runProvisioningScript() | ||
{ | ||
if ($this->isProvisioning()) { | ||
return; | ||
} | ||
|
||
$this->markAsProvisioning(); | ||
|
||
return $this->runInBackground(new Scripts\ProvisionBalancer($this), [ | ||
'then' => [ | ||
MarkAsProvisioned::class, | ||
new Dispatch(SyncBalancer::class) | ||
], | ||
]); | ||
} | ||
|
||
/** | ||
* Delete the model from the database. | ||
* | ||
* @return bool|null | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function delete() | ||
{ | ||
if ($this->address) { | ||
UpdateStackDnsRecords::dispatch( | ||
$this->project, $this->address->public_address | ||
); | ||
} | ||
|
||
DeleteServerOnProvider::dispatch( | ||
$this->project, $this->providerServerId() | ||
); | ||
|
||
$this->address()->delete(); | ||
$this->tasks()->delete(); | ||
|
||
parent::delete(); | ||
} | ||
} |
Oops, something went wrong.