Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support build-contexts for docker build #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions container-scan/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ To use this action in your GitHub Actions workflow, include the following steps:
| image-tag | Docker image tag | `true` | |
| image-platform | Target platform to build image for (eg. linux/amd64 (default), linux/arm64, etc) | `false` | linux/amd64 |
| build-args | List of build arguments for docker build as key-value pairs (e.g., KEY=VALUE) | `false` | |
| build-contexts | List of additional build contexts (e.g., name=path) | `false` | |
| secrets | List of secrets for docker build as key-value pairs (e.g., SECRET_KEY=VALUE) | `false` | |
| enable-docker-build | Docker image tag | `false` | true |
| image-tags | List of tags as key-value pair attributes | `false` | |
<!-- action-docs-inputs -->

<!-- action-docs-outputs -->
Expand Down
12 changes: 10 additions & 2 deletions container-scan/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ inputs:
description: Target platform to build image for (eg. linux/amd64 (default), linux/arm64, etc)
required: false
default: linux/amd64

build-args:
required: false
description: List of build arguments for docker build as key-value pairs (e.g., KEY=VALUE)
default: ""
build-contexts:
required: false
description: List of additional build contexts (e.g., name=path)
default: ""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure the empty string is a valid context for docker build? we could use the . as default if the empty string is not valid.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm, I think empty string will still work as we are giving the context . in the beginning

secrets:
required: false
description: List of secrets for docker build as key-value pairs (e.g., SECRET_KEY=VALUE)
Expand All @@ -46,6 +49,10 @@ inputs:
required: false
default: true
description: Docker image tag
image-tags:
required: false
description: List of tags as key-value pair attributes
default: ""

outputs:
comment-id:
Expand All @@ -60,7 +67,7 @@ runs:

- name: Build docker image
if: ${{ inputs.enable-docker-build }}
uses: open-turo/actions-security/docker-build@v2
uses: open-turo/actions-security/docker-build@c/support_build_contexts
id: docker-build
with:
dockerhub-user: ${{ inputs.dockerhub-user }}
Expand All @@ -74,6 +81,7 @@ runs:
type=ref,event=branch
type=ref,event=pr
build-args: ${{ inputs.build-args }}
build-contexts: ${{ inputs.build-contexts }}
secrets: ${{ inputs.secrets }}

- name: "Determining image name"
Expand Down
12 changes: 10 additions & 2 deletions docker-build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ steps:
type=semver,pattern={{version}},value=${{ steps.release.outputs.new-release-version }}
```

#### Dynamically input multiple build arguments and secrets:
#### Dynamically input multiple build arguments, contexts and secrets:

If you want to pass multiple build arguments and secrets, you can use the `build-args` and `secrets` input parameters.
If you want to pass multiple build arguments and secrets, you can use the `build-args`, `build-contexts` and `secrets` input parameters.

```yaml
steps:
Expand All @@ -71,9 +71,15 @@ steps:
dockerhub-password: ${{ secrets.DOCKER_PASSWORD }}
github-token: ${{ secrets.GITHUB_TOKEN }}
image-version: ${{ steps.release.outputs.new-release-version }}
image-tags: |
tag1=value1
tag2=value2
build-args: |
KEY1=VALUE1
KEY2=VALUE2
build-contexts: |
context1=PATH1
context2=PATH2
secrets: |
SECRET_KEY1=SECRET_VALUE1
SECRET_KEY2=SECRET_VALUE2
Expand All @@ -98,7 +104,9 @@ steps:
| push | Do you want to push the image to the registry | `false` | false |
| load | Do you want to load the single-platform build result to docker images | `false` | true |
| build-args | List of build arguments as key-value pairs (e.g., KEY=VALUE) | `false` | |
| build-contexts | List of additional build contexts (e.g., name=path) | `false` | |
| secrets | List of secrets as key-value pairs (e.g., SECRET_KEY=VALUE) | `false` | |
| image-tags | List of tags as key-value pair attributes | `false` | |

## Outputs

Expand Down
13 changes: 11 additions & 2 deletions docker-build/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@ inputs:
required: false
description: List of build arguments as key-value pairs (e.g., KEY=VALUE)
default: ""
build-contexts:
required: false
description: List of additional build contexts (e.g., name=path)
default: ""
secrets:
required: false
description: List of secrets as key-value pairs (e.g., SECRET_KEY=VALUE)
default: ""
image-tags:
required: false
description: List of tags as key-value pair attributes
default: ""

outputs:
image-name:
description: Docker image name
Expand Down Expand Up @@ -113,5 +122,5 @@ runs:
load: ${{ inputs.load }}
tags: ${{ steps.config.outputs.image-name }}:${{ inputs.image-version }}
labels: ${{ steps.meta.outputs.labels }}
secrets: |
${{ inputs.secrets }}
secrets: ${{ inputs.secrets }}
build-contexts: ${{ inputs.build-contexts }}