Skip to content

Commit c97f7d2

Browse files
authored
fix(docker-build-and-push): add output to build image (#80)
* fix(docker-build-and-push): add output to build image * feat: add tag input * docs: README
1 parent 995d308 commit c97f7d2

5 files changed

Lines changed: 52 additions & 28 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ jobs:
2121
password: ${{ secrets.ACR_PUSH_TOKEN }}
2222

2323
- name: Test Build Docker Image
24+
id: build_docker_image
2425
uses: ./actions/build-docker
2526
with:
2627
context: ./test
2728
domain: infra
2829
registry: ${{ secrets.ACR_URL }}
30+
tag: v1.0.0
2931

3032
- name: Test Push Docker Image
3133
uses: ./actions/push-docker
3234
with:
33-
image_name: $DOCKER_IMAGE_NAME
35+
image_name: ${{ steps.build_docker_image.outputs.docker_image_name }}
36+
image_tag: ${{ steps.build_docker_image.outputs.docker_image_tag }}

actions/build-docker/README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@ This GitHub Action builds a Docker image from a specified context
44

55
## 🛠 Inputs
66

7-
| Name | Description | Required | Default |
8-
|--------------|-----------------------------------------------------------------------------|----------|--------------------------------|
9-
| `context` | Path to the Docker build context (e.g. `.` or `./app`). | ✅ Yes ||
10-
| `repository` | Full GitHub repository name. Used for image name. | ❌ No | `${{ github.repository }}` |
11-
| `domain` | The image's domain (e.g. `3d`, `infra`). | ✅ Yes ||
12-
| `registry` | Registry URL (e.g. ACR address). | ✅ Yes ||
7+
| Name | Description | Required | Default |
8+
|--------------|-----------------------------------------------------------------------------|----------|------------------------|
9+
| `context` | Path to the Docker build context | ❌ No | `.` |
10+
| `repository` | Repository name for the Docker image (defaults to current GitHub repository)| ❌ No | `${{ github.repository }}` |
11+
| `domain` | The image's domain (e.g. `3d`, `infra`). | ✅ Yes ||
12+
| `registry` | Azure Registry to authenticate against (e.g. ACR address). | ✅ Yes ||
13+
| `tag` | Tag for the Docker image | ❌ No | `${{ github.ref_name }}` |
14+
1315
## 📤 Outputs
1416

15-
| Name | Description |
16-
|---------|----------------------------------|
17-
| `DOCKER_IMAGE_NAME` | Fully qualified Docker image name to push (github output)|
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 |
1821

1922
## 🚀 Usage
2023

@@ -31,7 +34,6 @@ This GitHub Action builds a Docker image from a specified context
3134
- name: Build Docker Image
3235
uses: MapColonies/shared-workflows/actions/build-docker@build-docker-v1.0.0
3336
with:
34-
context: .
3537
domain: infra
3638
registry: ${{ secrets.ACR_URL }}
3739
```

actions/build-docker/action.yaml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,46 @@ name: "Build Docker Image"
22
description: "Builds a Docker image"
33
inputs:
44
context:
5-
description: "Path to the Docker build context."
6-
required: true
5+
description: "Path to the Docker build context"
6+
required: false
7+
default: "."
78
repository:
8-
description: "Repository name for the Docker image (defaults to current GitHub repository)."
9+
description: "Repository name for the Docker image (defaults to current GitHub repository)"
910
required: false
1011
default: ${{ github.repository }}
1112
domain:
12-
description: "The image's domain."
13+
description: "The image's domain"
1314
required: true
1415
registry:
15-
description: Azure Registry to authenticate against.
16+
description: "Azure Registry to authenticate against"
1617
required: true
18+
tag:
19+
description: "Tag for the Docker image"
20+
required: false
21+
default: ${{ github.ref_name }}
22+
outputs:
23+
docker_image_name:
24+
description: "The name of the Docker image"
25+
value: ${{ steps.set_image_name_and_tag.outputs.docker_image_name }}
26+
docker_image_tag:
27+
description: "The version of the Docker image"
28+
value: ${{ steps.set_image_name_and_tag.outputs.docker_image_tag }}
1729
runs:
1830
using: "composite"
1931
steps:
2032
- name: Checkout code
2133
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2234

23-
- name: Setup docker image name
35+
- name: Setup Docker image name and tag
36+
id: set_image_name_and_tag
2437
run: |
25-
IMAGE_TAG="${{ github.ref_name }}"
38+
DOCKER_IMAGE_TAG="${{ inputs.tag }}"
2639
REPO_NAME=$(basename "${{ inputs.repository }}")
27-
DOCKER_IMAGE_NAME="${{ inputs.registry }}/${{ inputs.domain }}/${REPO_NAME}:${IMAGE_TAG}"
28-
echo "DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME,,}" >> $GITHUB_ENV
40+
DOCKER_IMAGE_NAME="${{ inputs.registry }}/${{ inputs.domain }}/${REPO_NAME}"
2941
echo "docker_image_name=$DOCKER_IMAGE_NAME" >> $GITHUB_OUTPUT
42+
echo "docker_image_tag=$DOCKER_IMAGE_TAG" >> $GITHUB_OUTPUT
3043
shell: bash
3144

3245
- name: Build the docker image
33-
run: docker build ${{ inputs.context }} -t ${{ env.DOCKER_IMAGE_NAME }}
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 }}
3447
shell: bash

actions/push-docker/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ This action assumes the image is already tagged and available in the local Docke
99

1010
## 🛠 Inputs
1111

12-
| Name | Description | Required |
13-
|--------------|----------------------------------------------------|----------|
14-
| `image_name` | The fully qualified name of the Docker image (including tag) to push, e.g. `my-registry.com/my-scope/my-image:tag` | ✅ Yes |
12+
| Name | Description | Required | Default |
13+
|--------------|---------------------------------------------------------------------------------------------------|----------|----------|
14+
| `image_name` | The name of the Docker image to push, including the registry and repository (e.g., `myregistry.azurecr.io/myrepo/myimage`) | ✅ Yes | |
15+
| `image_tag` | Tag of the Docker image to push | ❌ No | `latest` |
1516

1617
---
1718

@@ -39,12 +40,13 @@ jobs:
3940
uses: MapColonies/shared-workflows/actions/build-docker@e7220d24b1c7ee5c8eaac7e50edc60239e829eb4 # v1.0.0
4041
with:
4142
context: ./test
42-
scope: infra
43+
domain: infra
4344
registry: ${{ secrets.ACR_URL }}
4445

4546
- name: Push Docker Image
4647
uses: MapColonies/shared-workflows/actions/push-docker@push-docker-v1.0.0
4748
with:
48-
image_name: $DOCKER_IMAGE_NAME
49+
image_name: ${{ steps.build.outputs.docker_image_name }}
50+
image_tag: ${{ steps.build.outputs.docker_image_tag }}
4951
```
5052
<!-- x-release-please-end-version -->

actions/push-docker/action.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ name: "Push Docker Image"
22
description: "Pushes a previously built Docker image."
33
inputs:
44
image_name:
5-
description: "Fully qualified Docker image name to push."
5+
description: "Name of the Docker image to push, including the registry and repository (e.g., 'myregistry.azurecr.io/myrepo/myimage')"
66
required: true
7+
image_tag:
8+
description: "Tag of the Docker image to push"
9+
required: false
10+
default: "latest"
711
runs:
812
using: "composite"
913
steps:
1014
- name: Push docker image
11-
run: docker push ${{ inputs.image_name }}
15+
run: docker push ${{ inputs.image_name }}:${{ inputs.image_tag }}
1216
shell: bash

0 commit comments

Comments
 (0)