Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"spatie/laravel-responsecache": "^7.7"
},
"require-dev": {
"austinmastlab/deployer-recipes": "^1.0.1",
"austinmastlab/deployer-recipes": "^1.2.0-rc1",
"barryvdh/laravel-debugbar": "^3.5",
"barryvdh/laravel-ide-helper": "^v3.0.0",
"deployer/deployer": "^8.0",
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@

require 'recipe/laravel.php';
require __DIR__.'/vendor/austinmastlab/deployer-recipes/recipe/ssm-env.php';
require __DIR__.'/vendor/austinmastlab/deployer-recipes/recipe/ci-artifacts.php';
require 'deploy/custom.php';

// .env is generated from SSM /digitizationacademy/{environment} by env:ssm (austinmastlab/deployer-recipes).
set('ssm_app', 'digitizationacademy');

// supervisor:reload (deployer-recipes) updates only this site's Supervisor group
set('supervisor_groups', ['da']);

// Deployment Configuration
set('repository', 'https://github.com/AustinMastLab/DigitizationAcademy.git');
set('base_path', '/data/web');
Expand Down
75 changes: 2 additions & 73 deletions deploy/custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,86 +81,15 @@
desc('Publish the Sweet Alert JavaScript');
task('artisan:alert:publish', artisan('alert:publish --assets --force'));

/**
* Reload Supervisor configuration
* Executes reread and update commands for Supervisor
*/
desc('Reload Supervisor configuration (config-only update)');
task('supervisor:reload', function () {
run('sudo supervisorctl reread');
run('sudo supervisorctl update');
});

/*
* =============================================================================
* CI/CD ARTIFACT DEPLOYMENT - CORE FEATURE
* =============================================================================
*/

desc('Download and extract pre-built assets from GitHub Actions');
task('deploy:ci-artifacts', function () {
// Environment variables automatically provided by GitHub Actions workflow
$githubToken = $_ENV['GITHUB_TOKEN'] ?? getenv('GITHUB_TOKEN') ?? '';
$githubSha = $_ENV['GITHUB_SHA'] ?? getenv('GITHUB_SHA') ?? '';
$githubRepo = $_ENV['GITHUB_REPO'] ?? getenv('GITHUB_REPO') ?? 'AustinMastLab/DigitizationAcademy';

// Validate required environment variables
if (empty($githubToken) || empty($githubSha)) {
throw new \Exception('GITHUB_TOKEN and GITHUB_SHA environment variables are required.');
}

// Artifact naming convention: digitizationacademy-{git-sha}
$artifactName = "digitizationacademy-{$githubSha}";
writeln("Downloading CI artifact: {$artifactName}");

// Step 1: Get artifact download URL from GitHub API
$apiUrl = "https://api.github.com/repos/{$githubRepo}/actions/artifacts";
$response = runLocally("curl -H 'Authorization: Bearer {$githubToken}' -H 'Accept: application/vnd.github.v3+json' '{$apiUrl}?name={$artifactName}&per_page=1'");
$artifacts = json_decode($response, true);

if (empty($artifacts['artifacts'])) {
throw new \Exception("No CI artifact found with name: {$artifactName}");
}

$downloadUrl = $artifacts['artifacts'][0]['archive_download_url'];
cd('{{release_or_current_path}}');

// Step 2: Download and extract
run("curl -L -H 'Authorization: Bearer {$githubToken}' -H 'Accept: application/vnd.github.v3+json' '{$downloadUrl}' -o artifact.zip");
run('unzip -o -q artifact.zip');

// Step 3: Biospex-style Nesting Correction
$nestLevelCmd = run('find . -type d -name "deployment-package" -printf "%p\\n" | wc -l');
$nests = (int) trim($nestLevelCmd);

if ($nests > 0) {
$innermost = run('find . -type d -name "deployment-package" | sort -r | head -1');
$innermost = trim($innermost);
if (! empty($innermost)) {
run("rsync -av '{$innermost}/' ./");
run('find . -type d -name "deployment-package" -exec rm -rf {} +');
}
}

run('rm -f artifact.zip');
writeln('✅ CI artifacts deployed successfully (Flat structure ensured)');
});
// deploy:ci-artifacts, deploy:verify-structure and supervisor:reload come from
// deployer-recipes/recipe/ci-artifacts.php (required in deploy.php).

/*
* =============================================================================
* ENVIRONMENT MANAGEMENT
* =============================================================================
*/

desc('Verify flat deployment structure');
task('deploy:verify-structure', function () {
$nestCheck = run('find {{release_path}} -type d -name "deployment-package" | wc -l');
if ((int) trim($nestCheck) > 0) {
throw new \Exception("Nesting detected post-deploy: {$nestCheck} dirs. Check CI artifact.");
}
writeln('✅ Deployment structure verified: flat and clean');
});

/**
* Clear package discovery cache before running composer operations
* This prevents conflicts when packages are removed (like Nova)
Expand Down
Loading