From 0f6111551cd66b76d7fff45003ae445243839a7b Mon Sep 17 00:00:00 2001 From: netanelC Date: Tue, 8 Jul 2025 20:00:17 +0300 Subject: [PATCH 1/3] fix(docker-build-and-push): add output to build image --- .../workflows/test-build-and-push-docker.yaml | 4 ++- actions/build-docker/README.md | 21 +++++++------- actions/build-docker/action.yaml | 29 ++++++++++++------- actions/push-docker/README.md | 12 ++++---- actions/push-docker/action.yaml | 8 +++-- 5 files changed, 46 insertions(+), 28 deletions(-) diff --git a/.github/workflows/test-build-and-push-docker.yaml b/.github/workflows/test-build-and-push-docker.yaml index 8a870593..dbfffeec 100644 --- a/.github/workflows/test-build-and-push-docker.yaml +++ b/.github/workflows/test-build-and-push-docker.yaml @@ -21,6 +21,7 @@ jobs: password: ${{ secrets.ACR_PUSH_TOKEN }} - name: Test Build Docker Image + id: build_docker_image uses: ./actions/build-docker with: context: ./test @@ -30,4 +31,5 @@ jobs: - name: Test Push Docker Image uses: ./actions/push-docker with: - image_name: $DOCKER_IMAGE_NAME + image_name: ${{ steps.build_docker_image.outputs.docker_image_name }} + image_tag: ${{ steps.build_docker_image.outputs.docker_image_tag }} diff --git a/actions/build-docker/README.md b/actions/build-docker/README.md index ff3ab3fc..6d7ba631 100644 --- a/actions/build-docker/README.md +++ b/actions/build-docker/README.md @@ -4,17 +4,19 @@ This GitHub Action builds a Docker image from a specified context ## 🛠 Inputs -| Name | Description | Required | Default | -|--------------|-----------------------------------------------------------------------------|----------|--------------------------------| -| `context` | Path to the Docker build context (e.g. `.` or `./app`). | ✅ Yes | — | -| `repository` | Full GitHub repository name. Used for image name. | ❌ No | `${{ github.repository }}` | -| `domain` | The image's domain (e.g. `3d`, `infra`). | ✅ Yes | — | -| `registry` | Registry URL (e.g. ACR address). | ✅ Yes | — | +| Name | Description | Required | Default | +|--------------|-----------------------------------------------------------------------------|----------|------------------------| +| `context` | Path to the Docker build context | No | `.` | +| `repository` | Repository name for the Docker image (defaults to current GitHub repository)| No | `${{ github.repository }}` | +| `domain` | The image's domain (e.g. `3d`, `infra`). | Yes | — | +| `registry` | Azure Registry to authenticate against (e.g. ACR address). | Yes | — | + ## 📤 Outputs -| Name | Description | -|---------|----------------------------------| -| `DOCKER_IMAGE_NAME` | Fully qualified Docker image name to push (github output)| +| Name | Description | +|---------------------|--------------------------------------------------| +| `docker_image_name` | The name of the Docker image | +| `docker_image_tag` | The version/tag of the Docker image | ## 🚀 Usage @@ -31,7 +33,6 @@ This GitHub Action builds a Docker image from a specified context - name: Build Docker Image uses: MapColonies/shared-workflows/actions/build-docker@build-docker-v1.0.0 with: - context: . domain: infra registry: ${{ secrets.ACR_URL }} ``` diff --git a/actions/build-docker/action.yaml b/actions/build-docker/action.yaml index 8b027609..0312f9f0 100644 --- a/actions/build-docker/action.yaml +++ b/actions/build-docker/action.yaml @@ -2,33 +2,42 @@ name: "Build Docker Image" description: "Builds a Docker image" inputs: context: - description: "Path to the Docker build context." - required: true + description: "Path to the Docker build context" + required: false + default: "." repository: - description: "Repository name for the Docker image (defaults to current GitHub repository)." + description: "Repository name for the Docker image (defaults to current GitHub repository)" required: false default: ${{ github.repository }} domain: - description: "The image's domain." + description: "The image's domain" required: true registry: - description: Azure Registry to authenticate against. + description: "Azure Registry to authenticate against" required: true +outputs: + docker_image_name: + description: "The name of the Docker image" + value: ${{ steps.set_image_name_and_tag.outputs.docker_image_name }} + docker_image_tag: + description: "The version of the Docker image" + value: ${{ steps.set_image_name_and_tag.outputs.docker_image_tag }} runs: using: "composite" steps: - name: Checkout code uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: Setup docker image name + - name: Setup Docker image name and tag + id: set_image_name_and_tag run: | - IMAGE_TAG="${{ github.ref_name }}" + DOCKER_IMAGE_TAG="${{ github.ref_name }}" REPO_NAME=$(basename "${{ inputs.repository }}") - DOCKER_IMAGE_NAME="${{ inputs.registry }}/${{ inputs.domain }}/${REPO_NAME}:${IMAGE_TAG}" - echo "DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME,,}" >> $GITHUB_ENV + DOCKER_IMAGE_NAME="${{ inputs.registry }}/${{ inputs.domain }}/${REPO_NAME}" echo "docker_image_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 ${{ env.DOCKER_IMAGE_NAME }} + 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 }} shell: bash diff --git a/actions/push-docker/README.md b/actions/push-docker/README.md index 96d96609..79f48812 100644 --- a/actions/push-docker/README.md +++ b/actions/push-docker/README.md @@ -9,9 +9,10 @@ This action assumes the image is already tagged and available in the local Docke ## 🛠 Inputs -| Name | Description | Required | -|--------------|----------------------------------------------------|----------| -| `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 | +| Name | Description | Required | Default | +|--------------|---------------------------------------------------------------------------------------------------|----------|----------| +| `image_name` | The name of the Docker image to push, including the registry and repository (e.g., `myregistry.azurecr.io/myrepo/myimage`) | ✅ Yes | | +| `image_tag` | Tag of the Docker image to push | ❌ No | `latest` | --- @@ -39,12 +40,13 @@ jobs: uses: MapColonies/shared-workflows/actions/build-docker@e7220d24b1c7ee5c8eaac7e50edc60239e829eb4 # v1.0.0 with: context: ./test - scope: infra + domain: infra registry: ${{ secrets.ACR_URL }} - name: Push Docker Image uses: MapColonies/shared-workflows/actions/push-docker@push-docker-v1.0.0 with: - image_name: $DOCKER_IMAGE_NAME + image_name: ${{ steps.build.outputs.docker_image_name }} + image_tag: ${{ steps.build.outputs.docker_image_tag }} ``` diff --git a/actions/push-docker/action.yaml b/actions/push-docker/action.yaml index e74ff942..fcd8c700 100644 --- a/actions/push-docker/action.yaml +++ b/actions/push-docker/action.yaml @@ -2,11 +2,15 @@ name: "Push Docker Image" description: "Pushes a previously built Docker image." inputs: image_name: - description: "Fully qualified Docker image name to push." + description: "Name of the Docker image to push, including the registry and repository (e.g., 'myregistry.azurecr.io/myrepo/myimage')" required: true + image_tag: + description: "Tag of the Docker image to push" + required: false + default: "latest" runs: using: "composite" steps: - name: Push docker image - run: docker push ${{ inputs.image_name }} + run: docker push ${{ inputs.image_name }}:${{ inputs.image_tag }} shell: bash From bac7b5f2e91362d37503f109e9a9eb9ae661d119 Mon Sep 17 00:00:00 2001 From: netanelC Date: Tue, 8 Jul 2025 20:10:48 +0300 Subject: [PATCH 2/3] feat: add tag input --- .github/workflows/test-build-and-push-docker.yaml | 1 + actions/build-docker/README.md | 1 + actions/build-docker/action.yaml | 6 +++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-build-and-push-docker.yaml b/.github/workflows/test-build-and-push-docker.yaml index dbfffeec..b78bb156 100644 --- a/.github/workflows/test-build-and-push-docker.yaml +++ b/.github/workflows/test-build-and-push-docker.yaml @@ -27,6 +27,7 @@ jobs: context: ./test domain: infra registry: ${{ secrets.ACR_URL }} + tag: v1.0.0 - name: Test Push Docker Image uses: ./actions/push-docker diff --git a/actions/build-docker/README.md b/actions/build-docker/README.md index 6d7ba631..fdce2622 100644 --- a/actions/build-docker/README.md +++ b/actions/build-docker/README.md @@ -10,6 +10,7 @@ This GitHub Action builds a Docker image from a specified context | `repository` | Repository name for the Docker image (defaults to current GitHub repository)| No | `${{ github.repository }}` | | `domain` | The image's domain (e.g. `3d`, `infra`). | Yes | — | | `registry` | Azure Registry to authenticate against (e.g. ACR address). | Yes | — | +| `tag` | Tag for the Docker image | No | `${{ github.ref_name }}` | ## 📤 Outputs diff --git a/actions/build-docker/action.yaml b/actions/build-docker/action.yaml index 0312f9f0..88b0acdc 100644 --- a/actions/build-docker/action.yaml +++ b/actions/build-docker/action.yaml @@ -15,6 +15,10 @@ inputs: registry: description: "Azure Registry to authenticate against" required: true + tag: + description: "Tag for the Docker image" + required: false + default: ${{ github.ref_name }} outputs: docker_image_name: description: "The name of the Docker image" @@ -31,7 +35,7 @@ runs: - name: Setup Docker image name and tag id: set_image_name_and_tag run: | - DOCKER_IMAGE_TAG="${{ github.ref_name }}" + 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 From bfcbb8bebb0d8f85b913263979d89d7267ba987e Mon Sep 17 00:00:00 2001 From: netanelC Date: Tue, 8 Jul 2025 20:13:10 +0300 Subject: [PATCH 3/3] docs: README --- actions/build-docker/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/actions/build-docker/README.md b/actions/build-docker/README.md index fdce2622..4a6fcf9d 100644 --- a/actions/build-docker/README.md +++ b/actions/build-docker/README.md @@ -6,11 +6,11 @@ This GitHub Action builds a Docker image from a specified context | Name | Description | Required | Default | |--------------|-----------------------------------------------------------------------------|----------|------------------------| -| `context` | Path to the Docker build context | No | `.` | -| `repository` | Repository name for the Docker image (defaults to current GitHub repository)| No | `${{ github.repository }}` | -| `domain` | The image's domain (e.g. `3d`, `infra`). | Yes | — | -| `registry` | Azure Registry to authenticate against (e.g. ACR address). | Yes | — | -| `tag` | Tag for the Docker image | No | `${{ github.ref_name }}` | +| `context` | Path to the Docker build context | ❌ No | `.` | +| `repository` | Repository name for the Docker image (defaults to current GitHub repository)| ❌ No | `${{ github.repository }}` | +| `domain` | The image's domain (e.g. `3d`, `infra`). | ✅ Yes | — | +| `registry` | Azure Registry to authenticate against (e.g. ACR address). | ✅ Yes | — | +| `tag` | Tag for the Docker image | ❌ No | `${{ github.ref_name }}` | ## 📤 Outputs