A Composer trick to build code simultaneously for Acquia Site Factory and Pantheon
I knew that switching platforms from Acquia Site Factory to Pantheon would take a while to complete. The tasks of transferring code, files and databases could be largely automated; coordination with change managers, site owners and DNS administrators would require attention and time on the calendar. I designed a process to deploy code changes to both platforms simultaneously.
I had already concluded that we would use a Pantheon custom upstream, and created a new repository for that. I realized that the Pantheon custom upstream structure—namely managing Composer dependencies in
upstream-configuration/composer.json rather than in the project root—could also work for Acquia. I moved the Drupal root from
web/ in the codebase and Composer, and transferred all of the Drupal modules, themes, etc., into the upstream Composer file.
Acquia expects code in
docroot/. It was easy enough to move the
web/ folder to that location during the build process. But there was a new problem—everything in the
vendor/ folder now was pointing at the wrong place, so I did not get a happy Drupal site. I didn’t want to do a massive search and replace within thousands of files within vendor, so I wanted to change the destination of the installation during the Composer build process.
It took some wrangling, but I finally figured out to switch the destination folders using
composer config commands.
Building the codebase for Acquia
Following is an excerpt from
acquia-pipelines.yml, showing the basic steps involved for building the Acquia codebase (not using BLT, which probably changes this). First I move the web-root folder. Then I set the various Composer pieces (
extra.installer-paths) to the web-root location Acquia anticipates. From there I do my usual Composer install, and continue on with other build tasks specific to this installation. This results in a codebase that runs on Acquia Site Factory.
Building the codebase for Pantheon
I left the Acquia Pipelines jobs in place for Acquia, and wrote a new Bitbucket Pipeline job to construct a build artifact for Pantheon. This was slightly complicated by the fact that Acquia required that we commit all of the dependencies installed by Composer—the
vendor/ folder and all of the contrib modules and themes. Pantheon has an integrated Composer build process that handles these as part of their DevOps workflow, so I want to make sure that I’m not committing them.
Below is an excerpt from my
bitbucket-pipelines.yml. First I clone the Pantheon upstream into a temporary build directory. I then swap out its git-related files with those from the source repo. I have now transformed the source repo into the Pantheon upstream, and commit the changes to the upstream repo.
Our Acquia Pipeline job was already set to deploy automatically into our dev environment on Site Factory. I then ran a shell script that applied the upstream updates to all of our Pantheon sites (I’d later automate this as a GitHub Action).
Once we had all of our sites migrated over to Pantheon, I removed the Acquia Pipeline job and platform-specific files that were no longer needed. It would, however, be feasible to leave both processes in place if there was an ongoing need to support both platforms or others.