Reader small image

You're reading from  Drupal 10 Masterclass

Product typeBook
Published inDec 2023
PublisherPackt
ISBN-139781837633104
Edition1st Edition
Tools
Concepts
Right arrow
Author (1)
Adam Bergstein
Adam Bergstein
author image
Adam Bergstein

Adam Bergstein is a product engineering leader and an architect. He has been a long-time Drupal community member, a routine speaker at Drupal community events around the globe, and provided keynotes for several events. He has maintained and contributed to many Drupal projects, including Password Policy, Taxonomy Menu, and more. Adam is the lead of Simplytest, a free service, and a project that offers Drupal community members testing sandboxes. He has also worked for both agencies building Drupal applications and Drupal service providers building Drupal-related products. He has led the Drupal Community Governance Task Force and is serving a term as a community board member of the Drupal Association.
Read more about Adam Bergstein

Right arrow

Git, Drush,
Composer, and DevOps

Much of the book so far has covered installing and configuring Drupal to meet a variety of use cases. However, even if you are not a developer, it can be difficult to maintain a Drupal application or contribute to the community without some basic technical skills. While this is an advanced topic, a brief primer in technologies such as Git, Drush, and Composer that enable developers can serve as a foundational launchpad into future development practices. These technologies bridge development and operations through practices known as DevOps. Getting started with this technology helps work toward the 80/20 rule, as discussed in previous chapters.

In this chapter, we’re going to cover the following main topics:

  • Git basics
  • Drush basics
  • Composer basics
  • DevOps practices

Technical requirements

This chapter moves beyond installing, using, and configuring Drupal. Many of the items in this chapter run on the command line through a terminal and are well-suited for Mac and Linux machines. Support for Windows exists, but Mac and Linux have well-vetted paths adopted by many in the Drupal community.

Technical requirements change by tool. For instance, Git may have certain system dependencies that are different from a PHP-based tool such as Composer. Much of the requirements are abstracted by installers that run on the local operating system and set up the tools.

Some commands may require Secure Shell (SSH), either to access a machine remotely or for use by the tool on the local system to connect to remote systems. This is often important for connecting to environments that run Drupal applications or working with code repositories. Configuring SSH often needs to be set up locally and on remote systems. Some SaaS vendors offer user interfaces that allow...

Git basics

Git is a distributed code versioning system. A repository is what stores the code, which is revised by changes known as commits. Each repository can configure remotes, which help synchronize code between repositories by fetching code from one repository to another. Remotes communicate via HTTPS with basic authentication credentials or the SSH protocol, which can leverage SSH keys. There is significant documentation on the internet on generating SSH keys and configuring SSH in Git that changes, based on operating systems and hosted Git platforms. Repositories maintain branches that help maintain a series of commits that relate to a change. Code in a branch is often merged into a main branch, which serves as a baseline for code to be accepted into a repository.

SaaS vendors have helped make Git more ubiquitous. Vendors such as GitHub and GitLab run managed Git repositories with a UI and various complementary features. It is common for a Drupal application to manage code...

Drush basics

Drush is a command-line tool that runs operations on a Drupal site. Because Drupal has a backend administrative area, users with the appropriate permissions can log in and operate a Drupal application. However, there are times when an application is unavailable, such as when it has pending database updates or requires a cache clear. Also, developers want to be able to run commands remotely and in scripts during events such as code deployments, without having to subsequently log in through the web application.

Operations is an overloaded term in technology, but with Drush, operations are focused on actions that run on the Drupal application – things such as logging in as a user, clearing the cache, or updating configuration from code to the application. Drush does not manage code in Drupal.

Like Git, Drush can leverage SSH to manage remotes. This feature is known as site aliases in Drush. Site aliases are helpful for developers who work on multiple Drupal applications...

Composer basics

Composer is a command-line tool for managing code in PHP-based applications such as Drupal. PHP has a vast ecosystem of components, libraries, and so on, including the catalog of Drupal projects and various Symfony components used by Drupal. Like a package manager, Composer helps assemble and update the PHP-based parts of an application.

Composer starts with a project. Not to be confused with a Drupal project, a Composer project is the high-level scaffolding for an application. Drupal applications are initialized as a Composer project. Composer projects have installed packages, and each package has its own dependencies – all of which can be managed by Composer through Composer projects.

Once a Composer project is initialized, Composer has a few key constructs. A composer.json file manages a developer-friendly list of projects, versions, and constraints for the Drupal application. A constraint in Composer is a set of directives defined per project to help...

DevOps practices

Historically, software engineers would delegate management, coordination, and execution of releases to operators. The practice of DevOps brought those practices together, primarily through continuous learning and the use of automation. Summarizing DevOps can be challenging, given it spans a set of practices and technologies that enable that practice. At a high level, it manages operations in code through configuration and scripts. Both development and operations teams can perpetually learn from issues that arise and update code based on that knowledge. This philosophy promotes consistency, given the same code is used repeatedly to perform the same actions on repeat.

Drupal best practices have evolved as DevOps has become more emergent. DevOps for Drupal applications closely align with events found in GitOps, practices tied to continuous integration, and the desire to have repeatable and frequent code deployments. Developer workflows often create new branches, review...

Summary

Git, Drush, and Composer all are tools that Drupal developers are required to learn. Each of the tools handles different aspects of development. Git manages distributed code versioning from local systems through deployments. Drush manages operations that run on Drupal applications. Composer manages Drupal’s projects, dependencies, and code. All of these can be combined to do automation, which is common for consistency in code deployments.

The next chapter explores creating custom modules with Drupal’s development framework.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Drupal 10 Masterclass
Published in: Dec 2023Publisher: PacktISBN-13: 9781837633104
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Adam Bergstein

Adam Bergstein is a product engineering leader and an architect. He has been a long-time Drupal community member, a routine speaker at Drupal community events around the globe, and provided keynotes for several events. He has maintained and contributed to many Drupal projects, including Password Policy, Taxonomy Menu, and more. Adam is the lead of Simplytest, a free service, and a project that offers Drupal community members testing sandboxes. He has also worked for both agencies building Drupal applications and Drupal service providers building Drupal-related products. He has led the Drupal Community Governance Task Force and is serving a term as a community board member of the Drupal Association.
Read more about Adam Bergstein