Skip to content

Latest commit

 

History

History
61 lines (46 loc) · 3.42 KB

README.md

File metadata and controls

61 lines (46 loc) · 3.42 KB

Docker Layer Caching with Harness CI

This is a fork of grafana/grafana. This project can be used to demonstrate Docker Layer Caching in Harness CI pipelines.

This demo will build and push the Grafana Docker image to Docker Hub. The initial pipeline execution will take about seven minutes to build the cache. The second pipeline execution will take about thirty seconds.

Setting up this pipeline on Harness CI Cloud

  1. Create a GitHub Account or use an existing account

  2. Fork this repository into your GitHub account

  3. a. If you are new to Harness CI, signup for Harness CI

    • Select the Continuous Integration module and choose the Starter pipeline wizard to create your first pipeline using the forked repo from #2.
    • Go to the newly created pipeline and hit the Triggerstab. If everything went well, you should see two triggers auto-created. A Pull Requesttrigger and a Push trigger. For this exercise, we only need Pushtrigger to be enabled. So, please disable or delete the Pull Requesttrigger.

    b. If you are an existing Harness CI user, create a new pipeline to use the cloud option for infrastructure and setup the push trigger.

  4. Check the Docker Layer Caching documentation to learn how to enable the feature in your Harness account.

  5. Insert this YAML into your pipeline's stages section.

    - stage:
        identifier: Build
        type: CI
        name: Build
        description: ""
        spec:
          cloneCodebase: true
          platform:
            os: Linux
            arch: Amd64
          runtime:
            type: Cloud
            spec: {}
          execution:
            steps:
              - step:
                  identifier: Docker_Build
                  type: BuildAndPushDockerRegistry
                  name: Docker Build
                  spec:
                    connectorRef: YOUR_DOCKER_REGISTRY_CONNECTOR
                    repo: YOUR_NAMESPACE/grafana
                    tags:
                      - latest
                      - <+codebase.shortCommitSha>
                    caching: true

Replace YOUR_DOCKER_REGISTRY_CONNECTOR with your Docker connector ID.

Replace YOUR_NAMESPACE with your namespace (usually your Docker Hub username).

  1. Save your changes and run your pipeline by selecting Run. This initial pipeline execution must build and push all Docker layers to the cache, it will complete in about seven minutes.

  2. Confirm that the Grafana Docker image was published to your Docker registry with two tags (latest as well as the short commit SHA).

  3. Add a comment to packaging/docker/run.sh in the main branch and push your change, this will trigger your pipeline in Harness CI. This time, only the last few layers of the Docker image will be rebuilt, all other layers will be pulled from the cache. The pipeline will complete in about thirty seconds.