Skip to content

Commit 4360537

Browse files
authored
feat(build-docker): add image full name as output (#83)
* feat(build-docker): add image full name as output * ci: fix image full name * fix: action build
1 parent 58f5083 commit 4360537

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

.github/workflows/test-build-and-push-docker.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ jobs:
3232
- name: Test Push Docker Image
3333
uses: ./actions/push-docker
3434
with:
35-
image_name: ${{ steps.build_docker_image.outputs.docker_image_name }}
35+
image_name: ${{ steps.build_docker_image.outputs.docker_image_full_name }}
3636
image_tag: ${{ steps.build_docker_image.outputs.docker_image_tag }}

actions/build-docker/README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Build Docker Image Action
22

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

55
## 🛠 Inputs
66

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

1515
## 📤 Outputs
1616

17-
| Name | Description |
18-
|---------------------|--------------------------------------------------|
19-
| `docker_image_name` | The name of the Docker image |
20-
| `docker_image_tag` | The version/tag of the Docker image |
17+
| Name | Description |
18+
|------------------------|--------------------------------------------------|
19+
| `docker_image_name` | The name of the Docker image (repository name) |
20+
| `docker_image_tag` | The version/tag of the Docker image |
21+
| `docker_image_full_name` | The full name of the Docker image (including registry, domain, and repository) |
2122

2223
## 🚀 Usage
2324

@@ -38,3 +39,10 @@ This GitHub Action builds a Docker image from a specified context
3839
registry: ${{ secrets.ACR_URL }}
3940
```
4041
<!-- x-release-please-end-version -->
42+
43+
---
44+
45+
**Notes:**
46+
- The `docker_image_name` output is just the repository name (e.g., `my-repo`).
47+
- The `docker_image_full_name` output is the full image name including registry, domain, and repository (e.g., `myregistry.azurecr.io/infra/my-repo`).
48+
- Use the outputs in downstream steps, such as for pushing the image.

actions/build-docker/action.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ inputs:
88
repository:
99
description: "Repository name for the Docker image (defaults to current GitHub repository)"
1010
required: false
11-
default: ${{ github.repository }}
11+
default: $(basename "${{ github.repository }}")
1212
domain:
1313
description: "The image's domain"
1414
required: true
@@ -26,6 +26,9 @@ outputs:
2626
docker_image_tag:
2727
description: "The version of the Docker image"
2828
value: ${{ steps.set_image_name_and_tag.outputs.docker_image_tag }}
29+
docker_image_full_name:
30+
description: "The version of the Docker image"
31+
value: ${{ steps.set_image_name_and_tag.outputs.docker_image_full_name }}
2932
runs:
3033
using: "composite"
3134
steps:
@@ -36,12 +39,12 @@ runs:
3639
id: set_image_name_and_tag
3740
run: |
3841
DOCKER_IMAGE_TAG="${{ inputs.tag }}"
39-
REPO_NAME=$(basename "${{ inputs.repository }}")
40-
DOCKER_IMAGE_NAME="${{ inputs.registry }}/${{ inputs.domain }}/${REPO_NAME}"
41-
echo "docker_image_name=$DOCKER_IMAGE_NAME" >> $GITHUB_OUTPUT
42+
DOCKER_IMAGE_NAME="${{ inputs.registry }}/${{ inputs.domain }}/${{ inputs.repository }}"
43+
echo "docker_image_name=${{ inputs.repository }}" >> $GITHUB_OUTPUT
44+
echo "docker_image_full_name=$DOCKER_IMAGE_NAME" >> $GITHUB_OUTPUT
4245
echo "docker_image_tag=$DOCKER_IMAGE_TAG" >> $GITHUB_OUTPUT
4346
shell: bash
4447

4548
- name: Build the docker image
46-
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 }}
49+
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 }}
4750
shell: bash

0 commit comments

Comments
 (0)