-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSite.php
executable file
·140 lines (121 loc) · 2.92 KB
/
Site.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
namespace App;
use App\Scripts\Site\Deploy;
use App\Jobs\Sites\Deploy as AppDeploy;
class Site extends Model
{
/**
* Fields to be cast to native types
*
* @var array
*/
protected $casts = [
'environment' => 'array',
'push_to_deploy' => 'boolean'
];
/**
* Fields to be hidden from database query results
*
* @var array
*/
protected $hidden = ['deploy_script'];
public function getDeploymentsAttribute()
{
return Activity::forSubject($this)
->where('description', 'Deployment')
->latest()
->paginate();
}
public function balancedServers()
{
return $this->hasMany(BalancedServer::class);
}
public function getLatestDeploymentAttribute()
{
return Activity::forSubject($this)
->where('description', 'Deployment')
->latest()
->first();
}
/**
*
* Build the ssh clone url based on the repository provider
*
* @return string
*/
public function getSshUrl()
{
switch ($this->repository_provider) {
case 'github':
return "[email protected]:{$this->repository}.git";
case 'gitlab':
return "[email protected]:{$this->repository}.git";
default:
return '';
}
}
/**
* A site belongs to a server
*
* @return \Illuminate\Database\Relations\BelongsTo
*/
public function server()
{
return $this->belongsTo(Server::class);
}
public function pm2Processes()
{
return $this->hasMany(Pm2Process::class)->where(
'status',
'!=',
STATUS_DELETING
);
}
public function pm2ProcessesExceptWeb()
{
return $this->pm2Processes()
->where('name', '!=', $this->name)
->get();
}
/**
*
* Get the nexabox site domain for this site
*
* @return string
*/
public function getNexaboxSiteDomain(string $slug = null)
{
$subdomain = $slug ?? $this->slug;
$domain = config('services.digital-ocean.app-domain');
return "{$subdomain}.{$domain}";
}
public function triggerDeployment()
{
$this->update([
'deploying' => true
]);
$deployment = activity()
->causedBy(auth()->user())
->performedOn($this)
->withProperty('log', '')
->withProperty('status', 'pending')
->log('Deployment');
AppDeploy::dispatch($this->server, $this, $deployment);
}
/**
* Roll job slug
*
*
*/
public function rollSlug()
{
do {
$this->slug = str_random(8);
} while ($this->where('slug', $this->slug)->exists());
$this->save();
}
public function toTinyArray()
{
return [];
}
}