I want to add secrets to build-push-action
by names. This is how I done with one secret:
Define a reusable workflow:
<code>
## inputs definition
on:
workflow_call:
inputs:
build_repo_secret_name:
description: 'Build Arguments (format: "secret_name")'
required: false
type: string
default: ''
## some other inputs
# the action i am mentioning
- name: Docker build and push
id: build-and-push
uses: docker/build-push-action@v5
with:
context: ${{ inputs.context }}
push: ${{ inputs.push }}
platforms: ${{ inputs.build_platforms }}
tags: ${{ inputs.tags }}
target: ${{ inputs.target }}
file: ${{ inputs.dockerfile }}
no-cache: ${{ inputs.no_cache }}
provenance: ${{ inputs.provenance }}
load: ${{ inputs.load }}
build-args: ${{ inputs.build_args }}
secrets: ${{ inputs.build_repo_secret_name != '' && format('"{0}={1}"', inputs.build_repo_secret_name, secrets[inputs.build_repo_secret_name]) || '' }}
</code>
<code>
## inputs definition
on:
workflow_call:
inputs:
build_repo_secret_name:
description: 'Build Arguments (format: "secret_name")'
required: false
type: string
default: ''
## some other inputs
# the action i am mentioning
- name: Docker build and push
id: build-and-push
uses: docker/build-push-action@v5
with:
context: ${{ inputs.context }}
push: ${{ inputs.push }}
platforms: ${{ inputs.build_platforms }}
tags: ${{ inputs.tags }}
target: ${{ inputs.target }}
file: ${{ inputs.dockerfile }}
no-cache: ${{ inputs.no_cache }}
provenance: ${{ inputs.provenance }}
load: ${{ inputs.load }}
build-args: ${{ inputs.build_args }}
secrets: ${{ inputs.build_repo_secret_name != '' && format('"{0}={1}"', inputs.build_repo_secret_name, secrets[inputs.build_repo_secret_name]) || '' }}
</code>
## inputs definition
on:
workflow_call:
inputs:
build_repo_secret_name:
description: 'Build Arguments (format: "secret_name")'
required: false
type: string
default: ''
## some other inputs
# the action i am mentioning
- name: Docker build and push
id: build-and-push
uses: docker/build-push-action@v5
with:
context: ${{ inputs.context }}
push: ${{ inputs.push }}
platforms: ${{ inputs.build_platforms }}
tags: ${{ inputs.tags }}
target: ${{ inputs.target }}
file: ${{ inputs.dockerfile }}
no-cache: ${{ inputs.no_cache }}
provenance: ${{ inputs.provenance }}
load: ${{ inputs.load }}
build-args: ${{ inputs.build_args }}
secrets: ${{ inputs.build_repo_secret_name != '' && format('"{0}={1}"', inputs.build_repo_secret_name, secrets[inputs.build_repo_secret_name]) || '' }}
I then reuse the workflow with build_repo_secret_name=A_SECRET_NAME
.
Now i want to be able to use multiple secret names, such as build_repo_secret_name=A_SECRET_NAME_1,A_SECRET_NAME_2
. How should I modify the Docker build and push
action to consume the new format of build_repo_secret_name
?
Much appreciate for any help. Thanks.