From ce1ca965b72444863a5e280e4d07baa547ffe7ff Mon Sep 17 00:00:00 2001 From: Joey Orlando Date: Wed, 5 Jun 2024 10:00:29 -0400 Subject: [PATCH 1/6] update inputs to build-push-to-dockerhub action --- actions/build-push-to-dockerhub/README.md | 2 ++ actions/build-push-to-dockerhub/action.yaml | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/actions/build-push-to-dockerhub/README.md b/actions/build-push-to-dockerhub/README.md index 80a05ffc..e028c460 100644 --- a/actions/build-push-to-dockerhub/README.md +++ b/actions/build-push-to-dockerhub/README.md @@ -39,6 +39,8 @@ jobs: | `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 | [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..039c3260 100644 --- a/actions/build-push-to-dockerhub/action.yaml +++ b/actions/build-push-to-dockerhub/action.yaml @@ -25,6 +25,15 @@ 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 runs: using: composite @@ -79,3 +88,5 @@ runs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} file: ${{ inputs.file }} + build-args: ${{ inputs.build-args }} + target: ${{ inputs.target }} From 2cd8f06917d985a0f83176e6e439f69398c8d6e8 Mon Sep 17 00:00:00 2001 From: Joey Orlando Date: Wed, 5 Jun 2024 10:04:43 -0400 Subject: [PATCH 2/6] add `cache-from` and `cache-to` inputs --- actions/build-push-to-dockerhub/README.md | 22 +++++++++++---------- actions/build-push-to-dockerhub/action.yaml | 12 +++++++++++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/actions/build-push-to-dockerhub/README.md b/actions/build-push-to-dockerhub/README.md index e028c460..b795da55 100644 --- a/actions/build-push-to-dockerhub/README.md +++ b/actions/build-push-to-dockerhub/README.md @@ -31,16 +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`) | -| `build-args` | String | List of arguments necessary for the Docker image to be built. | -| `target` | String | Sets the target stage to build | +| 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 039c3260..c0e1847d 100644 --- a/actions/build-push-to-dockerhub/action.yaml +++ b/actions/build-push-to-dockerhub/action.yaml @@ -34,6 +34,16 @@ inputs: 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 @@ -90,3 +100,5 @@ runs: file: ${{ inputs.file }} build-args: ${{ inputs.build-args }} target: ${{ inputs.target }} + cache-from: ${{ inputs.cache-from }} + cache-to: ${{ inputs.cache-to }} From a5b95e1419bc78276cf74f0f8246e25192345b94 Mon Sep 17 00:00:00 2001 From: Joey Orlando Date: Wed, 5 Jun 2024 14:08:26 -0400 Subject: [PATCH 3/6] comment out push check logic --- actions/build-push-to-dockerhub/action.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/actions/build-push-to-dockerhub/action.yaml b/actions/build-push-to-dockerhub/action.yaml index c0e1847d..ea737cf6 100644 --- a/actions/build-push-to-dockerhub/action.yaml +++ b/actions/build-push-to-dockerhub/action.yaml @@ -48,13 +48,13 @@ inputs: runs: using: composite steps: - - name: Check if push is allowed - if: ${{ inputs.push == 'true' && github.event_name != 'push' }} - shell: sh - run: | - >&2 echo "Publishing to DockerHub is only allowed on push events." - >&2 echo "If you still want to build images without pushing them, set the push input to false." - exit 1 + # - name: Check if push is allowed + # if: ${{ inputs.push == 'true' && github.event_name != 'push' }} + # shell: sh + # run: | + # >&2 echo "Publishing to DockerHub is only allowed on push events." + # >&2 echo "If you still want to build images without pushing them, set the push input to false." + # exit 1 - name: Checkout shared workflows env: From ec33a2a3fe17a98b7837315d2a47fb61cf372c2a Mon Sep 17 00:00:00 2001 From: Joey Orlando Date: Thu, 6 Jun 2024 09:45:19 -0400 Subject: [PATCH 4/6] don't allow pushing from a pull_request event --- actions/build-push-to-dockerhub/action.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/actions/build-push-to-dockerhub/action.yaml b/actions/build-push-to-dockerhub/action.yaml index ea737cf6..ba8b7465 100644 --- a/actions/build-push-to-dockerhub/action.yaml +++ b/actions/build-push-to-dockerhub/action.yaml @@ -48,13 +48,13 @@ inputs: runs: using: composite steps: - # - name: Check if push is allowed - # if: ${{ inputs.push == 'true' && github.event_name != 'push' }} - # shell: sh - # run: | - # >&2 echo "Publishing to DockerHub is only allowed on push events." - # >&2 echo "If you still want to build images without pushing them, set the push input to false." - # exit 1 + - name: Check if push is allowed + if: ${{ inputs.push == 'true' && github.event_name != 'pull_request' }} + shell: sh + run: | + >&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 - name: Checkout shared workflows env: From 0846a45c1e511394002de7823f3bae1d1cb6ef71 Mon Sep 17 00:00:00 2001 From: Joey Orlando Date: Thu, 6 Jun 2024 09:45:53 -0400 Subject: [PATCH 5/6] add comment --- actions/build-push-to-dockerhub/action.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/actions/build-push-to-dockerhub/action.yaml b/actions/build-push-to-dockerhub/action.yaml index ba8b7465..7c27e161 100644 --- a/actions/build-push-to-dockerhub/action.yaml +++ b/actions/build-push-to-dockerhub/action.yaml @@ -48,6 +48,8 @@ inputs: 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 != 'pull_request' }} shell: sh From 72479d27a6ff52c045be0adcbc33e9c0fdda26c7 Mon Sep 17 00:00:00 2001 From: Joey Orlando Date: Thu, 6 Jun 2024 10:03:53 -0400 Subject: [PATCH 6/6] update check logic --- actions/build-push-to-dockerhub/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/build-push-to-dockerhub/action.yaml b/actions/build-push-to-dockerhub/action.yaml index 7c27e161..02177e85 100644 --- a/actions/build-push-to-dockerhub/action.yaml +++ b/actions/build-push-to-dockerhub/action.yaml @@ -51,7 +51,7 @@ runs: # 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 != 'pull_request' }} + if: ${{ inputs.push == 'true' && github.event_name == 'pull_request' }} shell: sh run: | >&2 echo "Publishing to DockerHub is not allowed on pull_request events."