The default strategy generates static content during the deploy phase when the site is in maintenance mode; This deployment strategy takes time to write the content directly to the mounted pub/static directory.
Describe the reason for moving generation static content to the build phase. Consider the way to do this and show the result (timeline)
Generating static content during the build phase with minified HTML is the optimal configuration for zero-downtime deployments, also known as the ideal state. Instead of copying files to a mounted drive, it creates a symlink from the ./init/pub/static directory.
By default, the STATIC_CONTENT_SYMLINK environment variable is set to true. After generating the static content during the build phase, it creates a symlink to the content folder.
Generating static content requires access to themes and locales. Magento stores themes in the file system, which is accessible during the build phase; however, Magento stores locales in the database. The database is not available during the build phase. In order to generate the static content during the build phase, you must use the config:dump command in the package to move locales to the file system. It reads the locales and saves them in the app/etc/config.php file.
To configure your project to generate SCD on build:
Verify your settings by running the Smart wizard for the ideal state.
php ./vendor/bin/ece-tools wizard:ideal-state
SKIP_HTML_MINIFICATION
in the .magento.env.yaml
file (Default: true, for ece-tools 2002.0.13 and later).
Enables or disables copying static view files to the <magento_root>/init/ directory at the end of the build stage. If set to true files are not copied and HTML minification is available on request. Set this value to true to reduce downtime when deploying to Staging and Production environments.
You can improve the SCD load time during the deployment process if you skip copying the static view files in the var/view_preprocessed directory and generate minified HTML when requested
SCD_THREADS
- Sets the number of threads for static content deployment. Increasing the number of threads speeds up static content deployment; decreasing the number of threads slows it down.
SCD_MATRIX
- You can configure multiple locales per theme as long as the theme is not excluded using the SCD_EXCLUDE_THEMES variable during build. This is ideal if you want to speed up the build process by reducing the amount of unnecessary theme files. For example, you can build the magento/backend theme in English and a custom theme in other languages.
stage:
build:
SCD_MATRIX:
"magento/backend":
language:
- en_US
- nb_NO
# not deploy a theme:
"magento/blank": [ ]
STATIC_CONTENT_SYMLINK
(Default: true) Generates symlinks for static content. This setting is vital in the Pro Production environment for the three-node cluster.
When this variable is set to false, it must copy every file during the deployment, which increases deployment time. Setting SCD_ON_DEMAND to true disables this variable.
If you generate static content during the build phase, it creates a symlink to the content folder. If you generate static content during the deploy phase, it writes directly to the content folder. Generating static content on demand disables this variable.
SKIP_SCD
in the .magento.env.yaml
- skips static content deployment during the build/deploy phases
stage:
build:
SKIP_SCD: true
# or
deploy:
SKIP_SCD: true
SCD_ON_DEMAND
in the .magento.env.yaml
file (Default: false) enable generation of static content when requested by a user
Generating SCD on demand is optimal for a development workflow in the Integration environment. It decreases deployment time so that you can quickly review your implementations and run integration tests. Enable the SCD_ON_DEMAND environment variable in the global stage of the .magento.env.yaml file. The SCD_ON_DEMAND variable overrides all other configurations related to SCD and clears existing content from the ~/pub/static directory.
When using the SCD on-demand strategy, it helps to preload the cache with pages you expect to request, such as the home page. Add your list of expected pages in the WARM_UP_PAGES environment variable in the post-deploy stage of the .magento.env.yaml file. (https://devdocs.magento.com/guides/v2.3/cloud/deploy/static-content-deployment.html)
The SCD_ON_DEMAND variable skips the SCD and the STATIC_CONTENT_SYMLINK in both phases (build and deploy), clears the pub/static and var/view_preprocessed folders, and writes the following to the app/etc/env.php file:
return array(
...
'static_content_on_demand_in_production' => 1,
...
);
Documentation: