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\CoolifyInstanceSettings;
use DateTimeImmutable;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use Lcobucci\JWT\Encoding\ChainedFormatter;
use Lcobucci\JWT\Encoding\JoseEncoder;
use Lcobucci\JWT\Signer\Key\InMemory;
@ -23,6 +23,7 @@
use Lcobucci\JWT\Token\Builder;
use Spatie\Activitylog\Models\Activity;
use Symfony\Component\Yaml\Yaml;
use Illuminate\Support\Str;
class DeployApplicationJob implements ShouldQueue
{
@ -118,7 +119,8 @@ public function handle(): void
$this->execute_in_builder("rm -fr {$this->workdir}/.git")
], 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->execute_in_builder("echo '{$docker_compose_base64}' | base64 -d > {$this->workdir}/docker-compose.yml")
], hideFromOutput: true);
@ -146,6 +148,11 @@ public function handle(): void
"echo 'Done. 🎉'",
"docker stop -t 0 {$this->deployment_uuid} >/dev/null"
], 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)

View File

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