wip: persisting data

This commit is contained in:
Andras Bacsai
2023-04-03 13:37:53 +02:00
parent 829a45f410
commit 259f41bb8a
10 changed files with 92 additions and 7 deletions

View File

@@ -121,15 +121,25 @@ class DeployApplicationJob implements ShouldQueue
$this->execute_in_builder("cp {$this->workdir}/.nixpacks/Dockerfile {$this->workdir}/Dockerfile"),
$this->execute_in_builder("rm -f {$this->workdir}/.nixpacks/Dockerfile"),
"echo 'Done.'",
]);
$this->executeNow([
"echo -n 'Building image... '",
$this->execute_in_builder("docker build -f {$this->workdir}/Dockerfile --build-arg SOURCE_COMMIT={$this->git_commit} --progress plain -t {$this->application->uuid}:{$this->git_commit} {$this->workdir}"),
"echo 'Done.'",
]);
$this->executeNow([
"echo -n 'Removing old container... '",
$this->execute_in_builder("docker rm -f {$this->application->uuid} >/dev/null 2>&1"),
"echo -n 'Deploying... '",
$this->execute_in_builder("docker compose --project-directory {$this->workdir} up -d"),
"echo 'Done.'",
]);
$this->executeNow([
"echo -n 'Starting new container... '",
$this->execute_in_builder("docker compose --project-directory {$this->workdir} up -d >/dev/null 2>&1"),
"echo 'Done. 🎉'",
"docker stop -t 0 {$this->deployment_uuid} >/dev/null"
], setStatus: true);
$this->executeNow([
"docker stop -t 0 {$this->deployment_uuid} >/dev/null"
]);
}
private function execute_in_builder(string $command)

View File

@@ -32,6 +32,10 @@ class Application extends BaseModel
{
return $this->morphTo();
}
public function persistentStorages()
{
return $this->morphMany(LocalPersistentVolume::class, 'resource');
}
public function portsMappings(): Attribute
{

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Models;
class LocalPersistentVolume extends BaseModel
{
public function application()
{
return $this->morphTo();
}
}