From 0e95ddba17b2cfbd267efbd633a5cf226732f5c7 Mon Sep 17 00:00:00 2001 From: Radek Date: Sun, 21 Dec 2025 23:34:01 +0100 Subject: [PATCH] first commit --- README.md | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ action.yml | 53 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 README.md create mode 100644 action.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..f002f88 --- /dev/null +++ b/README.md @@ -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** \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..42fe0c6 --- /dev/null +++ b/action.yml @@ -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 \ No newline at end of file