Skip to content

Commit f5e4a94

Browse files
committed
first
0 parents  commit f5e4a94

File tree

520 files changed

+42715
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

520 files changed

+42715
-0
lines changed

.env.example

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
APP_ENV=local
2+
APP_KEY=
3+
APP_DEBUG=true
4+
APP_LOG_LEVEL=debug
5+
APP_URL=http://localhost
6+
7+
DB_CONNECTION=mysql
8+
DB_HOST=127.0.0.1
9+
DB_PORT=3306
10+
DB_DATABASE=homestead
11+
DB_USERNAME=homestead
12+
DB_PASSWORD=secret
13+
14+
BROADCAST_DRIVER=log
15+
CACHE_DRIVER=file
16+
SESSION_DRIVER=file
17+
QUEUE_DRIVER=sync
18+
19+
REDIS_HOST=127.0.0.1
20+
REDIS_PASSWORD=null
21+
REDIS_PORT=6379
22+
23+
MAIL_DRIVER=smtp
24+
MAIL_HOST=smtp.mailtrap.io
25+
MAIL_PORT=2525
26+
MAIL_USERNAME=null
27+
MAIL_PASSWORD=null
28+
MAIL_ENCRYPTION=null
29+
30+
PUSHER_APP_ID=
31+
PUSHER_APP_KEY=
32+
PUSHER_APP_SECRET=

.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
* text=auto
2+
*.css linguist-vendored
3+
*.scss linguist-vendored
4+
*.js linguist-vendored
5+
CHANGELOG.md export-ignore

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/node_modules
2+
/public/storage
3+
/public/hot
4+
/storage/*.key
5+
/vendor
6+
/.idea
7+
/.vagrant
8+
Homestead.json
9+
Homestead.yaml
10+
.env

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.PHONY: test share
2+
3+
test:
4+
php vendor/bin/phpunit
5+
6+
share:
7+
ngrok http "cloud.dev:80" -subdomain=laravel-cloud -host-header=rewrite
8+
9+
fresh:
10+
php artisan migrate:fresh
11+
php artisan passport:install --force
12+
rm storage/app/keys/*
13+
14+
default: test

app/Alert.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class Alert extends Model
8+
{
9+
/**
10+
* The attributes that should be cast to native types.
11+
*
12+
* @var array
13+
*/
14+
protected $casts = [
15+
'meta' => 'json',
16+
];
17+
18+
/**
19+
* The attributes that aren't mass assignable.
20+
*
21+
* @var array
22+
*/
23+
protected $guarded = [];
24+
25+
/**
26+
* The attributes that should be hidden for arrays.
27+
*
28+
* @var array
29+
*/
30+
protected $hidden = [
31+
'exception',
32+
];
33+
34+
/**
35+
* The event map for the model.
36+
*
37+
* Allows for object-based events for native Eloquent events.
38+
*
39+
* @var array
40+
*/
41+
protected $dispatchesEvents = [
42+
'created' => Events\AlertCreated::class,
43+
];
44+
45+
/**
46+
* Get the project that the alert belongs to.
47+
*/
48+
public function project()
49+
{
50+
return $this->belongsTo(Project::class, 'project_id');
51+
}
52+
}

app/AppServer.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Carbon\Carbon;
6+
use App\Jobs\ProvisionAppServer;
7+
8+
class AppServer extends HttpServer
9+
{
10+
/**
11+
* Determine if this server will run a given deployment command.
12+
*
13+
* @param string $command
14+
* @return bool
15+
*/
16+
public function runsCommand($command)
17+
{
18+
return true;
19+
}
20+
21+
/**
22+
* Determine if this server is the "master" server for the stack.
23+
*
24+
* @return bool
25+
*/
26+
public function isMaster()
27+
{
28+
return $this->is($this->stack->masterServer());
29+
}
30+
31+
/**
32+
* Determine if this server processes queued jobs.
33+
*
34+
* @return bool
35+
*/
36+
public function isWorker()
37+
{
38+
return true;
39+
}
40+
41+
/**
42+
* Determine if this server is the "master" worker for the stack.
43+
*
44+
* @return bool
45+
*/
46+
public function isMasterWorker()
47+
{
48+
return $this->is($this->stack->masterWorker());
49+
}
50+
51+
/**
52+
* Dispatch the job to provision the server.
53+
*
54+
* @return void
55+
*/
56+
public function provision()
57+
{
58+
ProvisionAppServer::dispatch($this);
59+
60+
$this->update(['provisioning_job_dispatched_at' => Carbon::now()]);
61+
}
62+
63+
/**
64+
* Get the provisioning script for the server.
65+
*
66+
* @return \App\Scripts\Script
67+
*/
68+
public function provisioningScript()
69+
{
70+
return new Scripts\ProvisionAppServer($this);
71+
}
72+
}

app/AppServerRecordCreator.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace App;
4+
5+
class AppServerRecordCreator extends ServerRecordCreator
6+
{
7+
/**
8+
* The server type.
9+
*
10+
* @var string
11+
*/
12+
protected $type = 'app';
13+
14+
/**
15+
* Get the relationship for the server type.
16+
*
17+
* @return \Illuminate\Database\Eloquent\Relations\Relation
18+
*/
19+
public function relation()
20+
{
21+
return $this->stack->appServers();
22+
}
23+
24+
/**
25+
* Get the custom attributes for the servers.
26+
*
27+
* @return array
28+
*/
29+
protected function attributes()
30+
{
31+
return [
32+
'database_username' => 'cloud',
33+
'database_password' => str_random(40),
34+
];
35+
}
36+
}

app/Balancer.php

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Carbon\Carbon;
6+
use App\Jobs\SyncBalancer;
7+
use App\Callbacks\Dispatch;
8+
use App\Jobs\ProvisionBalancer;
9+
use App\Jobs\UpdateStackDnsRecords;
10+
use App\Jobs\DeleteServerOnProvider;
11+
use App\Callbacks\MarkAsProvisioned;
12+
use Illuminate\Database\Eloquent\Model;
13+
use App\Scripts\SyncBalancer as SyncBalancerScript;
14+
use App\Contracts\Provisionable as ProvisionableContract;
15+
16+
class Balancer extends Model implements ProvisionableContract
17+
{
18+
use Provisionable;
19+
20+
/**
21+
* The attributes that should be cast to native types.
22+
*
23+
* @var array
24+
*/
25+
protected $casts = [
26+
'self_signs' => 'boolean',
27+
];
28+
29+
/**
30+
* The attributes that aren't mass assignable.
31+
*
32+
* @var array
33+
*/
34+
protected $guarded = [];
35+
36+
/**
37+
* The attributes that should be hidden for arrays.
38+
*
39+
* @var array
40+
*/
41+
protected $hidden = [
42+
'private_key', 'sudo_password',
43+
];
44+
45+
/**
46+
* Determine if the given user can SSH into the balancer.
47+
*
48+
* @param \App\User $user
49+
* @return bool
50+
*/
51+
public function canSsh(User $user)
52+
{
53+
return $user->canAccessProject($this->project);
54+
}
55+
56+
/**
57+
* Sync the balancer's configuration with the current stacks.
58+
*
59+
* @param int $delay
60+
* @return void
61+
*/
62+
public function sync($delay = 0)
63+
{
64+
Jobs\SyncBalancer::dispatch($this)->delay($delay);
65+
}
66+
67+
/**
68+
* Sync the balancer's configuration with the current stacks.
69+
*
70+
* @return \App\Task
71+
*/
72+
public function syncNow()
73+
{
74+
return $this->run(new SyncBalancerScript($this));
75+
}
76+
77+
/**
78+
* Determine if the balancer should self-sign TLS certificates.
79+
*
80+
* @return bool
81+
*/
82+
public function selfSignsCertificates()
83+
{
84+
return $this->tls === 'self-signed';
85+
}
86+
87+
/**
88+
* Dispatch the job to provision the balancer.
89+
*
90+
* @return void
91+
*/
92+
public function provision()
93+
{
94+
ProvisionBalancer::dispatch($this);
95+
96+
$this->update(['provisioning_job_dispatched_at' => Carbon::now()]);
97+
}
98+
99+
/**
100+
* Run the provisioning script on the balancer.
101+
*
102+
* @return \App\Task|null
103+
*/
104+
public function runProvisioningScript()
105+
{
106+
if ($this->isProvisioning()) {
107+
return;
108+
}
109+
110+
$this->markAsProvisioning();
111+
112+
return $this->runInBackground(new Scripts\ProvisionBalancer($this), [
113+
'then' => [
114+
MarkAsProvisioned::class,
115+
new Dispatch(SyncBalancer::class)
116+
],
117+
]);
118+
}
119+
120+
/**
121+
* Delete the model from the database.
122+
*
123+
* @return bool|null
124+
*
125+
* @throws \Exception
126+
*/
127+
public function delete()
128+
{
129+
if ($this->address) {
130+
UpdateStackDnsRecords::dispatch(
131+
$this->project, $this->address->public_address
132+
);
133+
}
134+
135+
DeleteServerOnProvider::dispatch(
136+
$this->project, $this->providerServerId()
137+
);
138+
139+
$this->address()->delete();
140+
$this->tasks()->delete();
141+
142+
parent::delete();
143+
}
144+
}

0 commit comments

Comments
 (0)