Introducing continuous integration

There is a huge difference between developing a small web application by yourself and being part of a big team of developers, managers, marketing people, and so on, that works around the same big web application. Working on an application used by thousands or millions of users has a clear risk: if you mess it up, there will be a huge number of unhappy affected users, which may translate into sales going down, partnerships terminated, and so on.

From this scenario, you can imagine that people would be scared when they have to change anything in production. Before doing so, they will make sure that everything works perfectly fine. For this reason, there is always a heavy process around all the changes affecting a web application in production, including loads of tests of all kinds.

Some think that by reducing the number of times they deploy to production, they can reduce the risk of failure, which ends up with them having releases every several months with an uncountable number of changes.

Now, imagine releasing the result of two or three months of code changes at once and something mysteriously fails in production: do you know where to even start looking for the cause of the problem? What if your team is good enough to make perfect releases, but the end result is not what the market needs? You might end up wasting months of work!

Even though there are different approaches and not all companies use them, let's try to describe one of the most famous ones from the last few years: continuous integration (CI). The idea is to integrate small pieces of work often rather than big ones every once in a while. Of course, releasing is still a constraint in your system, which means that it takes a lot of time and resources. CI tries to automatize this process as much as possible, reducing the amount of time and resources that you need to invest. There are huge benefits with this approach, which are as follows:

  • Releases do not take forever to be done, and there isn't an entire team focused on releasing as this is done automatically.
  • You can release changes one by one as they come. If something fails, you know exactly what the change was and where to start looking for the error. You can even revert the changes easily if you need to.
  • As you release so often, you can get quick feedback from everyone. You will be able to change your plans in time if you need to instead of waiting for months to get any feedback and wasting all the effort you put on this release.

The idea seems perfect, but how do we implement it? First, let's focus on the manual part of the process: developing the features using a version control system (VCS). The following diagram shows a very common approach:

Introducing continuous integration

As we already mentioned, a VCS allows developers to work on the same codebase, tracking all the changes that everyone makes and helping on the resolution of conflicts. A VCS usually allows you to have different branches; that is, you can diverge from the main line of development and continue to do work without messing with it. The previous graph shows you how to use branches to write new features and can be explained as follows:

  • A: A team needs to start working on feature A. They create a new branch from the master, in which they will add all the changes for this feature.
  • B: A different team also needs to start working on a feature. They create a new branch from master, same as before. At this point, they are not aware of what the first team is doing as they do it on their own branch.
  • C: The second team finishes their job. No one else changed master, so they can merge their changes straight away. At this point, the CI process will start the release process.
  • D: The first team finishes the feature. In order to merge it to master, they need to first rebase their branch with the new changes of master and solve any conflicts that might take place. The older the branch is the more chances of getting conflicts you will have, so you can imagine that smaller and faster features are preferred.

Now, let's take a look at how the automated side of the process looks. The following graph shows you all the steps from the merging into master to production deployment:

Introducing continuous integration

Until you merge your code into master, you are in the development environment. The CI tool will listen to all the changes on the master branch of your project, and for each of them, it will trigger a job. This job will take care of building the project if necessary and then run all the tests. If there is any error or test failure, it will let everyone now, and the team that triggered this job should take care of fixing it. The master branch is considered unstable at this point.

If all tests pass, the CI tool will deploy your code into staging. Staging is an environment that emulates production as much as possible; that is, it has the same server configuration, database structure, and so on. Once the application is here, you can run all the tests that you need until you are confident to continue the deployment to production. As you make small changes, you do not need to manually test absolutely everything. Instead, you can test your changes and the main use cases of your application.

Learning PHP 7
titlepage.xhtml
part0000.html
part0001.html
part0002.html
part0003.html
part0004.html
part0005.html
part0006.html
part0007_split_000.html
part0007_split_001.html
part0007_split_002.html
part0008_split_000.html
part0008_split_001.html
part0009.html
part0010.html
part0011.html
part0012.html
part0013_split_000.html
part0013_split_001.html
part0013_split_002.html
part0013_split_003.html
part0013_split_004.html
part0014_split_000.html
part0014_split_001.html
part0014_split_002.html
part0014_split_003.html
part0014_split_004.html
part0015_split_000.html
part0015_split_001.html
part0015_split_002.html
part0015_split_003.html
part0015_split_004.html
part0016_split_000.html
part0016_split_001.html
part0016_split_002.html
part0016_split_003.html
part0016_split_004.html
part0017_split_000.html
part0017_split_001.html
part0017_split_002.html
part0017_split_003.html
part0018.html
part0019_split_000.html
part0019_split_001.html
part0019_split_002.html
part0019_split_003.html
part0019_split_004.html
part0020_split_000.html
part0020_split_001.html
part0021_split_000.html
part0021_split_001.html
part0021_split_002.html
part0021_split_003.html
part0022.html
part0023_split_000.html
part0023_split_001.html
part0024_split_000.html
part0024_split_001.html
part0025_split_000.html
part0025_split_001.html
part0025_split_002.html
part0025_split_003.html
part0025_split_004.html
part0025_split_005.html
part0025_split_006.html
part0026.html
part0027_split_000.html
part0027_split_001.html
part0027_split_002.html
part0027_split_003.html
part0027_split_004.html
part0027_split_005.html
part0027_split_006.html
part0027_split_007.html
part0028_split_000.html
part0028_split_001.html
part0028_split_002.html
part0028_split_003.html
part0028_split_004.html
part0029_split_000.html
part0029_split_001.html
part0029_split_002.html
part0029_split_003.html
part0030_split_000.html
part0030_split_001.html
part0030_split_002.html
part0030_split_003.html
part0030_split_004.html
part0031_split_000.html
part0031_split_001.html
part0031_split_002.html
part0031_split_003.html
part0032.html
part0033_split_000.html
part0033_split_001.html
part0033_split_002.html
part0033_split_003.html
part0033_split_004.html
part0033_split_005.html
part0034_split_000.html
part0034_split_001.html
part0035.html
part0036.html
part0037_split_000.html
part0037_split_001.html
part0037_split_002.html
part0038_split_000.html
part0038_split_001.html
part0038_split_002.html
part0038_split_003.html
part0039_split_000.html
part0039_split_001.html
part0040.html
part0041_split_000.html
part0041_split_001.html
part0041_split_002.html
part0041_split_003.html
part0042_split_000.html
part0042_split_001.html
part0042_split_002.html
part0043.html
part0044.html
part0045_split_000.html
part0045_split_001.html
part0045_split_002.html
part0046_split_000.html
part0046_split_001.html
part0046_split_002.html
part0046_split_003.html
part0047_split_000.html
part0047_split_001.html
part0047_split_002.html
part0047_split_003.html
part0047_split_004.html
part0048.html
part0049.html
part0050_split_000.html
part0050_split_001.html
part0050_split_002.html
part0050_split_003.html
part0051.html
part0052.html
part0053_split_000.html
part0053_split_001.html
part0053_split_002.html
part0053_split_003.html
part0054.html
part0055.html
part0056_split_000.html
part0056_split_001.html
part0057_split_000.html
part0057_split_001.html
part0057_split_002.html
part0057_split_003.html
part0057_split_004.html
part0058_split_000.html
part0058_split_001.html
part0058_split_002.html
part0058_split_003.html
part0058_split_004.html
part0059_split_000.html
part0059_split_001.html
part0059_split_002.html
part0059_split_003.html
part0060_split_000.html
part0060_split_001.html
part0060_split_002.html
part0060_split_003.html
part0060_split_004.html
part0060_split_005.html
part0060_split_006.html
part0060_split_007.html
part0061_split_000.html
part0061_split_001.html
part0061_split_002.html
part0061_split_003.html
part0061_split_004.html
part0061_split_005.html
part0062_split_000.html
part0062_split_001.html
part0062_split_002.html
part0063.html
part0064_split_000.html
part0064_split_001.html
part0064_split_002.html
part0064_split_003.html
part0065_split_000.html
part0065_split_001.html
part0065_split_002.html
part0065_split_003.html
part0066_split_000.html
part0066_split_001.html
part0066_split_002.html
part0066_split_003.html
part0066_split_004.html
part0067_split_000.html
part0067_split_001.html
part0067_split_002.html
part0067_split_003.html
part0068.html
part0069_split_000.html
part0069_split_001.html
part0070.html
part0071_split_000.html
part0071_split_001.html
part0071_split_002.html
part0071_split_003.html
part0072_split_000.html
part0072_split_001.html
part0072_split_002.html
part0072_split_003.html
part0072_split_004.html
part0073_split_000.html
part0073_split_001.html
part0073_split_002.html
part0074_split_000.html
part0074_split_001.html
part0074_split_002.html
part0074_split_003.html
part0075_split_000.html
part0075_split_001.html
part0075_split_002.html
part0075_split_003.html
part0075_split_004.html
part0075_split_005.html
part0075_split_006.html
part0075_split_007.html
part0076_split_000.html
part0076_split_001.html
part0076_split_002.html
part0076_split_003.html
part0076_split_004.html
part0077.html
part0078.html
part0079_split_000.html
part0079_split_001.html
part0080.html
part0081_split_000.html
part0081_split_001.html
part0081_split_002.html
part0081_split_003.html
part0082_split_000.html
part0082_split_001.html
part0082_split_002.html
part0082_split_003.html
part0082_split_004.html
part0083_split_000.html
part0083_split_001.html
part0083_split_002.html
part0084_split_000.html
part0084_split_001.html
part0084_split_002.html
part0084_split_003.html
part0084_split_004.html
part0084_split_005.html
part0085_split_000.html
part0085_split_001.html
part0085_split_002.html
part0085_split_003.html
part0085_split_004.html
part0085_split_005.html
part0086.html
part0087.html
part0088_split_000.html
part0088_split_001.html
part0088_split_002.html
part0088_split_003.html
part0088_split_004.html
part0088_split_005.html
part0089_split_000.html
part0089_split_001.html
part0089_split_002.html
part0089_split_003.html
part0089_split_004.html
part0090_split_000.html
part0090_split_001.html
part0090_split_002.html
part0090_split_003.html
part0091.html
part0092_split_000.html
part0092_split_001.html
part0092_split_002.html
part0092_split_003.html
part0092_split_004.html
part0092_split_005.html
part0092_split_006.html
part0092_split_007.html
part0092_split_008.html
part0092_split_009.html
part0092_split_010.html
part0092_split_011.html
part0092_split_012.html
part0092_split_013.html
part0092_split_014.html
part0092_split_015.html
part0092_split_016.html
part0092_split_017.html
part0092_split_018.html
part0092_split_019.html
part0092_split_020.html
part0092_split_021.html
part0092_split_022.html
part0092_split_023.html
part0092_split_024.html