This is Lesson 2 of Deploying an Application in Drupal 8.
In this lesson we will:
- Generate a deployment artifact
- Push the artifact to Acquia Cloud Platform
Generate a production-ready deployment artifact for a Drupal 8 application.
In order to complete this lesson you will need:
- A Drupal 8 application that is ready for deployment
- Access to an Acquia Cloud subscription
- PHP 7.2 or later (php 7.3 recommended - see Acquia's EOL schedule)
The following tools are not required, but are recommended:
Using Acquia BLT (recommended)
Specifically, the command will:
- Remove development dependencies
- Optimize your composer autoload files
- Remove extraneous files from the application
- Execute frontend compilation tasks
- Cut a git tag for you
- Push that tag to your hosting environment
For those not using Acquia BLT you should, at a minimum, use Composer to remove development dependencies and optimize your application’s autoloader:
composer install --no-dev --optimize-autoloader
This will install only the dependencies in your composer.json’s “require” array (not in the “require-dev” array) and will optimize Composer’s autoloader, which significantly improves application performance.
You should also consider performing the following manual steps:
- Remove Drupal core text files, like CHANGELOG.txt, from your docroot directory. These can inadvertently reveal your exact Drupal core version to malicious site visitors.
- Change/Restrict any reachable path for security purposes.
- Compile front end source code (like SASS) into front end assets (like CSS).
After you’ve manually prepared your codebase for production, you will need to create a new Git tag.
Using a git tag for deployment is a best practice because tags are immutable. In other words, after it has been created a tag cannot be changed. For instance, using a tag will prevent someone from accidentally pushing a new commit to a branch that is deployed to your production environment. This cannot happen with a tag.
git tag 1.0.0 -m 'This is the first major release!'
Now that your tag is cut, you can push it to Acquia Cloud Platform:
git push origin 1.0.0
Naming your releases
You should use a naming convention for your tags that works well for your team. The most popular (and recommended option) is Semantic Versioning (semver). In short, semver provides a set of rules for naming tags. The rules help you track:
- The order in which releases are made
- Releases that introduce backwards incompatible changes (major)
- Releases that introduce new, backwards compatible functionality (minor)
- Releases that provide backwards compatible bug fixes (patch)
Tags using semver take the form MAJOR.MINOR.PATCH. For more information, see semver.org.
In combination with Composer version constraints, you can use semver to ensure that your application’s dependencies are never accidentally updated to a backwards incompatible version.
Now that you have a deployment artifact, you’re ready to deploy it on your Acquia Cloud Platform non-production environment! Reminder: Before moving to Production, ensure you take a database backup of your Production environment first.