Skip to content

Commit

Permalink
fix: change error handling, do not use alias for ConsoleUtility
Browse files Browse the repository at this point in the history
  • Loading branch information
martipoe committed May 21, 2024
1 parent f11a3d0 commit fd11669
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions recipe/reset_from_gitlab_artifact.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
<?php

namespace Deployer;
use SourceBroker\DeployerExtendedDatabase\Utility\ConsoleUtility as DatabaseConsoleUtility;
use SourceBroker\DeployerExtendedDatabase\Utility\ConsoleUtility;
use Deployer\Exception\GracefulShutdownException;

task('reset:from_gitlab_artifact', function () {
// set in deploy.php as https://gitlab.example.org/api/v4/projects/<project-id>/jobs/artifacts/<branch>/download?job=<job-of-artifact>
$url = get('reset_gitlab_artifact_url');
// Gitlab API token for the repository where the artifact is stored. Can be a project token.
$gitlabApiToken = (new DatabaseConsoleUtility())->getOption('token', true);
$gitlabApiToken = (new ConsoleUtility())->getOption('token', true);
// Database dumpcode that was used during the creation of the Gitlab artifact.
$dumpCode = (new DatabaseConsoleUtility())->getOption('dumpcode', true);
$dumpCode = (new ConsoleUtility())->getOption('dumpcode', true);

if ( filter_var($url, FILTER_VALIDATE_URL) && preg_match('#jobs\/artifacts\/.+\/download$#', parse_url($url, PHP_URL_PATH)) ) {
if (get('is_argument_host_the_same_as_local_host')) {
$activeDir = get('deploy_path') . (testLocally('[ -e {{deploy_path}}/release ]') ? '/release' : '/current');
$activeDir = testLocally('[ -e ' . $activeDir . ' ]') ? $activeDir : get('deploy_path');
runLocally('cd ' . $activeDir . ' && curl --location --output artifacts.zip --header "PRIVATE-TOKEN: ' . $gitlabApiToken . '" "' . $url . '"');
runLocally('cd ' . $activeDir . ' && vendor/bin/dep db:rmdump {{argument_host}} --options=dumpcode:' . $dumpCode . ' --no-interaction');
runLocally('cd ' . $activeDir . ' && unzip -o artifacts.zip');
runLocally('cd ' . $activeDir . ' && mv -n .dep/database/dumps/*dumpcode=' . $dumpCode . '* {{db_storage_path_local}}/');
runLocally('cd ' . $activeDir . ' && vendor/bin/dep db:decompress {{argument_host}} --options=dumpcode:' . $dumpCode . ' --no-interaction');
runLocally('cd ' . $activeDir . ' && vendor/bin/dep db:import {{argument_host}} --options=dumpcode:' . $dumpCode . ' --no-interaction');
runLocally('cd ' . $activeDir . ' && vendor/bin/dep db:rmdump {{argument_host}} --options=dumpcode:' . $dumpCode . ' --no-interaction');
runLocally('cd ' . $activeDir . ' && rm -f artifacts.zip');
runLocally('cd ' . $activeDir . ' && {{local/bin/php}} {{bin/typo3cms}} cache:flush');
runLocally('cd ' . $activeDir . ' && {{local/bin/php}} {{bin/typo3cms}} cache:warmup');
} else {
$verbosity = (new DatabaseConsoleUtility())->getVerbosityAsParameter();
run('cd {{release_or_current_path}} && {{bin/php}} {{bin/deployer}} reset:from_gitlab_artifact ' . $verbosity . ' --options="token:' . $gitlabApiToken . ',dumpcode:' . $dumpCode . '" {{argument_host}}');
};
} else {
writeln('Gitlab API URL is invalid: ' . $url);
exit(1);
if (!filter_var($url, FILTER_VALIDATE_URL) || !preg_match('#jobs\/artifacts\/.+\/download$#', parse_url($url, PHP_URL_PATH))) {
throw new GracefulShutdownException('Gitlab API URL is invalid: ' . $url);
return;
}
if (get('is_argument_host_the_same_as_local_host')) {
$activeDir = get('deploy_path') . (testLocally('[ -e {{deploy_path}}/release ]') ? '/release' : '/current');
$activeDir = testLocally('[ -e ' . $activeDir . ' ]') ? $activeDir : get('deploy_path');
runLocally('cd ' . $activeDir . ' && curl --location --output artifacts.zip --header "PRIVATE-TOKEN: ' . $gitlabApiToken . '" "' . $url . '"');
runLocally('cd ' . $activeDir . ' && vendor/bin/dep db:rmdump {{argument_host}} --options=dumpcode:' . $dumpCode . ' --no-interaction');
runLocally('cd ' . $activeDir . ' && unzip -o artifacts.zip');
runLocally('cd ' . $activeDir . ' && mv -n .dep/database/dumps/*dumpcode=' . $dumpCode . '* {{db_storage_path_local}}/');
runLocally('cd ' . $activeDir . ' && vendor/bin/dep db:decompress {{argument_host}} --options=dumpcode:' . $dumpCode . ' --no-interaction');
runLocally('cd ' . $activeDir . ' && vendor/bin/dep db:import {{argument_host}} --options=dumpcode:' . $dumpCode . ' --no-interaction');
runLocally('cd ' . $activeDir . ' && vendor/bin/dep db:rmdump {{argument_host}} --options=dumpcode:' . $dumpCode . ' --no-interaction');
runLocally('cd ' . $activeDir . ' && rm -f artifacts.zip');
runLocally('cd ' . $activeDir . ' && {{local/bin/php}} {{bin/typo3cms}} cache:flush');
runLocally('cd ' . $activeDir . ' && {{local/bin/php}} {{bin/typo3cms}} cache:warmup');
} else {
$verbosity = (new ConsoleUtility())->getVerbosityAsParameter();
run('cd {{release_or_current_path}} && {{bin/php}} {{bin/deployer}} reset:from_gitlab_artifact ' . $verbosity . ' --options="token:' . $gitlabApiToken . ',dumpcode:' . $dumpCode . '" {{argument_host}}');
};
});

0 comments on commit fd11669

Please sign in to comment.