🚀 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:
- When the Bump Version workflow (
1. Bump Version) completes on themainbranch. - 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 matchingv*.*.*-*): Runs when a version-tagged commit is pushed.
Environment Variables
_VERSION: Initially set to3.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: readactions: 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_USERNAMEandDOCKERHUB_TOKENfrom 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 Versionworkflow completes on themainbranch. - 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
platformsfield is configured forlinux/amd64andlinux/arm64architectures. - Caching is enabled to speed up builds.
- The workflow triggers the next step,
3.create-release.yml, usinggh workflow run.
Troubleshooting
- If the workflow fails during the Docker Login step, verify that
DOCKERHUB_USERNAMEandDOCKERHUB_TOKENare correctly set. - If the build fails, ensure
docker/setup-qemu-actionis using a stable version. - If the version is not retrieved correctly, check if
get-version.shis executable. - If the final release workflow is not triggered, confirm that
GITHUB_TOKENhas the required permissions.