This commit is contained in:
Joao Patricio 2023-03-30 20:24:43 +01:00
parent f05ab87c08
commit a852a15dab
6 changed files with 53 additions and 19 deletions

View File

@ -51,17 +51,21 @@ protected static function boot()
$model->uuid = (string) new Cuid2(7); $model->uuid = (string) new Cuid2(7);
}); });
} }
public function teams() public function teams()
{ {
return $this->belongsToMany(Team::class); return $this->belongsToMany(Team::class);
} }
public function currentTeam() public function currentTeam()
{ {
return $this->belongsTo(Team::class); return $this->belongsTo(Team::class);
} }
public function otherTeams() public function otherTeams()
{ {
$team_id = session('currentTeam')->id; $team_id = data_get(session('currentTeam'), 'id');
return auth()->user()->teams->filter(function ($team) use ($team_id) { return auth()->user()->teams->filter(function ($team) use ($team_id) {
return $team->id != $team_id; return $team->id != $team_id;
}); });

View File

@ -30,19 +30,22 @@ function remoteProcess(
return resolve(DispatchRemoteProcess::class, [ return resolve(DispatchRemoteProcess::class, [
'remoteProcessArgs' => new RemoteProcessArgs( 'remoteProcessArgs' => new RemoteProcessArgs(
type: $deployment_uuid ? ActivityTypes::DEPLOYMENT->value : ActivityTypes::REMOTE_PROCESS->value,
model: $model, model: $model,
server_ip: $server->ip, server_ip: $server->ip,
deployment_uuid: $deployment_uuid,
private_key_location: $private_key_location, private_key_location: $private_key_location,
deployment_uuid: $deployment_uuid,
command: <<<EOT command: <<<EOT
{$command_string} {$command_string}
EOT, EOT,
port: $server->port, port: $server->port,
user: $server->user, user: $server->user,
type: $deployment_uuid ? ActivityTypes::DEPLOYMENT->value : ActivityTypes::REMOTE_PROCESS->value,
), ),
])(); ])();
} }
}
if (!function_exists('checkTeam')) {
function checkTeam(string $team_id) function checkTeam(string $team_id)
{ {
$found_team = auth()->user()->teams->pluck('id')->contains($team_id); $found_team = auth()->user()->teams->pluck('id')->contains($team_id);

View File

@ -19,6 +19,7 @@ public function definition(): array
{ {
return [ return [
'name' => fake()->name(), 'name' => fake()->name(),
'uuid' => Str::uuid(),
'email' => fake()->unique()->safeEmail(), 'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(), 'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password

View File

@ -10,13 +10,11 @@ class UserSeeder extends Seeder
public function run(): void public function run(): void
{ {
User::factory()->create([ User::factory()->create([
'id' => 1,
'name' => 'Root User', 'name' => 'Root User',
'email' => 'test@example.com', 'email' => 'test@example.com',
'is_root_user' => true, 'is_root_user' => true,
]); ]);
User::factory()->create([ User::factory()->create([
'id' => 2,
'name' => 'Normal User', 'name' => 'Normal User',
'email' => 'test2@example.com', 'email' => 'test2@example.com',
]); ]);

View File

@ -13,15 +13,17 @@ stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0 stderr_logfile_maxbytes=0
[program:laravel-worker] # Run workers by running manually `sail artisan queue:listen`
process_name=%(program_name)s_%(process_num)02d #
command=/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan queue:listen #[program:laravel-worker]
user=sail #process_name=%(program_name)s_%(process_num)02d
autostart=true #command=/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan queue:listen
autorestart=true #user=sail
stopasgroup=true #autostart=true
killasgroup=true #autorestart=true
numprocs=8 #stopasgroup=true
redirect_stderr=true #killasgroup=true
stdout_logfile=/var/www/html/storage/logs/worker.log #numprocs=8
stopwaitsecs=3600 #redirect_stderr=true
#stdout_logfile=/var/www/html/storage/logs/worker.log
#stopwaitsecs=3600

View File

@ -2,13 +2,28 @@
use App\Models\User; use App\Models\User;
use App\Models\Server; use App\Models\Server;
use Database\Seeders\DatabaseSeeder;
use Tests\Support\Output; use Tests\Support\Output;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
uses(DatabaseMigrations::class);
beforeEach(function () {
$this->seed(DatabaseSeeder::class);
});
it('starts a docker container correctly', function () { it('starts a docker container correctly', function () {
test()->actingAs(User::factory()->create()); test()->actingAs(User::factory([
'uuid' => Str::uuid(),
'email' => Str::uuid().'@example.com',
])->create());
$coolifyNamePrefix = 'coolify_test_'; $coolifyNamePrefix = 'coolify_test_';
$format = '{"ID":"{{ .ID }}", "Image": "{{ .Image }}", "Names":"{{ .Names }}"}'; $format = '{"ID":"{{ .ID }}", "Image": "{{ .Image }}", "Names":"{{ .Names }}"}';
$areThereCoolifyTestContainers = "docker ps --filter=\"name={$coolifyNamePrefix}*\" --format '{$format}' "; $areThereCoolifyTestContainers = "docker ps --filter=\"name={$coolifyNamePrefix}*\" --format '{$format}' ";
@ -16,6 +31,14 @@
$containerName = 'coolify_test_' . now()->format('Ymd_his'); $containerName = 'coolify_test_' . now()->format('Ymd_his');
$host = Server::where('name', 'testing-local-docker-container')->first(); $host = Server::where('name', 'testing-local-docker-container')->first();
// Stop testing containers
$activity = remoteProcess([
"docker stop $(docker ps --filter='name={$coolifyNamePrefix}*' -aq)",
"docker rm $(docker ps --filter='name={$coolifyNamePrefix}*' -aq)",
], $host);
ray($activity->description);
expect($activity->getExtraProperty('exitCode'))->toBe(0);
// Assert there's no containers start with coolify_test_* // Assert there's no containers start with coolify_test_*
$activity = remoteProcess([$areThereCoolifyTestContainers], $host); $activity = remoteProcess([$areThereCoolifyTestContainers], $host);
$containers = Output::containerList($activity->getExtraProperty('stdout')); $containers = Output::containerList($activity->getExtraProperty('stdout'));
@ -31,6 +54,9 @@
expect($containers->where('Names', $containerName)->count())->toBe(1); expect($containers->where('Names', $containerName)->count())->toBe(1);
// Stop testing containers // Stop testing containers
$activity = remoteProcess(["docker stop $(docker ps --filter='name={$coolifyNamePrefix}*' -q)"], $host); $activity = remoteProcess([
"docker stop $(docker ps --filter='name={$coolifyNamePrefix}*' -aq)",
"docker rm $(docker ps --filter='name={$coolifyNamePrefix}*' -aq)",
], $host);
expect($activity->getExtraProperty('exitCode'))->toBe(0); expect($activity->getExtraProperty('exitCode'))->toBe(0);
}); });