mirror of
https://github.com/coollabsio/coolify.git
synced 2026-08-28 02:24:23 -05:00
Restrict V5 application and resource-connection creation to team admins. Resolve project, environment, and application from query params and keep session selection in sync. Surface V5 apps on the v4 resource index and count them for project/environment emptiness. Create the flux data dir on install and upgrade.
151 lines
5.7 KiB
PHP
151 lines
5.7 KiB
PHP
<?php
|
|
|
|
function assertBashSyntaxIsValid(string $path): void
|
|
{
|
|
$process = proc_open(
|
|
['bash', '-n', getcwd().'/'.$path],
|
|
[
|
|
1 => ['pipe', 'w'],
|
|
2 => ['pipe', 'w'],
|
|
],
|
|
$pipes,
|
|
getcwd()
|
|
);
|
|
|
|
expect($process)->toBeResource();
|
|
|
|
$stdout = stream_get_contents($pipes[1]);
|
|
$stderr = stream_get_contents($pipes[2]);
|
|
fclose($pipes[1]);
|
|
fclose($pipes[2]);
|
|
|
|
$exitCode = proc_close($process);
|
|
|
|
expect($exitCode, trim($stdout."\n".$stderr))->toBe(0);
|
|
}
|
|
|
|
it('ships postgres upgrade scripts with valid bash syntax', function () {
|
|
assertBashSyntaxIsValid('scripts/upgrade-postgres.sh');
|
|
assertBashSyntaxIsValid('other/nightly/upgrade-postgres.sh');
|
|
});
|
|
|
|
it('downloads postgres upgrade script during install and upgrade without auto-running it', function (string $path) {
|
|
$script = file_get_contents(getcwd().'/'.$path);
|
|
|
|
expect($script)
|
|
->toContain('upgrade-postgres.sh')
|
|
->toContain('curl -fsSL -L $CDN/upgrade-postgres.sh -o /data/coolify/source/upgrade-postgres.sh')
|
|
->toContain('chmod +x')
|
|
->not->toContain('bash /data/coolify/source/upgrade-postgres.sh');
|
|
})->with([
|
|
'stable install' => 'scripts/install.sh',
|
|
'nightly install' => 'other/nightly/install.sh',
|
|
'stable upgrade' => 'scripts/upgrade.sh',
|
|
'nightly upgrade' => 'other/nightly/upgrade.sh',
|
|
]);
|
|
|
|
it('generates a dedicated flux laravel api token during install and upgrade', function (string $path) {
|
|
$script = file_get_contents(getcwd().'/'.$path);
|
|
|
|
expect($script)
|
|
->toContain('update_env_var "COOLIFY_FLUX_LARAVEL_API_TOKEN" "$(openssl rand -hex 32)"');
|
|
})->with([
|
|
'stable install' => 'scripts/install.sh',
|
|
'nightly install' => 'other/nightly/install.sh',
|
|
'stable upgrade' => 'scripts/upgrade.sh',
|
|
'nightly upgrade' => 'other/nightly/upgrade.sh',
|
|
]);
|
|
|
|
it('creates a writable flux storage directory during install and upgrade', function (string $path) {
|
|
$script = file_get_contents(getcwd().'/'.$path);
|
|
|
|
expect($script)
|
|
->toContain('/data/coolify/flux')
|
|
->toContain('chown -R 9999:root /data/coolify/flux');
|
|
})->with([
|
|
'stable install' => 'scripts/install.sh',
|
|
'nightly install' => 'other/nightly/install.sh',
|
|
'stable upgrade' => 'scripts/upgrade.sh',
|
|
'nightly upgrade' => 'other/nightly/upgrade.sh',
|
|
]);
|
|
|
|
it('uses the selected registry url when extracting upgrade images', function (string $path) {
|
|
$script = file_get_contents(getcwd().'/'.$path);
|
|
|
|
expect($script)->toContain('IMAGES=$(REGISTRY_URL=${REGISTRY_URL} LATEST_IMAGE=${LATEST_IMAGE} docker compose --env-file "$ENV_FILE" $COMPOSE_FILES config --images');
|
|
})->with([
|
|
'stable upgrade' => 'scripts/upgrade.sh',
|
|
'nightly upgrade' => 'other/nightly/upgrade.sh',
|
|
]);
|
|
|
|
it('persists the selected registry url during upgrades', function (string $path) {
|
|
$script = file_get_contents(getcwd().'/'.$path);
|
|
|
|
expect($script)->toContain('set_env_var "REGISTRY_URL" "$REGISTRY_URL"');
|
|
})->with([
|
|
'stable upgrade' => 'scripts/upgrade.sh',
|
|
'nightly upgrade' => 'other/nightly/upgrade.sh',
|
|
]);
|
|
|
|
it('uses the existing env registry url when old callers do not pass a registry argument', function (string $path) {
|
|
$script = file_get_contents(getcwd().'/'.$path);
|
|
|
|
expect($script)
|
|
->toContain('if [ -n "${3+x}" ]; then')
|
|
->toContain('REGISTRY_URL="$3"')
|
|
->toContain('elif [ -f "$ENV_FILE" ] && grep -q "^REGISTRY_URL=" "$ENV_FILE"; then')
|
|
->toContain("REGISTRY_URL=$(grep \"^REGISTRY_URL=\" \"\$ENV_FILE\" | cut -d '=' -f2- | head -n1)")
|
|
->toContain('REGISTRY_URL="docker.io"');
|
|
})->with([
|
|
'stable upgrade' => 'scripts/upgrade.sh',
|
|
'nightly upgrade' => 'other/nightly/upgrade.sh',
|
|
]);
|
|
|
|
it('keeps postgres upgrade compose override in future upgrade compose commands', function (string $path) {
|
|
$script = file_get_contents(getcwd().'/'.$path);
|
|
|
|
expect($script)
|
|
->toContain('docker-compose.postgres-upgrade.yml')
|
|
->toContain('Including PostgreSQL upgrade compose override in image extraction')
|
|
->toContain('Using PostgreSQL upgrade compose override');
|
|
})->with([
|
|
'stable upgrade' => 'scripts/upgrade.sh',
|
|
'nightly upgrade' => 'other/nightly/upgrade.sh',
|
|
]);
|
|
|
|
it('uses postgres 18 compatible mount path in generated override and restore container', function () {
|
|
$script = file_get_contents(getcwd().'/scripts/upgrade-postgres.sh');
|
|
|
|
expect($script)
|
|
->toContain("printf '%s' '/var/lib/postgresql'")
|
|
->toContain("printf '%s' '/var/lib/postgresql/data'")
|
|
->toContain('- coolify-db:${mount_path}')
|
|
->toContain('-v "${TARGET_VOLUME}:${TARGET_MOUNT_PATH}"');
|
|
});
|
|
|
|
it('persists rollback metadata and exposes a rollback command', function () {
|
|
$script = file_get_contents(getcwd().'/scripts/upgrade-postgres.sh');
|
|
|
|
expect($script)
|
|
->toContain('ROLLBACK_FILE="${SOURCE_DIR}/postgres-upgrade-rollback.env"')
|
|
->toContain('$0 rollback')
|
|
->toContain('write_rollback_file')
|
|
->toContain('PREVIOUS_VOLUME=')
|
|
->toContain('PREVIOUS_IMAGE=')
|
|
->toContain('PREVIOUS_MOUNT_PATH=')
|
|
->toContain('rollback_postgres()')
|
|
->toContain('Rollback completed successfully.');
|
|
});
|
|
|
|
it('detects the active postgres volume instead of assuming coolify-db', function () {
|
|
$script = file_get_contents(getcwd().'/scripts/upgrade-postgres.sh');
|
|
|
|
expect($script)
|
|
->toContain('current_postgres_mount_name()')
|
|
->toContain('current_postgres_mount_path()')
|
|
->toContain('current_postgres_image()')
|
|
->toContain('Current active volume: ${PREVIOUS_VOLUME}')
|
|
->toContain("Previous volume '")
|
|
->toContain('will be kept for rollback');
|
|
});
|