Docker Image Automation

Purpose

This subtopic addresses the need for an automated, reliable, and efficient mechanism to build, tag, cache, and push Docker images used in deploying blockchain node services, indexers, and APIs. In the broader context of deployment automation, Docker Image Automation ensures that container images are consistently created with proper versioning and caching, minimizing build times and avoiding redundant uploads. It tackles challenges such as verifying existing image tags to prevent unnecessary rebuilds and managing multi-tag images essential for Kubernetes deployments.

Functionality

At its core, Docker Image Automation provides utilities to:

Key Workflow Example

  1. Tag Existence Check:

    Before building an image, the system queries the Docker Hub API to verify if an image tag already exists.

    const exists = await hasTag('username/my-image', 'v1.0.0')
    if (!exists) {
      // Proceed with build and push
    }
    
  2. Image Building and Tagging:

    The build function constructs Docker CLI arguments, incorporating:

    • Multiple tags (-t image:tag).

    • Build arguments (--build-arg).

    • Cache layers (--cache-from).

    • Custom Dockerfile if provided (-f Dockerfile).

    • Build context directory.

    It then runs `docker build` with these parameters and environment variables.

  3. Image Pushing:

    After successful build, all tags are pushed to the Docker registry using docker push.

  4. Integration with Pulumi Deployment:

    Higher-level functions use these utilities to build base images tagged with content hashes to ensure uniqueness and cacheability, as seen in:

    if (!(await hasTag(baseImage, baseTag))) {
      await buildAndPushImage({ /* ... */ })
    }
    

This process reduces redundant builds and network usage by skipping image creation when an exact tag is already published.

Integration

Docker Image Automation complements the broader **Deployment Automation** topic by providing the foundational step of creating container images that Kubernetes will deploy as StatefulSets or services. It integrates tightly with:

This subtopic introduces the critical feature of **remote tag existence checks** (`hasTag`) to avoid unnecessary builds, which is not covered by other deployment automation aspects. Also, the detailed handling of multi-tag builds with caching is unique here.

Diagram

flowchart TD
  Start[Start Deployment] --> CheckTag[Check if Image Tag Exists]
  CheckTag -->|Tag Exists| SkipBuild[Skip Build and Push]
  CheckTag -->|Tag Missing| BuildImage[Build Docker Image]
  BuildImage --> TagImage[Apply Multiple Tags]
  TagImage --> PushImage[Push Tags to Registry]
  SkipBuild --> End[Deployment Continues]
  PushImage --> End

This flowchart illustrates the core decision-making process in Docker Image Automation, emphasizing the optimization of skipping builds when the image tag already exists remotely.


By automating Docker image lifecycle management with caching, tagging, and remote tag verification, this subtopic ensures efficient, reproducible, and scalable container deployments within the blockchain infrastructure platform.