Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-build-and-push-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ jobs:
- name: Test Push Docker Image
uses: ./actions/push-docker
with:
image_name: ${{ steps.build_docker_image.outputs.docker_image_name }}
image_name: ${{ steps.build_docker_image.outputs.docker_image_full_name }}
image_tag: ${{ steps.build_docker_image.outputs.docker_image_tag }}
18 changes: 13 additions & 5 deletions actions/build-docker/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Build Docker Image Action

This GitHub Action builds a Docker image from a specified context
This GitHub Action builds a Docker image from a specified context and outputs useful image information for downstream steps

## 🛠 Inputs

Expand All @@ -14,10 +14,11 @@ This GitHub Action builds a Docker image from a specified context

## 📤 Outputs

| Name | Description |
|---------------------|--------------------------------------------------|
| `docker_image_name` | The name of the Docker image |
| `docker_image_tag` | The version/tag of the Docker image |
| Name | Description |
|------------------------|--------------------------------------------------|
| `docker_image_name` | The name of the Docker image (repository name) |
| `docker_image_tag` | The version/tag of the Docker image |
| `docker_image_full_name` | The full name of the Docker image (including registry, domain, and repository) |

## 🚀 Usage

Expand All @@ -38,3 +39,10 @@ This GitHub Action builds a Docker image from a specified context
registry: ${{ secrets.ACR_URL }}
```
<!-- x-release-please-end-version -->

---

**Notes:**
- The `docker_image_name` output is just the repository name (e.g., `my-repo`).
- The `docker_image_full_name` output is the full image name including registry, domain, and repository (e.g., `myregistry.azurecr.io/infra/my-repo`).
- Use the outputs in downstream steps, such as for pushing the image.
13 changes: 8 additions & 5 deletions actions/build-docker/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ inputs:
repository:
description: "Repository name for the Docker image (defaults to current GitHub repository)"
required: false
default: ${{ github.repository }}
default: $(basename "${{ github.repository }}")
domain:
description: "The image's domain"
required: true
Expand All @@ -26,6 +26,9 @@ outputs:
docker_image_tag:
description: "The version of the Docker image"
value: ${{ steps.set_image_name_and_tag.outputs.docker_image_tag }}
docker_image_full_name:
description: "The version of the Docker image"
value: ${{ steps.set_image_name_and_tag.outputs.docker_image_full_name }}
runs:
using: "composite"
steps:
Expand All @@ -36,12 +39,12 @@ runs:
id: set_image_name_and_tag
run: |
DOCKER_IMAGE_TAG="${{ inputs.tag }}"
REPO_NAME=$(basename "${{ inputs.repository }}")
DOCKER_IMAGE_NAME="${{ inputs.registry }}/${{ inputs.domain }}/${REPO_NAME}"
echo "docker_image_name=$DOCKER_IMAGE_NAME" >> $GITHUB_OUTPUT
DOCKER_IMAGE_NAME="${{ inputs.registry }}/${{ inputs.domain }}/${{ inputs.repository }}"
echo "docker_image_name=${{ inputs.repository }}" >> $GITHUB_OUTPUT
echo "docker_image_full_name=$DOCKER_IMAGE_NAME" >> $GITHUB_OUTPUT
echo "docker_image_tag=$DOCKER_IMAGE_TAG" >> $GITHUB_OUTPUT
shell: bash

- name: Build the docker image
run: docker build ${{ inputs.context }} -t ${{ steps.set_image_name_and_tag.outputs.docker_image_name }}:${{ steps.set_image_name_and_tag.outputs.docker_image_tag }}
run: docker build ${{ inputs.context }} -t ${{ steps.set_image_name_and_tag.outputs.docker_image_full_name }}:${{ steps.set_image_name_and_tag.outputs.docker_image_tag }}
shell: bash