Files
coolify/tests/Unit/UpgradeScriptContainerStartTest.php
T
peaklabs-dev e0fb2b3897 ci(release): build and release a nightly twice a day
- Remove other/nightly, the nightly channel uses the production files, so there are no longer two copies to keep in sync
- sync-cdn.sh --nightly syncs the files of the commit the nightly is built from to /coolify/nightly on the CDN, with the nightly version in its versions.json and in /coolify/release.json, and pushes them straight to main of coollabs-cdn
- version.sh picks the branch the nightly comes from, the release branch of the next version after the newest stable one or next, and names the version <preview>.<YYYYMMDD>.<N>
- The image is labeled with its version and commit, the nightly workflow reads both from the image nightly points at to count up N and to skip a run without a new commit
2026-11-01 19:37:39 +01:00

64 lines
2.3 KiB
PHP

<?php
/**
* Runs the detached container restart block of the upgrade script with a fake docker.
*
* @return array{exitCode: int, status: string}
*/
function runUpgradeScriptContainerStart(string $script, int $composeExitCode, bool $coolifyRunning): array
{
$dir = sys_get_temp_dir().'/upgrade-start-'.bin2hex(random_bytes(4));
mkdir($dir);
touch("{$dir}/status");
$source = file_get_contents(getcwd().'/'.$script);
preg_match('/^nohup bash -c "\n(.*?)^" >>"\$LOGFILE" 2>&1 &$/ms', $source, $match);
$running = $coolifyRunning ? 'true' : 'false';
$harness = <<<BASH
LOGFILE="{$dir}/upgrade.log"
STATUS_FILE="{$dir}/status"
DOCKER_CONFIG_MOUNT=''
REGISTRY_URL='docker.io'
LATEST_HELPER_VERSION='1.0.17'
LATEST_IMAGE='4.4.7'
docker() {
case "\$1" in
run) return {$composeExitCode} ;;
inspect) echo {$running} ;;
esac
}
sleep() { :; }
export -f docker sleep
bash -c "
{$match[1]}"
BASH;
exec('bash -c '.escapeshellarg($harness).' >/dev/null 2>&1', result_code: $exitCode);
$status = is_file("{$dir}/status") ? file_get_contents("{$dir}/status") : '';
exec('rm -rf '.escapeshellarg($dir));
return ['exitCode' => $exitCode, 'status' => $status];
}
it('reports an error when the new Coolify containers do not start', function (string $script) {
$result = runUpgradeScriptContainerStart($script, composeExitCode: 1, coolifyRunning: false);
expect($result['exitCode'])->toBe(1)
->and($result['status'])->toStartWith('error|')
->toContain('upgrade log');
})->with(['scripts/upgrade.sh']);
it('completes the upgrade when the coolify container runs but is not healthy within the wait timeout', function (string $script) {
$result = runUpgradeScriptContainerStart($script, composeExitCode: 1, coolifyRunning: true);
expect($result['exitCode'])->toBe(0)
->and($result['status'])->toBe('');
})->with(['scripts/upgrade.sh']);
it('completes the upgrade when docker compose up succeeds', function (string $script) {
$result = runUpgradeScriptContainerStart($script, composeExitCode: 0, coolifyRunning: true);
expect($result['exitCode'])->toBe(0)
->and($result['status'])->toBe('');
})->with(['scripts/upgrade.sh']);