diff --git a/actions/build-push-to-dockerhub/README.md b/actions/build-push-to-dockerhub/README.md index 80a05ffc..b795da55 100644 --- a/actions/build-push-to-dockerhub/README.md +++ b/actions/build-push-to-dockerhub/README.md @@ -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 diff --git a/actions/build-push-to-dockerhub/action.yaml b/actions/build-push-to-dockerhub/action.yaml index 372b72a6..02177e85 100644 --- a/actions/build-push-to-dockerhub/action.yaml +++ b/actions/build-push-to-dockerhub/action.yaml @@ -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 @@ -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 }}