Skip to content

Commit

Permalink
feat: support build-contexts for docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
gopkri24 committed Nov 5, 2024
1 parent 574f29a commit c2a1b67
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
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
10 changes: 9 additions & 1 deletion 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: ""
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 Down Expand Up @@ -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 }}

0 comments on commit c2a1b67

Please sign in to comment.