Originally published on the Consensus Enterprises blog.
Aegir is often seen as a stand-alone application lifecycle management (ALM) system for hosting and managing Drupal sites. In the enterprise context, however, it’s necessary to provide mutiple deployment environments for quality assurance (QA), development or other purposes. Aegir trivializes this process by allowing sites to easily be copied from one environment to another in a point-and-click fashion from the Web front-end, eliminating the need for command-line DevOps tasks, which it was designed to do.
Setting up the environments
An Aegir instance needs to be installed in each environment. We would typically have three (3) of them:
- Development (Dev): While generally reserved for integration testing, it is sometimes also used for development (e.g. when local environments cannot be used by developers or there are a small number of them).
- Staging: Used for QA purposes. Designed to be a virtual clone of Production to ensure that tagged releases operate the same way as they would there, before being made live.
- Production (Prod): The live environment visible to the public or the target audience, and the authoritative source for data.
(While outside the scope of this article, local development environments can be set up as well. See Try Aegir now with the new Dev VM for details.)
To install Aegir in each of these, follow the installation instructions. For larger deployments, common architectures for Staging and Prod would include features such as:
- Separate Web and database servers
- Multiple Web and database servers
- Load balancers
- Caching/HTTPS proxies
- Separate partitions for (external) storage of:
- The Aegir file system (
/var/aegir
) - Site backups (
/var/aegir/backups
) - Database storage (
/var/lib/mysql
)
- The Aegir file system (
- etc.
As these are all out of scope for the purposes of this article, I’ll save these discussions for the future, and assume we’re working with default installations.
Allowing the environments to communicate
To enable inter-environment communication, we must perform the following series of tasks on each Aegir VM as part of the initial set-up, which only needs to be done once.
Back-end set-up
The back-ends of each instance must be able to communicate. For that we use the secure SSH protocol. As stated on Wikipedia:
SSH is important in cloud computing to solve connectivity problems, avoiding the security issues of exposing a cloud-based virtual machine directly on the Internet. An SSH tunnel can provide a secure path over the Internet, through a firewall to a virtual machine.
Steps to enable SSH communication:
- SSH into the VM.
ssh ENVIRONMENT.aegir.example.com
- Become the Aegir user.
sudo -sHu aegir
- Generate an SSH key. (If you’ve done this already to access a private Git repository, you can skip this step.)
ssh-keygen -t rsa -b 4096 -C "ORGANIZATION Aegir ENVIRONMENT"
- For every other environment from where you’d like to fetch sites:
- Add the generated public key (
~/.ssh/id_rsa.pub
) to the whitelist for the Aegir user on the other VM so that the original instance can connect to this target.ssh OTHER_ENVIRONMENT.aegir.example.com
sudo -sHu aegir
vi ~/.ssh/authorized_keys
exit
- Back on the original VM, allow connections to the target VM.
sudo -sHu aegir
ssh OTHER_ENVIRONMENT.aegir.example.com
- Answer affirmatively when asked to confirm the host (after verifying the fingerprint, etc.).
- Add the generated public key (
Front-end set-up
These steps will tell Aegir about the other Aegir servers whose sites can be imported.
- On Aegir’s front-end Web UI, the “hostmaster” site, enable remote site imports by navigating to Administration » Hosting » Advanced, and check the Remote import box. Save the form. (This enables the Aegir Hosting Remote Import module.)
- For every other server you’d like to add, do the following:
- Navigate to the Servers tab, and click on the Add server link.
- For the Server hostname, enter the hostname of the other Aegir server (e.g.
staging.aegir.example.com
) - Click the Remote import vertical tab, check Remote hostmaster, and then enter
aegir
for the Remote user. - For the Human-readable name, you can enter something like
Foo's Staging Aegir
(assuming the Staging instance). - You can generally ignore the IP addresses section.
- Hit the Save button.
- Wait for the server verification to complete successfully.
All of the one-time command-line tasks are now done. You or your users can now use the Web UI to shuffle site data between environments.
Deploying sites from one environment to another
Whenever necessary, this point-and-click process can be used to deploy sites from one Aegir environment to another. It’s actually a pull method as the destination Aegir instance imports a site from the source.
Reasons to do this include:
- The initial deployment of a development site from Dev to Prod.
- Refreshing Dev and Staging sites from Prod.
Steps:
- If you’d like to install the site onto a new platform that’s not yet available, create the platform first.
- Navigate to the Servers tab.
- Click on the server hosting the site you’d like to import.
- Click on the Import remote sites link.
- Follow the prompts.
- Wait for the batch job, Import and Verify tasks to complete.
- Enable the imported site by hitting the Run button on the Enable task.
- The imported site is now ready for use!