Table of Contents

    Rules : Scenario of Building an App

    CI/CD Rules

    Until now, you had read through the concept of continuous deployment.

    The main rules to be followed for building and deploying an application are listed in the upcoming cards. (Short summarization of CI and CD concepts).

    Codebase

    Rule: One codebase, many deploys.

    Codebase: Single repository (like subversion) or set of repositories (like Git).

    • One to one correlation must be maintained between codebase and application.

    • Codebase must remain same across each deployment (versions can be different).

    Dependencies

    Rule: Declare and isolate dependencies.

    • Maintain a dependency manager

      • To specify the libraries required for the app.

      • Enables a developer to check out the app's codebase.

    • Install language runtime and dependency manager as prerequisites.

    Configuration

    Rule: Store configuration information in environment variables (Env Var).

    Configuration includes:

    • Resource handles to the database, other backing services.

    • Credentials for external services like AWS S3.

    Configuration varies across deploys while code does not.

    Storing it in Env Var makes it easy to change without changing code.

    Backing Services

    Rule: Treat backing services as attached resources.

    Backing Services are resources that the application needs for its normal operation like:

    • Data stores (MySQL)

    • Messaging systems (RabbitMQ)

    • Email services (Postfix)

    • Caching systems (Memcached)

    Backing Services...

    Backing services are managed:

    • Locally by system administrators (like a database).

    • By the third party (like email services).

    Ensure for the app:

    • There must be no distinction between local and third party services.

    • Services must be easily swapped without any code change (local with a third party and vice versa).

    • Attach and detach services when required.

     
     

    Build, Release and Run

    Rule : Separate the build, release and run stages.

    Codebase gets transformed into a deploy element in three stages:

    Build stage:

    • Converts a code into an executable bundle.

    • Gets dependencies and compiles binaries.

    Build, Release and Run...

    Release stage:

    • Integrates the build with configuration.

    • After this stage, change is ready for immediate execution.

    Run stage (or runtime) :

    • Runs the application.

    Strictly separate build, release and run stages. For example, do not change a code at the run stage, as it cannot propagate back to the build stage.

     

    Port Binding

    Rule: Export services through port binding.

    At times web apps are executed inside a container. For example, Java apps may run inside Tomcat.

    Instead, the app could export services:

    • By binding to a port.

    • Listening to the requests coming in on that port.

    For example:

    • Tornado is used for Python.

    • Visit a service URL such as http://localhost:5000/ to access the service.

    Disposability

    Rule: Fast startup and graceful shutdown.

    • Start and stop application processes when required.

    • Enables robust production deploys (quick code or configuration deployment).

    Environment Parity

    Rule: Keep all environments as similar as possible.

    All environments such as dev, staging and production must use the same type, versions of backing services.