first commit
This commit is contained in:
72
README.md
Normal file
72
README.md
Normal file
@@ -0,0 +1,72 @@
|
||||
# 🏗️ 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
|
||||
|
||||
```yaml
|
||||
- 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:
|
||||
|
||||
1. 🧰 **Set up Docker Buildx**: Initializes the Docker Buildx builder.
|
||||
2. 🔑 **Login to Registry**: Authenticates with the specified Docker registry.
|
||||
3. 🏗️ **Build and Push**:
|
||||
- Builds the Docker image using the specified context and Dockerfile.
|
||||
- Applies the provided tags.
|
||||
- Pushes the image to the registry (if `push` is 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**
|
||||
53
action.yml
Normal file
53
action.yml
Normal file
@@ -0,0 +1,53 @@
|
||||
name: 'Build and Push Docker Image'
|
||||
description: 'Builds and pushes a Docker image to a registry using Docker Buildx'
|
||||
inputs:
|
||||
image_name:
|
||||
description: 'Full image name (including registry) used for caching references'
|
||||
required: true
|
||||
registry:
|
||||
description: 'Docker registry URL'
|
||||
required: true
|
||||
username:
|
||||
description: 'Registry username'
|
||||
required: true
|
||||
password:
|
||||
description: 'Registry password'
|
||||
required: true
|
||||
dockerfile:
|
||||
description: 'Path to the Dockerfile'
|
||||
required: false
|
||||
default: 'Dockerfile'
|
||||
context:
|
||||
description: 'Build context'
|
||||
required: false
|
||||
default: '.'
|
||||
push:
|
||||
description: 'Whether to push the image'
|
||||
required: false
|
||||
default: 'true'
|
||||
tags:
|
||||
description: 'List of tags (comma separated)'
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Set up Docker Buildx 🧰
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Registry 🔑
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ inputs.registry }}
|
||||
username: ${{ inputs.username }}
|
||||
password: ${{ inputs.password }}
|
||||
|
||||
- name: Build and push image 🏗️
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: ${{ inputs.context }}
|
||||
file: ${{ inputs.dockerfile }}
|
||||
push: ${{ inputs.push }}
|
||||
tags: ${{ inputs.tags }}
|
||||
cache-from: type=registry,ref=${{ inputs.image_name }}:latest
|
||||
cache-to: type=inline
|
||||
Reference in New Issue
Block a user