Table of contents
Tools
You will need git, composer, php. Use the links below to install or use UMD Virtual Workspace which has the necessary tools installed.
- Follow the instructions at https://www.atlassian.com/git/tutorials/install-git to get git installed
- Install php 7 or 8, https://www.php.net/manual/en/install.php
- Install composer https://getcomposer.org/doc/00-intro.md
- Create a SSH key certificate to checkout your site code from Pantheon
- Open a terminal/shell window and run the command:
- ssh-keygen -b 2048 -t rsa
- This command works on Linux, MacOS, and Windows 10.
- Unless you have reason to change it, leave the default location of
~/.ssh/id_rsa
as is. If the command says the key already exists, you can either overwrite it, or continue to the next step with your existing key. - A passphrase is recommended to provide greater security, but can conflict with tools that cannot handle them.
- Once the files are created, copy the contents of ~/.ssh/id_rsa.pub to your clipboard.
- Linux and Mac users can catthe file to the terminal and copy the output:
- cat ~/.ssh/id_rsa.pub
- Windows users can achieve the same result with type:
- type .ssh\id_rsa.pub
- Linux and Mac users can catthe file to the terminal and copy the output:
- ssh-add ~/.ssh/id_rsa
- Cut and paste the certificate into pantheon, this is done under your account page
- Open a terminal/shell window and run the command:
The build process on Pantheon is done with Composer, the build prioritizes the composer.json and composer.lock file in the root of the repo, and builds out based on those two files.
After checking out a site repo from the Pantheon dashboard under the 'connection info' button, composer can be used to to install and uninstall modules via the command line from with the site repo directory, some useful commands are below:
Add a module
composer require drupal/admin_toolbar
drupal/admin_toolbar
tells composer what repository the package is in, in this case drupal, and what exactly to install, in this example admin_toolbar
Advanced example:
composer --ignore-platform-reqs -W require drupal/admin_toolbar:^3
- --ignore-platform-reqs allows you to avoid local platform compatibility, the site will be built on Pantheon so this allows you to avoid any local issues
- -W is a shortcut for --with-all-dependencies, this pulls in all dependencies and requirements for a module, not just the module itself
- :^3 is a version constraint. Without a number listed, composer will get the latest version available. In this example, ^3 tells composer to get the lastest version on the 3.x branch, but not anything above the major version 3. In most cases, letting composer install the latest version is best practice, but in some cases it may be necessary to limit the versioning. Do note, limiting the versioning with a :^x means composer will never update the module past x automatically. When an update is eventually desired, composer.json must be edited to remove the constraint.
Remove a module
composer remove drupal/admin_toolbar
- With composer remove, the code for a module will be removed from the site code-base. NOTE: any module configuration will remain as config is stored in the site database. It is best to uninstall a module from the site web console by utilizing the 'uninstall' menu under the 'Extend' top menu item within the site to remove all database config before uninstalling a module via composer. Not removing the configuration can cause errors as the site will still be expecting the module to be present based on the config.
Add libraries via composer
Adding libraries is possible via composer, this allows composer to download and install the library files, freeing you from having to manage them. Adding libraries to the composer.json is a bit more complicated then adding a module, detailed documentation can be found on the Drupal.org page.
Composer update
To update all modules in your composer file to get all new versions for updates and security releases, you can run the update command. You should also run the update command once all needed additions and removals have been done via composer, to ensure all your changes work correctly and have been picked up. The update command should be run via:
composer update
This command will run the composer.json file, and build out the composer.lock file, downloading and installing all specific modules and dependencies that are listed as needed for the site. If you do not wish to install all the files locally, you can run composer update --no-install. Any updated versions since you last ran this will also be grabbed.
Commit and push
After installing and/or removing all modules with composer, and running composer update, you are now ready to commit your changes to the site repo and push them back to the Pantheon server to be build. From your git repo on the command line, or from your git GUI, you should see two files that have been changed, composer.json and composer.lock (if you see other files being changed, please see the pitfalls section below).
- Adding your changes with "
git add file_name
" or "git add .
"
- "git add ." adds all changes made at once
- Commit the changes to composer.json and composer.lock with
git commit -m "your message here"
, and give the commit a message describing what changes were done between the "".
- the -m command is for leaving the commit message
- Once you have committed them, you can push your changes to Pantheon with
git push
.
Once you push your changes, Pantheon will run the composer.json on their servers, and the changes will be deployed to the dev version of your site for review.
Updating the Test and Live environments
Once the changes have been pushed to the main branch and built on the Pantheon servers, they will appear on within the dev site environment. The dev site should be then tested to make sure the changes work as expected, and everything is still correct with the site. Once this testing is completed, the changes need to be pushed to the test environment, and finally to the live environment so that the public facing site receives the updates. To deploy the updates, click on the 'Test' tab on the site Pantheon dashboard, the first pane there should be the deploy section. You will see a list of changes that will be deployed, and a box for deploy messages. Write a message as desired, and click the 'deploy code' button. Once the code has been deployed on the test instance, repeat the same process for the live environment via the "Live" tab.
Quick version
- check out or update the site repo by changing into the site directory and running "git pull", without the " marks
- run "
composer --ignore-platform-reqs -W require drupal/admin_toolbar
" or "composer remove drupal/admin_toolbar
" as needed to install or remove modules - run "
composer update
" to build out the local site composer files - add, commit and push the changes (which should only be to composer.json and composer.lock) to the Pantheon repo.
- deploy the changes to the test and live environments via the Pantheon dashboard site tabs
Potential pitfalls and ways to avoid
The Pantheon build process can balk anywhere it encounters files that it 'expects' to be from Composer being committed in the git repo itself. Changing and committing files in directories where Composer puts files, especially force commits with git -f force, can cause problems. It is best to avoid using git -f force as a general rule.
If you have custom code for themes or modules, they should be added to the directories below:
/web/sites/default/modules/custom
/web/sites/default/themes/custom
/web/sites/default/libraries
Pantheon also does not change its build restrictions based on changes to the .gitignore file. Removing lines from the .gitignore and committing files in those now tracked directories can still lead to the Pantheon build process issues. We recommand avoiding making changes to the .gitignore file.