Save compose to local disk

This commit is contained in:
Andras Bacsai 2023-04-14 11:10:31 +02:00
parent 9b26a2a859
commit 4c3c546c2f
2 changed files with 9 additions and 4 deletions

View File

@ -9,13 +9,13 @@ use App\Models\Application;
use App\Models\CoolifyInstanceSettings; use App\Models\CoolifyInstanceSettings;
use DateTimeImmutable; use DateTimeImmutable;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use Lcobucci\JWT\Encoding\ChainedFormatter; use Lcobucci\JWT\Encoding\ChainedFormatter;
use Lcobucci\JWT\Encoding\JoseEncoder; use Lcobucci\JWT\Encoding\JoseEncoder;
use Lcobucci\JWT\Signer\Key\InMemory; use Lcobucci\JWT\Signer\Key\InMemory;
@ -23,6 +23,7 @@ use Lcobucci\JWT\Signer\Rsa\Sha256;
use Lcobucci\JWT\Token\Builder; use Lcobucci\JWT\Token\Builder;
use Spatie\Activitylog\Models\Activity; use Spatie\Activitylog\Models\Activity;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
use Illuminate\Support\Str;
class DeployApplicationJob implements ShouldQueue class DeployApplicationJob implements ShouldQueue
{ {
@ -118,7 +119,8 @@ class DeployApplicationJob implements ShouldQueue
$this->execute_in_builder("rm -fr {$this->workdir}/.git") $this->execute_in_builder("rm -fr {$this->workdir}/.git")
], hideFromOutput: true); ], hideFromOutput: true);
$docker_compose_base64 = base64_encode($this->generate_docker_compose()); $docker_compose = $this->generate_docker_compose();
$docker_compose_base64 = base64_encode($docker_compose);
$this->executeNow([ $this->executeNow([
$this->execute_in_builder("echo '{$docker_compose_base64}' | base64 -d > {$this->workdir}/docker-compose.yml") $this->execute_in_builder("echo '{$docker_compose_base64}' | base64 -d > {$this->workdir}/docker-compose.yml")
], hideFromOutput: true); ], hideFromOutput: true);
@ -146,6 +148,11 @@ class DeployApplicationJob implements ShouldQueue
"echo 'Done. 🎉'", "echo 'Done. 🎉'",
"docker stop -t 0 {$this->deployment_uuid} >/dev/null" "docker stop -t 0 {$this->deployment_uuid} >/dev/null"
], setStatus: true); ], setStatus: true);
dispatch(new ContainerStatusJob($this->application_uuid));
// Saving docker-compose.yml
Storage::disk('deployments')->put(Str::kebab($this->application->name) . '/docker-compose.yml', Yaml::dump($docker_compose, 10));
} }
private function execute_in_builder(string $command) private function execute_in_builder(string $command)

View File

@ -47,7 +47,6 @@ return [
'ssh-keys' => [ 'ssh-keys' => [
'driver' => 'local', 'driver' => 'local',
'root' => storage_path('app/ssh-keys'), 'root' => storage_path('app/ssh-keys'),
'url' => env('APP_URL').'/storage',
'visibility' => 'private', 'visibility' => 'private',
'throw' => false, 'throw' => false,
], ],
@ -55,7 +54,6 @@ return [
'deployments' => [ 'deployments' => [
'driver' => 'local', 'driver' => 'local',
'root' => storage_path('app/deployments'), 'root' => storage_path('app/deployments'),
'url' => env('APP_URL').'/storage',
'visibility' => 'private', 'visibility' => 'private',
'throw' => false, 'throw' => false,
], ],