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
5 changes: 4 additions & 1 deletion .github/workflows/test-build-and-push-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ jobs:
password: ${{ secrets.ACR_PUSH_TOKEN }}

- name: Test Build Docker Image
id: build_docker_image
uses: ./actions/build-docker
with:
context: ./test
domain: infra
registry: ${{ secrets.ACR_URL }}
tag: v1.0.0

- 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 }}
22 changes: 12 additions & 10 deletions actions/build-docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ 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 | — |
| `tag` | Tag for the Docker image | ❌ No | `${{ github.ref_name }}` |

## 📤 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

Expand All @@ -31,7 +34,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 }}
```
Expand Down
33 changes: 23 additions & 10 deletions actions/build-docker/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,46 @@ 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
tag:
description: "Tag for the Docker image"
required: false
default: ${{ github.ref_name }}
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="${{ inputs.tag }}"
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
12 changes: 7 additions & 5 deletions actions/push-docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |

---

Expand Down Expand Up @@ -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 }}
```
<!-- x-release-please-end-version -->
8 changes: 6 additions & 2 deletions actions/push-docker/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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