fix: local dev s3 uploads
fix: hetzner s3 uploads (mc alias instead of mc host)
This commit is contained in:
		@@ -237,7 +237,6 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            $this->backup_dir = backup_dir().'/databases/'.str($this->team->name)->slug().'-'.$this->team->id.'/'.$this->directory_name;
 | 
					            $this->backup_dir = backup_dir().'/databases/'.str($this->team->name)->slug().'-'.$this->team->id.'/'.$this->directory_name;
 | 
				
			||||||
 | 
					 | 
				
			||||||
            if ($this->database->name === 'coolify-db') {
 | 
					            if ($this->database->name === 'coolify-db') {
 | 
				
			||||||
                $databasesToBackup = ['coolify'];
 | 
					                $databasesToBackup = ['coolify'];
 | 
				
			||||||
                $this->directory_name = $this->container_name = 'coolify-db';
 | 
					                $this->directory_name = $this->container_name = 'coolify-db';
 | 
				
			||||||
@@ -515,10 +514,27 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
 | 
				
			|||||||
            $this->ensureHelperImageAvailable();
 | 
					            $this->ensureHelperImageAvailable();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $fullImageName = $this->getFullImageName();
 | 
					            $fullImageName = $this->getFullImageName();
 | 
				
			||||||
            $commands[] = "docker run -d --network {$network} --name backup-of-{$this->backup->uuid} --rm -v $this->backup_location:$this->backup_location:ro {$fullImageName}";
 | 
					
 | 
				
			||||||
            $commands[] = "docker exec backup-of-{$this->backup->uuid} mc config host add temporary {$endpoint} $key $secret";
 | 
					            if (isDev()) {
 | 
				
			||||||
 | 
					                if ($this->database->name === 'coolify-db') {
 | 
				
			||||||
 | 
					                    $backup_location_from = '/var/lib/docker/volumes/coolify_dev_backups_data/_data/databases/coolify/coolify-db-'.$this->server->ip.$this->backup_file;
 | 
				
			||||||
 | 
					                    $commands[] = "docker run -d --network {$network} --name backup-of-{$this->backup->uuid} --rm -v $backup_location_from:$this->backup_location:ro {$fullImageName}";
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    $backup_location_from = '/var/lib/docker/volumes/coolify_dev_backups_data/_data/databases/'.str($this->team->name)->slug().'-'.$this->team->id.'/'.$this->directory_name.$this->backup_file;
 | 
				
			||||||
 | 
					                    $commands[] = "docker run -d --network {$network} --name backup-of-{$this->backup->uuid} --rm -v $backup_location_from:$this->backup_location:ro {$fullImageName}";
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                $commands[] = "docker run -d --network {$network} --name backup-of-{$this->backup->uuid} --rm -v $this->backup_location:$this->backup_location:ro {$fullImageName}";
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if ($this->s3->isHetzner()) {
 | 
				
			||||||
 | 
					                $endpointWithoutBucket = 'https://'.str($endpoint)->after('https://')->after('.')->value();
 | 
				
			||||||
 | 
					                $commands[] = "docker exec backup-of-{$this->backup->uuid} mc alias set --path=off --api=S3v4 temporary {$endpointWithoutBucket} $key $secret";
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                $commands[] = "docker exec backup-of-{$this->backup->uuid} mc config host add temporary {$endpoint} $key $secret";
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            $commands[] = "docker exec backup-of-{$this->backup->uuid} mc cp $this->backup_location temporary/$bucket{$this->backup_dir}/";
 | 
					            $commands[] = "docker exec backup-of-{$this->backup->uuid} mc cp $this->backup_location temporary/$bucket{$this->backup_dir}/";
 | 
				
			||||||
            instant_remote_process($commands, $this->server);
 | 
					            instant_remote_process($commands, $this->server);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $this->add_to_backup_output('Uploaded to S3.');
 | 
					            $this->add_to_backup_output('Uploaded to S3.');
 | 
				
			||||||
        } catch (\Throwable $e) {
 | 
					        } catch (\Throwable $e) {
 | 
				
			||||||
            $this->add_to_backup_output($e->getMessage());
 | 
					            $this->add_to_backup_output($e->getMessage());
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,6 +40,16 @@ class S3Storage extends BaseModel
 | 
				
			|||||||
        return "{$this->endpoint}/{$this->bucket}";
 | 
					        return "{$this->endpoint}/{$this->bucket}";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function isHetzner()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return str($this->endpoint)->contains('your-objectstorage.com');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function isDigitalOcean()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return str($this->endpoint)->contains('digitaloceanspaces.com');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function testConnection(bool $shouldSave = false)
 | 
					    public function testConnection(bool $shouldSave = false)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,15 +1,11 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use App\Models\S3Storage;
 | 
					use App\Models\S3Storage;
 | 
				
			||||||
use Illuminate\Support\Str;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
function set_s3_target(S3Storage $s3)
 | 
					function set_s3_target(S3Storage $s3)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    $is_digital_ocean = false;
 | 
					    $is_digital_ocean = false;
 | 
				
			||||||
    if ($s3->endpoint) {
 | 
					
 | 
				
			||||||
        $is_digital_ocean = Str::contains($s3->endpoint, 'digitaloceanspaces.com');
 | 
					 | 
				
			||||||
        $is_hetzner = Str::contains($s3->endpoint, 'your-objectstorage.com');
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    config()->set('filesystems.disks.custom-s3', [
 | 
					    config()->set('filesystems.disks.custom-s3', [
 | 
				
			||||||
        'driver' => 's3',
 | 
					        'driver' => 's3',
 | 
				
			||||||
        'region' => $s3['region'],
 | 
					        'region' => $s3['region'],
 | 
				
			||||||
@@ -18,7 +14,7 @@ function set_s3_target(S3Storage $s3)
 | 
				
			|||||||
        'bucket' => $s3['bucket'],
 | 
					        'bucket' => $s3['bucket'],
 | 
				
			||||||
        'endpoint' => $s3['endpoint'],
 | 
					        'endpoint' => $s3['endpoint'],
 | 
				
			||||||
        'use_path_style_endpoint' => true,
 | 
					        'use_path_style_endpoint' => true,
 | 
				
			||||||
        'bucket_endpoint' => $is_digital_ocean || $is_hetzner,
 | 
					        'bucket_endpoint' => $s3->isHetzner() || $s3->isDigitalOcean(),
 | 
				
			||||||
        'aws_url' => $s3->awsUrl(),
 | 
					        'aws_url' => $s3->awsUrl(),
 | 
				
			||||||
    ]);
 | 
					    ]);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -296,9 +296,8 @@
 | 
				
			|||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    <template x-if="step === 1">
 | 
					                    <template x-if="step === 1">
 | 
				
			||||||
                        @if(isDev() && $submitAction === 'delete')
 | 
					                        @if(isDev() && str($submitAction)->contains('delete'))
 | 
				
			||||||
                            <x-forms.button class="w-auto" isError
 | 
					                            <x-forms.button class="w-auto" isError wire:click="{{ $submitAction }}('hello')">
 | 
				
			||||||
                                    @click="$wire.delete('hello')">
 | 
					 | 
				
			||||||
                                <span x-text="step3ButtonText"></span>
 | 
					                                <span x-text="step3ButtonText"></span>
 | 
				
			||||||
                            </x-forms.button>
 | 
					                            </x-forms.button>
 | 
				
			||||||
                        @else
 | 
					                        @else
 | 
				
			||||||
@@ -309,7 +308,7 @@
 | 
				
			|||||||
                    </template>
 | 
					                    </template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    <template x-if="step === 2">
 | 
					                    <template x-if="step === 2">
 | 
				
			||||||
                        <x-forms.button x-bind:disabled="confirmationText !== '' && confirmWithText && userConfirmationText !== confirmationText"
 | 
					                        <x-forms.button x-bind:disabled="confirmationText !== ''  && userConfirmationText !== confirmationText"
 | 
				
			||||||
                            class="w-auto" isError
 | 
					                            class="w-auto" isError
 | 
				
			||||||
                            @click="
 | 
					                            @click="
 | 
				
			||||||
                            if (dispatchEvent) {
 | 
					                            if (dispatchEvent) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -45,20 +45,11 @@
 | 
				
			|||||||
                            <x-forms.button class="dark:hover:bg-coolgray-400"
 | 
					                            <x-forms.button class="dark:hover:bg-coolgray-400"
 | 
				
			||||||
                                x-on:click="download_file('{{ data_get($execution, 'id') }}')">Download</x-forms.button>
 | 
					                                x-on:click="download_file('{{ data_get($execution, 'id') }}')">Download</x-forms.button>
 | 
				
			||||||
                        @endif
 | 
					                        @endif
 | 
				
			||||||
                        <x-modal-confirmation
 | 
					                        <x-modal-confirmation title="Confirm Backup Deletion?" buttonTitle="Delete" isErrorButton
 | 
				
			||||||
                        title="Confirm Backup Deletion?"
 | 
					                            submitAction="deleteBackup({{ data_get($execution, 'id') }})"
 | 
				
			||||||
                        buttonTitle="Delete"
 | 
					                            :actions="['This backup will be permanently deleted from local storage.']" confirmationText="{{ data_get($execution, 'filename') }}"
 | 
				
			||||||
                        isErrorButton
 | 
					                            confirmationLabel="Please confirm the execution of the actions by entering the Backup Filename below"
 | 
				
			||||||
                        submitAction="deleteBackup({{ data_get($execution, 'id') }})"
 | 
					                            shortConfirmationLabel="Backup Filename" step3ButtonText="Permanently Delete" />
 | 
				
			||||||
                        {{-- :checkboxes="$checkboxes"  --}}
 | 
					 | 
				
			||||||
                        :actions="[
 | 
					 | 
				
			||||||
                            'This backup will be permanently deleted from local storage.'
 | 
					 | 
				
			||||||
                        ]"
 | 
					 | 
				
			||||||
                        confirmationText="{{ data_get($execution, 'filename') }}"
 | 
					 | 
				
			||||||
                        confirmationLabel="Please confirm the execution of the actions by entering the Backup Filename below"
 | 
					 | 
				
			||||||
                        shortConfirmationLabel="Backup Filename"
 | 
					 | 
				
			||||||
                        step3ButtonText="Permanently Delete"
 | 
					 | 
				
			||||||
                        />
 | 
					 | 
				
			||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
            @empty
 | 
					            @empty
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,16 +2,18 @@
 | 
				
			|||||||
    <x-forms.input placeholder="0 0 * * * or daily" id="frequency"
 | 
					    <x-forms.input placeholder="0 0 * * * or daily" id="frequency"
 | 
				
			||||||
        helper="You can use every_minute, hourly, daily, weekly, monthly, yearly or a cron expression." label="Frequency"
 | 
					        helper="You can use every_minute, hourly, daily, weekly, monthly, yearly or a cron expression." label="Frequency"
 | 
				
			||||||
        required />
 | 
					        required />
 | 
				
			||||||
    <x-forms.checkbox id="save_s3" label="Save to S3" />
 | 
					    @if ($s3s->count() === 0)
 | 
				
			||||||
    <x-forms.select id="selected_storage_id">
 | 
					        <div class="text-red-500">No validated S3 Storages found.</div>
 | 
				
			||||||
        @if ($s3s->count() === 0)
 | 
					    @else
 | 
				
			||||||
            <option value="0">No S3 Storages found.</option>
 | 
					        <x-forms.checkbox wire:model.live="save_s3" label="Save to S3" />
 | 
				
			||||||
        @else
 | 
					        @if ($save_s3)
 | 
				
			||||||
            @foreach ($s3s as $s3)
 | 
					            <x-forms.select id="selected_storage_id" label="Select a validated S3 storage">
 | 
				
			||||||
                <option value="{{ $s3->id }}">{{ $s3->name }}</option>
 | 
					                @foreach ($s3s as $s3)
 | 
				
			||||||
            @endforeach
 | 
					                    <option value="{{ $s3->id }}">{{ $s3->name }}</option>
 | 
				
			||||||
 | 
					                @endforeach
 | 
				
			||||||
 | 
					            </x-forms.select>
 | 
				
			||||||
        @endif
 | 
					        @endif
 | 
				
			||||||
    </x-forms.select>
 | 
					    @endif
 | 
				
			||||||
    <x-forms.button type="submit" @click="modalOpen=false">
 | 
					    <x-forms.button type="submit" @click="modalOpen=false">
 | 
				
			||||||
        Save
 | 
					        Save
 | 
				
			||||||
    </x-forms.button>
 | 
					    </x-forms.button>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user