Skip to content

🚀 Build and Publish

Overview

This GitHub Action automates the process of building and publishing a Docker image. It runs after a version bump workflow is completed and also triggers on specific tag pushes.

How It Works

The workflow is triggered in two cases:

  1. When the Bump Version workflow (1. Bump Version) completes on the main branch.
  2. When a push occurs to a tag matching the pattern v*.*.*-*.

Workflow Configuration

Trigger

  • workflow_run: Runs after the Bump Version workflow completes.
  • push (tags matching v*.*.*-*): Runs when a version-tagged commit is pushed.

Environment Variables

  • _VERSION: Initially set to 3.0.0-250216, but dynamically updated during the workflow execution.

Jobs

1. Build and Publish

This job builds and pushes a Docker image.

  • Runs on: ubuntu-22.04
  • Permissions:
    • contents: read
    • actions: write
  • Steps:
  • Checkout the repository
  • Set up QEMU (for multi-platform builds)
  • Set up Docker Buildx (for efficient image building)
  • Login to Docker Hub (using DOCKERHUB_USERNAME and DOCKERHUB_TOKEN from secrets)
  • Retrieve the version number using get-version.sh
  • (Optional, commented out) Build and export the image for local testing.
  • (Optional, commented out) Run and test the Docker container.
  • Build and push the Docker image with multi-platform support (linux/amd64, linux/arm64)
  • Trigger the release workflow (3.create-release.yml)

Usage

To trigger this workflow:

Automatic Execution

  • This workflow runs automatically after the 1. Bump Version workflow completes on the main branch.
  • It also runs automatically when a tag matching v*.*.*-* is pushed.

Manual Execution

  • Navigate to Actions in the repository.
  • Select "2. Build and Publish" from the workflow list.
  • Click "Run workflow" (if manual triggering is enabled).

Required Secrets

  • DOCKERHUB_USERNAME: Docker Hub username.
  • DOCKERHUB_TOKEN: Docker Hub access token.
  • DOCKER_UID_HASH_PASSWORD: Used as a build argument for the image.
  • GITHUB_TOKEN: GitHub token for triggering the next workflow.

Scripts Used

  • get-version.sh: Extracts the current version number.
  • bump-version.sh: (from previous workflow) Updates the version.

Notes

  • The Build and Push step builds an image and pushes it to Docker Hub with tags:
    • latest
    • The extracted version (e.g., 3.0.0-250216)
  • The platforms field is configured for linux/amd64 and linux/arm64 architectures.
  • Caching is enabled to speed up builds.
  • The workflow triggers the next step, 3.create-release.yml, using gh workflow run.

Troubleshooting

  • If the workflow fails during the Docker Login step, verify that DOCKERHUB_USERNAME and DOCKERHUB_TOKEN are correctly set.
  • If the build fails, ensure docker/setup-qemu-action is using a stable version.
  • If the version is not retrieved correctly, check if get-version.sh is executable.
  • If the final release workflow is not triggered, confirm that GITHUB_TOKEN has the required permissions.