Skip to content

Commit

Permalink
update inputs to build-push-to-dockerhub action (#143)
Browse files Browse the repository at this point in the history
* update inputs to build-push-to-dockerhub action

* add `cache-from` and `cache-to` inputs

* comment out push check logic

* don't allow pushing from a pull_request event

* add comment

* update check logic
  • Loading branch information
joeyorlando authored Jun 6, 2024
1 parent 7817819 commit 7c79c23
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
20 changes: 12 additions & 8 deletions actions/build-push-to-dockerhub/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ jobs:
## Inputs
| Name | Type | Description |
| ------------ | ------ | ------------------------------------------------------------------------------------ |
| `context` | String | Path to the Dockerfile (default: `.`) |
| `platforms` | List | List of platforms the image should be built for (e.g. `linux/amd64,linux/arm64`) |
| `push` | Bool | Push the generated image (default: `false`) |
| `repository` | String | Docker repository name |
| `tags` | List | Tags that should be used for the image (see the [metadata-action][mda] for details) |
| `file` | String | Path and filename of the dockerfile to build from. (Default: `{context}/Dockerfile`) |
| Name | Type | Description |
| ------------ | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `context` | String | Path to the Dockerfile (default: `.`) |
| `platforms` | List | List of platforms the image should be built for (e.g. `linux/amd64,linux/arm64`) |
| `push` | Bool | Push the generated image (default: `false`) |
| `repository` | String | Docker repository name |
| `tags` | List | Tags that should be used for the image (see the [metadata-action][mda] for details) |
| `file` | String | Path and filename of the dockerfile to build from. (Default: `{context}/Dockerfile`) |
| `build-args` | String | List of arguments necessary for the Docker image to be built. |
| `target` | String | Sets the target stage to build |
| `cache-from` | String | Where cache should be fetched from ([more about GHA and container caching](https://www.kenmuse.com/blog/implementing-docker-layer-caching-in-github-actions/)) |
| `cache-to` | String | Where cache should be stored to ([more about GHA and container caching](https://www.kenmuse.com/blog/implementing-docker-layer-caching-in-github-actions/)) |

[mda]: https://github.com/docker/metadata-action?tab=readme-ov-file#tags-input

Expand Down
29 changes: 27 additions & 2 deletions actions/build-push-to-dockerhub/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,36 @@ inputs:
description: |
The dockerfile to use.
required: false
build-args:
description: |
List of arguments necessary for the Docker image to be built.
required: false
default: ""
target:
description: |
Target stage to build
required: false
cache-from:
description: |
Where cache should be fetched from
required: false
default: "type=gha"
cache-to:
description: |
Where cache should be stored to
required: false
default: "type=gha,mode=max"

runs:
using: composite
steps:
# See this conversation for more context as to why we don't want to allow pushes on pull requests
# https://github.com/grafana/shared-workflows/pull/143#discussion_r1628314620
- name: Check if push is allowed
if: ${{ inputs.push == 'true' && github.event_name != 'push' }}
if: ${{ inputs.push == 'true' && github.event_name == 'pull_request' }}
shell: sh
run: |
>&2 echo "Publishing to DockerHub is only allowed on push events."
>&2 echo "Publishing to DockerHub is not allowed on pull_request events."
>&2 echo "If you still want to build images without pushing them, set the push input to false."
exit 1
Expand Down Expand Up @@ -79,3 +100,7 @@ runs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: ${{ inputs.file }}
build-args: ${{ inputs.build-args }}
target: ${{ inputs.target }}
cache-from: ${{ inputs.cache-from }}
cache-to: ${{ inputs.cache-to }}

0 comments on commit 7c79c23

Please sign in to comment.