Docker on Amazon Web Services
上QQ阅读APP看书,第一时间看更新

Testing and building the application using Docker

In the previous chapter, you gained a good understanding of what the sample application is, and how to test and run the application in your local development environment. You are now ready to start creating a Docker workflow that will test, build, and package your application into a Docker image.

It is important to understand that whenever you are packaging an application into a Docker image, the best-practice approach is to reduce or eliminate all development and test dependencies from your final packaged application. By my own convention, I refer to this packaged application—free of test and development dependencies—as a release image, which supports the paradigm of continuous delivery, where every successful build should be a release candidate that is able to be published to production if required.

To achieve this goal of creating a release image, an approach that works well is to split the Docker build process into two stages:

  • Test stage: This stage has all the test and development dependencies available to compile and build your application source into an application artifact, and run unit and integration tests.
  • Release stage: This stage copies the tested and built application artifact(s) from the test stage into a minimalistic runtime environment configured appropriately for running the application in production.

Docker natively supports such an approach using a feature called multi-stage builds, and this is the approach we will adopt in this book. For now, we will focus on the test stage, and move on to the release stage in the next section.