Skip to content

Commit

Permalink
Support optional target and build-args in build action
Browse files Browse the repository at this point in the history
  • Loading branch information
tcjennings committed Dec 17, 2024
1 parent bbcadb8 commit 489bf2a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ To automatically set that, the above example uses the context variable `${{ gith

- `platforms` (list, optional) List of target platform for build.

- `target` (string, optional) the name of a build stage in the Dockerfile to target for the image. This allows multiple images
built from a single Dockerfile, e.g., "runtime-A" and "runtime-B".

- `build-args` (string, optional) A list of build-arguments as newline-delimited `arg=value` string pairs. These may be
specified in the Dockerfile as `ARG` statements.

- `additional-tags` (list, optional) A newline-delimited list of additional tags to be added to the built image.

### Outputs

- `fully_qualified_image_digest` (string) A complete, unique, and immutable identifier for the built image,
Expand Down
24 changes: 22 additions & 2 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ inputs:
platforms:
description: "List of target platforms for build"
required: false
target:
description: "Name of target stage to build"
required: false
build-args:
description: "List of build-time variables"
required: false
additional-tags:
description: "List of additional tags to add to built image"
required: false
outputs:
tag:
description: "The tag of the Docker image that was built."
Expand All @@ -41,6 +50,16 @@ runs:
shell: bash
run: echo "tag=`bash ${{ github.action_path }}/docker-tag.sh`" >> ${GITHUB_OUTPUT}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ inputs.image }}
tags: |
type=raw,${{ steps.tag.outputs.tag }}
${{ input.addtional-tags }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

Expand All @@ -61,9 +80,10 @@ runs:
with:
context: "${{ inputs.context }}"
file: "${{ inputs.dockerfile }}"
build-args: "${{ inputs.build-args }}"
target: "${{ inputs.target }}"
push: ${{ fromJSON(inputs.push) == true }}
platforms: ${{ inputs.platforms }}
tags: |
ghcr.io/${{ inputs.image }}:${{ steps.tag.outputs.tag }}
tags: ${{ steps.meta.output.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max

0 comments on commit 489bf2a

Please sign in to comment.