Skip to content

Commit 3058b62

Browse files
committed
add ssh and secrets inputs to build workflow
Expose ssh and secrets inputs in workflow_call and pass them through to docker/build-push-action. Set up ssh-agent when ssh is configured so SSH_AUTH_SOCK is available for BuildKit SSH mounts.
1 parent 701e2d7 commit 3058b62

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ on:
7676
type: string
7777
description: "List of target platforms to build"
7878
required: false
79+
secrets:
80+
type: string
81+
description: "List of secrets to expose to the build"
82+
required: false
7983
push:
8084
type: boolean
8185
description: "Push image to the registry (for image output)"
@@ -90,6 +94,10 @@ on:
9094
type: string
9195
description: "Size of /dev/shm (e.g., 2g)"
9296
required: false
97+
ssh:
98+
type: string
99+
description: "List of SSH agent socket or keys to expose to the build"
100+
required: false
93101
sign:
94102
type: string
95103
description: "Sign attestation manifest for image output or artifacts for local output, can be one of auto, true or false. The auto mode will enable signing if push is enabled for pushing the image or if artifact-upload is enabled for uploading the local build output as GitHub Artifact"
@@ -133,6 +141,9 @@ on:
133141
github-token:
134142
description: "GitHub Token used to authenticate against the repository for Git context"
135143
required: false
144+
ssh-private-key:
145+
description: "SSH private key used to populate SSH_AUTH_SOCK for buildx SSH mounts"
146+
required: false
136147
outputs:
137148
meta-json:
138149
description: "Metadata JSON output (for image output)"
@@ -653,6 +664,14 @@ jobs:
653664
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
654665
with:
655666
registry-auth: ${{ secrets.registry-auths }}
667+
-
668+
name: Set up ssh-agent
669+
if: ${{ inputs.ssh }}
670+
shell: bash
671+
run: |
672+
eval "$(ssh-agent -s)"
673+
echo "${{ secrets.ssh-private-key }}" | tr -d '\r' | ssh-add -
674+
echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> "$GITHUB_ENV"
656675
-
657676
name: Build
658677
id: build
@@ -669,8 +688,10 @@ jobs:
669688
platforms: ${{ steps.prepare.outputs.platform }}
670689
provenance: ${{ steps.prepare.outputs.provenance }}
671690
sbom: ${{ steps.prepare.outputs.sbom }}
691+
secrets: ${{ inputs.secrets }}
672692
secret-envs: GIT_AUTH_TOKEN=GIT_AUTH_TOKEN
673693
shm-size: ${{ inputs.shm-size }}
694+
ssh: ${{ inputs.ssh }}
674695
target: ${{ inputs.target }}
675696
ulimit: ${{ inputs.ulimit }}
676697
env:

0 commit comments

Comments
 (0)