0e95ddba17b2cfbd267efbd633a5cf226732f5c7
🏗️ Build and Push Docker Image Action
A composite action that simplifies building and pushing Docker images using Docker Buildx. It handles setting up Buildx, logging into the registry, and performing the build and push operation with caching support.
✨ Features
- 🧰 Automatic Buildx Setup: Sets up Docker Buildx for multi-platform builds and advanced features.
- 🔑 Registry Authentication: Handles login to any Docker registry.
- 🚀 Build & Push: Builds the image and pushes it to the registry (configurable).
- 💾 Caching: Uses registry-based caching (
type=registry) to speed up builds. - 📝 Flexible Configuration: Supports custom Dockerfiles, build contexts, and tags.
📥 Inputs
| Input | Description | Required | Default |
|---|---|---|---|
image_name |
Full image name (including registry) used for caching references | ✅ Yes | - |
registry |
Docker registry URL | ✅ Yes | - |
username |
Registry username | ✅ Yes | - |
password |
Registry password | ✅ Yes | - |
tags |
List of tags (comma separated) | ✅ Yes | - |
dockerfile |
Path to the Dockerfile | ❌ No | Dockerfile |
context |
Build context | ❌ No | . |
push |
Whether to push the image | ❌ No | true |
🛠️ Example Usage
- name: Build and push image 🏗️
uses: your-org/build-push-action@main
with:
image_name: ${{ vars.REMOTE_REGISTRY_URL }}/${{ vars.REMOTE_REGISTRY_NAMESPACE }}/my-app
registry: ${{ vars.REMOTE_REGISTRY_URL }}
username: ${{ vars.REMOTE_REGISTRY_USERNAME }}
password: ${{ secrets.REMOTE_REGISTRY_PASSWORD }}
tags: ${{ steps.meta.outputs.tags }}
dockerfile: Dockerfile
context: .
push: true
🧑💻 How It Works
This action performs the following steps:
- 🧰 Set up Docker Buildx: Initializes the Docker Buildx builder.
- 🔑 Login to Registry: Authenticates with the specified Docker registry.
- 🏗️ Build and Push:
- Builds the Docker image using the specified context and Dockerfile.
- Applies the provided tags.
- Pushes the image to the registry (if
pushis true). - Uses inline caching and registry caching (
cache-from) to optimize build times.
📜 License
This action is open-source software licensed under the MIT license.
Happy building! 🚀
— Grand
Description