Add SSH support to reusable workflows

This commit is contained in:
estebanthi
2026-01-04 16:50:30 +01:00
parent 74bd39fcd3
commit c001f91b5e
3 changed files with 59 additions and 0 deletions

View File

@@ -31,6 +31,10 @@ on:
required: true required: true
ci_token: ci_token:
required: true required: true
ssh_private_key:
required: false
ssh_known_hosts:
required: false
jobs: jobs:
build: build:
@@ -40,6 +44,19 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Start ssh-agent
if: ${{ secrets.ssh_private_key != '' }}
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.ssh_private_key }}
- name: Add SSH known hosts
if: ${{ secrets.ssh_known_hosts != '' }}
run: |
mkdir -p ~/.ssh
printf '%s\n' "${{ secrets.ssh_known_hosts }}" >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
@@ -64,6 +81,11 @@ jobs:
run: | run: |
set -euo pipefail set -euo pipefail
SSH_FLAGS=""
if [ -n "${SSH_AUTH_SOCK:-}" ]; then
SSH_FLAGS="--ssh default"
fi
echo "$IMAGES" | jq -c '.[]' | while read -r img; do echo "$IMAGES" | jq -c '.[]' | while read -r img; do
IMAGE_NAME=$(echo "$img" | jq -r '.name') IMAGE_NAME=$(echo "$img" | jq -r '.name')
FULL_IMAGE="${{ inputs.registry_host }}/${IMAGE_NAME}" FULL_IMAGE="${{ inputs.registry_host }}/${IMAGE_NAME}"
@@ -97,6 +119,7 @@ jobs:
--target "$TARGET" \ --target "$TARGET" \
--cache-from "type=registry,ref=$CACHE_REF" \ --cache-from "type=registry,ref=$CACHE_REF" \
--cache-to "type=registry,ref=$CACHE_REF,mode=max" \ --cache-to "type=registry,ref=$CACHE_REF,mode=max" \
$SSH_FLAGS \
--load \ --load \
$TAG_ARGS \ $TAG_ARGS \
$BUILD_ARG_FLAGS \ $BUILD_ARG_FLAGS \

View File

@@ -27,6 +27,11 @@ on:
test_command: test_command:
type: string type: string
default: "pnpm test" default: "pnpm test"
secrets:
ssh_private_key:
required: false
ssh_known_hosts:
required: false
jobs: jobs:
quality: quality:
@@ -37,6 +42,19 @@ jobs:
- name: Checkout source - name: Checkout source
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Start ssh-agent
if: ${{ secrets.ssh_private_key != '' }}
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.ssh_private_key }}
- name: Add SSH known hosts
if: ${{ secrets.ssh_known_hosts != '' }}
run: |
mkdir -p ~/.ssh
printf '%s\n' "${{ secrets.ssh_known_hosts }}" >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
- name: Set up Node - name: Set up Node
uses: actions/setup-node@v4 uses: actions/setup-node@v4
with: with:

View File

@@ -30,6 +30,11 @@ on:
test_command: test_command:
type: string type: string
default: "uv run pytest" default: "uv run pytest"
secrets:
ssh_private_key:
required: false
ssh_known_hosts:
required: false
jobs: jobs:
quality: quality:
@@ -43,6 +48,19 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Start ssh-agent
if: ${{ secrets.ssh_private_key != '' }}
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.ssh_private_key }}
- name: Add SSH known hosts
if: ${{ secrets.ssh_known_hosts != '' }}
run: |
mkdir -p ~/.ssh
printf '%s\n' "${{ secrets.ssh_known_hosts }}" >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
- name: Set up Python - name: Set up Python
uses: actions/setup-python@v5 uses: actions/setup-python@v5
with: with: