Move SCD to Build Phase
Understanding the default SCD process, config:dump, smart wizards, time measurements, and how to optimize for minimal downtime.
SCD Build Phase Optimization
Default SCD Process and Downtime Impact
Build vs Deploy Phase Capabilities
Both build and deploy phases can generate static content, but there's a critical difference:
| Phase | Database Available? | Site Status | Default? |
|---|---|---|---|
| Build | NO - Requires config:dump | Site UP | No (requires setup) |
| Deploy | YES - Always available | Site DOWN (maintenance) | Yes (default) |
Critical Understanding
To generate static content, Magento needs to know what themes and locales are in use. This requires:
- Database connection (readily available in deploy phase)
- OR app/etc/config.php with scope data (from
./vendor/bin/ece-tools config:dump)
Why Deploy Phase is Default (But Not Best)
The Easiest ≠ The Best
Deploy Phase (Default)
- ✓ Easy - database readily available
- ✓ No setup required
- ✗ Site is DOWN during SCD
- ✗ Significant downtime
- ✗ SCD time = downtime
Build Phase (Optimal)
- ✓ Site stays UP during SCD
- ✓ Minimal downtime
- ✓ More secure (read-only)
- ✗ Requires config:dump setup
- ✗ Small config overhead
Process to Move SCD to Build Phase
5-Step Process
Prerequisites
- Access to production environment via SSH
- Git repository access
- Understanding of deployment workflow
Step 1: SSH into Production
magento-cloud ssh -e production
Step 2: Run config:dump
./vendor/bin/ece-tools config:dump
What config:dump Does
- Runs
bin/magento app:config:dump - Filters configuration to ensure ONLY stores and websites are saved
- Updates
app/etc/config.phpwith scope data
Step 3: Copy app/etc/config.php
Download the generated file to your local project:
# From production server
cat app/etc/config.php
# Or use magento-cloud CLI to download
magento-cloud ssh -e production "cat app/etc/config.php" > app/etc/config.php
Step 4: Commit to Git
git add app/etc/config.php
git commit -m "Add scope configuration for build-phase SCD"
git push origin master
Step 5: Deploy
The next deployment will automatically build static content in the build phase!
Result
Static content is now generated during build phase (site UP), not deploy phase (site DOWN). Downtime dramatically reduced!
Smart Wizards
ece-tools Optimization Wizards
Smart wizards help optimize deployment and operation of Cloud-hosted websites.
1. wizard:ideal-state
Command: ./vendor/bin/ece-tools wizard:ideal-state
Checks:
- Static-content deploy happens in build stage
- post_deploy hook is configured
- SKIP_HTML_MINIFICATION is true
Note: This check runs as validator in build:generate command. Failure outputs warning but doesn't stop build.
2. wizard:master-slave
Command: ./vendor/bin/ece-tools wizard:master-slave
Checks:
- MySQL slave connections configured
- Redis slave connections configured
3. wizard:scd-on-demand
Command: ./vendor/bin/ece-tools wizard:scd-on-demand
Output: "SCD on demand is (enabled or disabled)."
Purpose: Quickly check if SCD_ON_DEMAND is enabled
4. wizard:scd-on-build
Command: ./vendor/bin/ece-tools wizard:scd-on-build
Uses: Global stage ScdOnBuild validator
Checks:
- SCD_ON_DEMAND is disabled
- SKIP_SCD is disabled
- app/etc/config.php exists
- app/etc/config.php contains scope configurations
5. wizard:scd-on-deploy
Command: ./vendor/bin/ece-tools wizard:scd-on-deploy
Uses: Global stage ScdOnDeploy validator
Checks:
- SCD_ON_DEMAND is disabled
- SKIP_SCD is disabled
- Build-phase SCD is disabled
Reasons to Move SCD to Build Phase
Two Primary Benefits
1. Reduce Downtime
Impact: Dramatic reduction in deployment downtime
- SCD happens while site is still UP
- Deploy phase only runs migrations and config updates
- Can reduce downtime by 60-80%!
- Better user experience during deployments
2. Increased Security
Security Benefit: Pre-generated static content is more secure
- Static content files are read-only
- Cannot change files after generation
- Reduces attack vector for MageCart-esque problems
- Prevents malicious code injection into static files
MageCart Protection
Pre-generated, read-only static content prevents attackers from injecting malicious JavaScript to steal credit card data during checkout (common MageCart attack vector).
Time Measurements
Real-World Performance Data
Data from vanilla Magento install on integration branch with sample data:
| Configuration | Build | Deploy | Post-Deploy | Total | SCD Time |
|---|---|---|---|---|---|
| SCD on Deploy, Skip Minify | 01:11 | 06:46 | 00:02 | 08:37 | 05:18 |
| SCD on Deploy, Minify | 01:10 | 07:31 | 00:02 | 09:20 | 06:04 |
| SCD on Build, Skip Minify | 01:52 | 00:48 | 00:02 | 03:22 | 00:41 |
| SCD on Build, Minify | 01:58 | 01:46 | 00:02 | 04:27 | 00:41 |
| SCD on Demand | 01:14 | 00:39 | 00:02 | 02:31 | 00:00 |
Key Insights
- SCD on Deploy: 06:46 downtime (site in maintenance)
- SCD on Build: 00:48 downtime (83% reduction!)
- Total time: 08:37 vs 03:22 (61% faster)
- Note: Disparity is MUCH GREATER with multiple themes/locales
Production Reality
For basic Magento Cloud deploy, building static content on deploy takes almost a minute extra downtime. With multiple themes and locales, this can be 5-10+ minutes!
SKIP_HTML_MINIFICATION Configuration
Additional Deployment Optimization
What It Does
Setting SKIP_HTML_MINIFICATION to true (default) prevents an additional file copy in deploy phase.
When HTML is Minified (SKIP_HTML_MINIFICATION = false):
- Files copied from
init/var/view_preprocessedtovar/view_preprocessed - Takes additional (minimal) time during deploy
- Reduces downloaded bytes for users
Trade-off Decision
HTML is NOT minified by default. Merchants must decide if fewer downloaded bytes justify slightly longer deploy time.
Recommendation: Keep SKIP_HTML_MINIFICATION = true for faster deploys. Use Varnish/CDN compression instead.
Practical Experience Exercise
Step-by-Step Testing
Part 1: Baseline (Deploy Phase SCD)
- Ensure NO scope data (stores/websites/groups) in
app/etc/config.php - Deploy code to Cloud
- Check time between maintenance mode enabled and disabled
- Record the downtime
Part 2: Optimized (Build Phase SCD)
- Use
ece-tools config:dumpto generateapp/etc/config.php - Copy file to local repository
- Push to Cloud
- Static content now built in build phase
- Record the new (much shorter) downtime
Part 3: Verify Configuration
For non-vanilla projects, ensure:
SCD_ON_DEMAND=== falseSKIP_HTML_MINIFICATION=== trueSKIP_SCD=== false (in .magento.env.yaml build stage)SCD_STRATEGY=== compact
Exam Tips
Key Points to Remember
- Default: SCD in deploy phase (easy but causes downtime)
- Optimal: SCD in build phase (requires config:dump, minimal downtime)
- config:dump: Generates app/etc/config.php with scope data
- 5 steps: SSH, config:dump, copy, commit, deploy
- Smart wizards: ideal-state, master-slave, scd-on-demand, scd-on-build, scd-on-deploy
- wizard:ideal-state: Checks build SCD, post-deploy hook, SKIP_HTML_MINIFICATION
- Benefits: Reduce downtime (60-80%), increase security (read-only)
- Downtime comparison: 06:46 (deploy) vs 00:48 (build) - 83% reduction
- SKIP_HTML_MINIFICATION: Default true, prevents file copy in deploy
- config:dump filters: Only stores and websites saved, not all config
- Security benefit: Read-only files prevent MageCart attacks
- setup:upgrade: Must still run in deploy phase (unavoidable)