diff --git a/.github/workflows/test-build-and-push-docker.yaml b/.github/workflows/test-build-and-push-docker.yaml index b78bb15..b6eb62c 100644 --- a/.github/workflows/test-build-and-push-docker.yaml +++ b/.github/workflows/test-build-and-push-docker.yaml @@ -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 }} diff --git a/actions/build-docker/README.md b/actions/build-docker/README.md index 28746b6..7f8dccf 100644 --- a/actions/build-docker/README.md +++ b/actions/build-docker/README.md @@ -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 @@ -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 @@ -38,3 +39,10 @@ This GitHub Action builds a Docker image from a specified context registry: ${{ secrets.ACR_URL }} ``` + +--- + +**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. diff --git a/actions/build-docker/action.yaml b/actions/build-docker/action.yaml index 88b0acd..da4d88b 100644 --- a/actions/build-docker/action.yaml +++ b/actions/build-docker/action.yaml @@ -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 @@ -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: @@ -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