DO-1743: update CST endpoint format to use project key structure #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 🛍️ Magento Cloud Deployment | ||
|
Check failure on line 1 in .github/workflows/magento-cloud-deploy.yml
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| # Magento Cloud Configuration | ||
| magento-cloud-project-id: | ||
| description: "Magento Cloud project ID (required)" | ||
| type: string | ||
| required: true | ||
| environment: | ||
| description: "Target environment (integration/staging/production)" | ||
| type: string | ||
| required: false | ||
| default: "integration" | ||
| # PHP Configuration | ||
| php-version: | ||
| description: "PHP version for Magento (8.1, 8.2, 8.3)" | ||
| type: string | ||
| required: false | ||
| default: "8.1" | ||
| memory-limit: | ||
| description: "PHP memory limit for compilation (-1 for unlimited)" | ||
| type: string | ||
| required: false | ||
| default: "-1" | ||
| # Magento-specific Configuration | ||
| apply-patches: | ||
| description: "Apply ECE patches before deployment" | ||
| type: boolean | ||
| required: false | ||
| default: true | ||
| di-compile: | ||
| description: "Run dependency injection compilation" | ||
| type: boolean | ||
| required: false | ||
| default: true | ||
| # Monitoring and Reporting | ||
| newrelic-app-id: | ||
| description: "NewRelic application ID for deployment markers (optional)" | ||
| type: string | ||
| required: false | ||
| default: "" | ||
| # CST Reporting Configuration | ||
| cst-endpoint: | ||
| description: "CST endpoint base URL (optional, overrides workspace variable)" | ||
| type: string | ||
| required: false | ||
| default: "" | ||
| cst-project-key: | ||
| description: "CST project key (optional, overrides workspace variable)" | ||
| type: string | ||
| required: false | ||
| default: "" | ||
| cst-reporting-key: | ||
| description: "CST reporting key (optional, overrides workspace secret)" | ||
| type: string | ||
| required: false | ||
| default: "" | ||
| # Advanced Configuration | ||
| debug: | ||
| description: "Enable verbose logging and debug output" | ||
| type: boolean | ||
| required: false | ||
| default: false | ||
| secrets: | ||
| magento-cloud-cli-token: | ||
| description: "Magento Cloud CLI token for authentication" | ||
| required: true | ||
| newrelic-api-key: | ||
| description: "NewRelic API key for deployment markers (optional)" | ||
| required: false | ||
| cst-reporting-token: | ||
| description: "CST system reporting token (optional)" | ||
| required: false | ||
| outputs: | ||
| deployment-url: | ||
| description: "URL of the deployed Magento application" | ||
| value: ${{ jobs.deploy.outputs.deployment-url }} | ||
| deployment-id: | ||
| description: "Magento Cloud deployment ID" | ||
| value: ${{ jobs.deploy.outputs.deployment-id }} | ||
| jobs: | ||
| # Validate inputs and prepare deployment configuration | ||
| prepare: | ||
| name: 🔍 Prepare Magento Deployment | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| php-container: ${{ steps.php-config.outputs.container }} | ||
| memory-limit: ${{ steps.php-config.outputs.memory-limit }} | ||
| deployment-strategy: ${{ steps.deployment-config.outputs.strategy }} | ||
| steps: | ||
| - name: Validate required inputs | ||
| run: | | ||
| if [ -z "${{ inputs.magento-cloud-project-id }}" ]; then | ||
| echo "❌ Error: magento-cloud-project-id is required" | ||
| exit 1 | ||
| fi | ||
| if [ "${{ inputs.environment }}" != "integration" ] && [ "${{ inputs.environment }}" != "staging" ] && [ "${{ inputs.environment }}" != "production" ]; then | ||
| echo "❌ Error: environment must be one of: integration, staging, production" | ||
| exit 1 | ||
| fi | ||
| case "${{ inputs.php-version }}" in | ||
| "8.1"|"8.2"|"8.3") | ||
| echo "✅ PHP version ${{ inputs.php-version }} is supported" | ||
| ;; | ||
| *) | ||
| echo "❌ Error: php-version must be one of: 8.1, 8.2, 8.3" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| echo "✅ All required inputs validated" | ||
| - name: Configure PHP environment | ||
| id: php-config | ||
| run: | | ||
| # Set Magento-optimized PHP container based on version | ||
| case "${{ inputs.php-version }}" in | ||
| "8.1") | ||
| echo "container=magento/magento-cloud-docker-php:8.1-cli" >> $GITHUB_OUTPUT | ||
| ;; | ||
| "8.2") | ||
| echo "container=magento/magento-cloud-docker-php:8.2-cli" >> $GITHUB_OUTPUT | ||
| ;; | ||
| "8.3") | ||
| echo "container=magento/magento-cloud-docker-php:8.3-cli" >> $GITHUB_OUTPUT | ||
| ;; | ||
| esac | ||
| # Configure memory limit for DI compilation | ||
| MEMORY_LIMIT="${{ inputs.memory-limit }}" | ||
| if [ "$MEMORY_LIMIT" = "-1" ]; then | ||
| MEMORY_LIMIT="unlimited" | ||
| fi | ||
| echo "memory-limit=${MEMORY_LIMIT}" >> $GITHUB_OUTPUT | ||
| if [ "${{ inputs.debug }}" = "true" ]; then | ||
| echo "🔍 PHP configuration:" | ||
| echo " Version: ${{ inputs.php-version }}" | ||
| echo " Container: $(cat $GITHUB_OUTPUT | grep container | cut -d'=' -f2-)" | ||
| echo " Memory Limit: $(cat $GITHUB_OUTPUT | grep memory-limit | cut -d'=' -f2-)" | ||
| fi | ||
| - name: Configure deployment strategy | ||
| id: deployment-config | ||
| run: | | ||
| # Determine deployment strategy based on environment | ||
| case "${{ inputs.environment }}" in | ||
| "production") | ||
| echo "strategy=production" >> $GITHUB_OUTPUT | ||
| ;; | ||
| "staging") | ||
| echo "strategy=staging" >> $GITHUB_OUTPUT | ||
| ;; | ||
| "integration") | ||
| echo "strategy=integration" >> $GITHUB_OUTPUT | ||
| ;; | ||
| esac | ||
| if [ "${{ inputs.debug }}" = "true" ]; then | ||
| echo "🔍 Deployment configuration:" | ||
| echo " Environment: ${{ inputs.environment }}" | ||
| echo " Strategy: $(cat $GITHUB_OUTPUT | grep strategy | cut -d'=' -f2-)" | ||
| fi | ||
| # Pre-deployment preparation and validation | ||
| pre-deploy: | ||
| name: 🛠️ Pre-deployment Setup | ||
| runs-on: ubuntu-latest | ||
| needs: [prepare] | ||
| container: | ||
| image: ${{ needs.prepare.outputs.php-container }} | ||
| options: --user root | ||
| steps: | ||
| - name: Checkout code with full git history | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 # Full git history required for Magento Cloud | ||
| - name: Install Magento Cloud CLI | ||
| run: | | ||
| echo "📦 Installing Magento Cloud CLI..." | ||
| curl -fsS https://accounts.magento.cloud/cli/installer | php | ||
| export PATH=$HOME/.magento-cloud/bin:$PATH | ||
| echo "$HOME/.magento-cloud/bin" >> $GITHUB_PATH | ||
| # Verify installation | ||
| magento-cloud --version | ||
| echo "✅ Magento Cloud CLI installed successfully" | ||
| - name: Configure Magento Cloud CLI authentication | ||
| run: | | ||
| echo "🔐 Configuring Magento Cloud authentication..." | ||
| magento-cloud auth:login --token "${{ secrets.magento-cloud-cli-token }}" | ||
| echo "✅ Authentication configured" | ||
| - name: Validate project access | ||
| run: | | ||
| echo "🔍 Validating project access..." | ||
| magento-cloud project:info --project "${{ inputs.magento-cloud-project-id }}" --format plain | ||
| echo "✅ Project access validated" | ||
| - name: Configure PHP for Magento | ||
| run: | | ||
| echo "🔧 Configuring PHP for Magento..." | ||
| # Set memory limit for DI compilation | ||
| if [ "${{ needs.prepare.outputs.memory-limit }}" = "unlimited" ]; then | ||
| echo "memory_limit = -1" > /usr/local/etc/php/conf.d/memory-limit.ini | ||
| else | ||
| echo "memory_limit = ${{ needs.prepare.outputs.memory-limit }}" > /usr/local/etc/php/conf.d/memory-limit.ini | ||
| fi | ||
| # Magento-specific PHP settings | ||
| cat > /usr/local/etc/php/conf.d/magento.ini << 'EOF' | ||
| max_execution_time = 18000 | ||
| max_input_vars = 10000 | ||
| upload_max_filesize = 64M | ||
| post_max_size = 64M | ||
| realpath_cache_size = 10M | ||
| realpath_cache_ttl = 7200 | ||
| opcache.memory_consumption = 512 | ||
| opcache.max_accelerated_files = 60000 | ||
| opcache.consistency_checks = 0 | ||
| opcache.validate_timestamps = 0 | ||
| opcache.enable_cli = 1 | ||
| EOF | ||
| if [ "${{ inputs.debug }}" = "true" ]; then | ||
| echo "🔍 PHP configuration:" | ||
| php -i | grep memory_limit | ||
| php -i | grep max_execution_time | ||
| fi | ||
| - name: Install Composer dependencies | ||
| run: | | ||
| echo "📦 Installing Composer dependencies..." | ||
| debug="" | ||
| if [ "${{ inputs.debug }}" = "true" ]; then | ||
| debug="--verbose" | ||
| fi | ||
| # Use Composer with Magento-specific optimizations | ||
| composer install \ | ||
| --no-dev \ | ||
| --optimize-autoloader \ | ||
| --no-interaction \ | ||
| --prefer-dist \ | ||
| $debug | ||
| echo "✅ Composer dependencies installed" | ||
| - name: Apply ECE patches | ||
| if: inputs.apply-patches == true | ||
| run: | | ||
| echo "🩹 Applying ECE patches..." | ||
| debug="" | ||
| if [ "${{ inputs.debug }}" = "true" ]; then | ||
| debug="--verbose" | ||
| fi | ||
| # Apply Magento Cloud patches | ||
| if [ -f "vendor/magento/ece-tools/bin/ece-patches" ]; then | ||
| php vendor/magento/ece-tools/bin/ece-patches apply $debug | ||
| echo "✅ ECE patches applied successfully" | ||
| else | ||
| echo "⚠️ ECE patches tool not found, skipping patch application" | ||
| fi | ||
| - name: Run dependency injection compilation | ||
| if: inputs.di-compile == true | ||
| run: | | ||
| echo "⚙️ Running dependency injection compilation..." | ||
| debug="" | ||
| if [ "${{ inputs.debug }}" = "true" ]; then | ||
| debug="--verbose" | ||
| fi | ||
| # DI compilation with unlimited memory | ||
| php -dmemory_limit=-1 bin/magento setup:di:compile $debug | ||
| echo "✅ DI compilation completed successfully" | ||
| - name: Generate static content (if required) | ||
| run: | | ||
| echo "🎨 Checking for static content deployment..." | ||
| # Only run if in production mode or if static content is missing | ||
| if php bin/magento deploy:mode:show | grep -q "production" || [ ! -d "pub/static/_cache" ]; then | ||
| echo "Generating static content..." | ||
| php -dmemory_limit=-1 bin/magento setup:static-content:deploy -f | ||
| echo "✅ Static content generated" | ||
| else | ||
| echo "ℹ️ Static content generation skipped (developer mode or already exists)" | ||
| fi | ||
| # Deploy to Magento Cloud | ||
| deploy: | ||
| name: 🚀 Deploy to Magento Cloud | ||
| runs-on: ubuntu-latest | ||
| needs: [prepare, pre-deploy] | ||
| if: needs.pre-deploy.result == 'success' | ||
| environment: ${{ inputs.environment }} | ||
| container: | ||
| image: ${{ needs.prepare.outputs.php-container }} | ||
| options: --user root | ||
| outputs: | ||
| deployment-url: ${{ steps.deploy-info.outputs.url }} | ||
| deployment-id: ${{ steps.deploy-info.outputs.id }} | ||
| steps: | ||
| - name: Checkout code with full git history | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Configure Magento Cloud CLI | ||
| run: | | ||
| curl -fsS https://accounts.magento.cloud/cli/installer | php | ||
| export PATH=$HOME/.magento-cloud/bin:$PATH | ||
| echo "$HOME/.magento-cloud/bin" >> $GITHUB_PATH | ||
| magento-cloud auth:login --token "${{ secrets.magento-cloud-cli-token }}" | ||
| - name: Create NewRelic deployment marker (start) | ||
| if: inputs.newrelic-app-id != '' && secrets.newrelic-api-key != '' | ||
| run: | | ||
| echo "📊 Creating NewRelic deployment marker (start)..." | ||
| curl -X POST "https://api.newrelic.com/v2/applications/${{ inputs.newrelic-app-id }}/deployments.json" \ | ||
| -H "X-Api-Key: ${{ secrets.newrelic-api-key }}" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{ | ||
| "deployment": { | ||
| "revision": "${{ github.sha }}", | ||
| "changelog": "Magento Cloud deployment started", | ||
| "description": "Deployment to ${{ inputs.environment }} environment", | ||
| "user": "${{ github.actor }}" | ||
| } | ||
| }' | ||
| echo "✅ NewRelic deployment marker created" | ||
| - name: Deploy to Magento Cloud | ||
| id: deployment | ||
| run: | | ||
| echo "🚀 Starting deployment to ${{ inputs.environment }}..." | ||
| debug="" | ||
| if [ "${{ inputs.debug }}" = "true" ]; then | ||
| debug="--verbose" | ||
| fi | ||
| # Set project context | ||
| magento-cloud project:set-remote "${{ inputs.magento-cloud-project-id }}" | ||
| # Deploy based on environment type | ||
| case "${{ inputs.environment }}" in | ||
| "integration") | ||
| # Push to integration environment | ||
| echo "Deploying to integration environment..." | ||
| magento-cloud push --force --wait $debug | ||
| ;; | ||
| "staging"|"production") | ||
| # Push to staging/production branch | ||
| echo "Deploying to ${{ inputs.environment }} environment..." | ||
| magento-cloud push --environment "${{ inputs.environment }}" --force --wait $debug | ||
| ;; | ||
| esac | ||
| echo "✅ Deployment completed successfully" | ||
| - name: Get deployment information | ||
| id: deploy-info | ||
| run: | | ||
| echo "📋 Retrieving deployment information..." | ||
| # Get environment URL | ||
| URL=$(magento-cloud url --environment "${{ inputs.environment }}" --project "${{ inputs.magento-cloud-project-id }}" --pipe) | ||
| echo "url=${URL}" >> $GITHUB_OUTPUT | ||
| # Get deployment ID | ||
| DEPLOYMENT_ID=$(magento-cloud activity:list --environment "${{ inputs.environment }}" --type push --limit 1 --format csv --columns id --no-header | head -1) | ||
| echo "id=${DEPLOYMENT_ID}" >> $GITHUB_OUTPUT | ||
| if [ "${{ inputs.debug }}" = "true" ]; then | ||
| echo "🔍 Deployment information:" | ||
| echo " URL: ${URL}" | ||
| echo " Deployment ID: ${DEPLOYMENT_ID}" | ||
| fi | ||
| - name: Report deployment to CST (Confidentiality and Security Team) | ||
| run: | | ||
| # Determine CST endpoint - input overrides workspace variable | ||
| CST_ENDPOINT="${{ inputs.cst-endpoint }}" | ||
| if [ -z "$CST_ENDPOINT" ]; then | ||
| CST_ENDPOINT="${{ vars.CST_ENDPOINT }}" | ||
| fi | ||
| # Determine CST project key - input overrides workspace variable | ||
| CST_PROJECT_KEY="${{ inputs.cst-project-key }}" | ||
| if [ -z "$CST_PROJECT_KEY" ]; then | ||
| CST_PROJECT_KEY="${{ vars.CST_PROJECT_KEY }}" | ||
| fi | ||
| # Determine CST reporting key - input overrides workspace secret | ||
| CST_KEY="${{ inputs.cst-reporting-key }}" | ||
| if [ -z "$CST_KEY" ]; then | ||
| CST_KEY="${{ secrets.cst-reporting-token }}" | ||
| fi | ||
| # Only run CST reporting if endpoint, project key, and auth key are available | ||
| if [ -n "$CST_ENDPOINT" ] && [ -n "$CST_PROJECT_KEY" ] && [ -n "$CST_KEY" ]; then | ||
| echo "📡 Reporting deployment to CST (Confidentiality and Security Team)..." | ||
| # Construct full CST URL: endpoint/project_key/adobe-commerce | ||
| CST_FULL_URL="${CST_ENDPOINT}/${CST_PROJECT_KEY}/adobe-commerce" | ||
| # Send composer.lock file contents to CST endpoint | ||
| if [ -f "composer.lock" ]; then | ||
| curl -X POST "${CST_FULL_URL}" \ | ||
| -H "Authorization: Bearer ${CST_KEY}" \ | ||
| -H "Content-Type: application/octet-stream" \ | ||
| --data-binary @composer.lock | ||
| echo "✅ Deployment reported to CST systems at ${CST_FULL_URL}" | ||
| else | ||
| echo "⚠️ composer.lock not found, skipping CST reporting" | ||
| fi | ||
| else | ||
| echo "ℹ️ CST reporting skipped (missing endpoint, project key, or auth key)" | ||
| fi | ||
| - name: Create NewRelic deployment marker (complete) | ||
| if: inputs.newrelic-app-id != '' && secrets.newrelic-api-key != '' | ||
| run: | | ||
| echo "📊 Creating NewRelic deployment marker (complete)..." | ||
| curl -X POST "https://api.newrelic.com/v2/applications/${{ inputs.newrelic-app-id }}/deployments.json" \ | ||
| -H "X-Api-Key: ${{ secrets.newrelic-api-key }}" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{ | ||
| "deployment": { | ||
| "revision": "${{ github.sha }}", | ||
| "changelog": "Magento Cloud deployment completed successfully", | ||
| "description": "Deployment to ${{ inputs.environment }} completed at ${{ steps.deploy-info.outputs.url }}", | ||
| "user": "${{ github.actor }}" | ||
| } | ||
| }' | ||
| echo "✅ NewRelic deployment marker updated" | ||
| - name: Generate deployment summary | ||
| run: | | ||
| echo "## 🛍️ Magento Cloud Deployment Summary" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "| Property | Value |" >> $GITHUB_STEP_SUMMARY | ||
| echo "|----------|-------|" >> $GITHUB_STEP_SUMMARY | ||
| echo "| **Project ID** | ${{ inputs.magento-cloud-project-id }} |" >> $GITHUB_STEP_SUMMARY | ||
| echo "| **Environment** | ${{ inputs.environment }} |" >> $GITHUB_STEP_SUMMARY | ||
| echo "| **PHP Version** | ${{ inputs.php-version }} |" >> $GITHUB_STEP_SUMMARY | ||
| echo "| **ECE Patches** | ${{ inputs.apply-patches && '✅ Applied' || '❌ Skipped' }} |" >> $GITHUB_STEP_SUMMARY | ||
| echo "| **DI Compilation** | ${{ inputs.di-compile && '✅ Completed' || '❌ Skipped' }} |" >> $GITHUB_STEP_SUMMARY | ||
| echo "| **Deployment ID** | ${{ steps.deploy-info.outputs.id }} |" >> $GITHUB_STEP_SUMMARY | ||
| echo "| **Site URL** | [${{ steps.deploy-info.outputs.url }}](${{ steps.deploy-info.outputs.url }}) |" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "### 🔧 Technical Details" >> $GITHUB_STEP_SUMMARY | ||
| echo "- **Memory Limit**: ${{ needs.prepare.outputs.memory-limit }}" >> $GITHUB_STEP_SUMMARY | ||
| echo "- **Container**: ${{ needs.prepare.outputs.php-container }}" >> $GITHUB_STEP_SUMMARY | ||
| echo "- **Git Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY | ||
| echo "- **Deployed By**: ${{ github.actor }}" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| if [ "${{ inputs.newrelic-app-id }}" != "" ]; then | ||
| echo "### 📊 Monitoring" >> $GITHUB_STEP_SUMMARY | ||
| echo "- **NewRelic App ID**: ${{ inputs.newrelic-app-id }}" >> $GITHUB_STEP_SUMMARY | ||
| echo "- **Deployment Markers**: ✅ Created" >> $GITHUB_STEP_SUMMARY | ||
| fi | ||
| case "${{ inputs.environment }}" in | ||
| "production") | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "### 🌍 Production Deployment" >> $GITHUB_STEP_SUMMARY | ||
| echo "Your Magento store is now live at:" >> $GITHUB_STEP_SUMMARY | ||
| echo "**[${{ steps.deploy-info.outputs.url }}](${{ steps.deploy-info.outputs.url }})**" >> $GITHUB_STEP_SUMMARY | ||
| ;; | ||
| "staging") | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "### 🚀 Staging Environment" >> $GITHUB_STEP_SUMMARY | ||
| echo "Staging environment updated successfully:" >> $GITHUB_STEP_SUMMARY | ||
| echo "**[${{ steps.deploy-info.outputs.url }}](${{ steps.deploy-info.outputs.url }})**" >> $GITHUB_STEP_SUMMARY | ||
| ;; | ||
| *) | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "### 🔧 Integration Environment" >> $GITHUB_STEP_SUMMARY | ||
| echo "Integration environment deployed for testing:" >> $GITHUB_STEP_SUMMARY | ||
| echo "**[${{ steps.deploy-info.outputs.url }}](${{ steps.deploy-info.outputs.url }})**" >> $GITHUB_STEP_SUMMARY | ||
| ;; | ||
| esac | ||