Skip to content

Commit

Permalink
feat: make job into multi-cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
joryirving committed Dec 28, 2024
1 parent 7ec5792 commit 1a24105
Showing 1 changed file with 66 additions and 7 deletions.
73 changes: 66 additions & 7 deletions .github/workflows/pre-pull-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ jobs:
app-id: ${{ env.BOT_APP_ID }}
private-key: ${{ env.BOT_APP_PRIVATE_KEY }}

- name: Setup Homebrew
uses: Homebrew/actions/setup-homebrew@master

- name: Setup mise
uses: jdx/mise-action@v2
with:
Expand Down Expand Up @@ -156,17 +153,79 @@ jobs:
echo "### Images" >> $GITHUB_STEP_SUMMARY
echo "${images}" | jq --raw-output 'to_entries[] | "* \(.value)"' >> $GITHUB_STEP_SUMMARY
pre-pull-images:
generate-matrix:
if: ${{ needs.extract-images.outputs.matrix != '[]' }}
name: Generate Matrix
runs-on: ubuntu-latest
needs: ["changed-clusters", "extract-images"]
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}
steps:
- name: Setup mise
uses: jdx/mise-action@v2
with:
mise_toml: |
[tools]
"aqua:mikefarah/yq" = "latest"
- name: Generate Combined Matrix
id: generate-matrix
run: |
images=${{ needs.extract-images.outputs.matrix }}
clusters=${{ needs.changed-clusters.outputs.matrix }}
# Define the talosconfig mapping as a valid JSON object
configs=$(echo "${clusters[@]}" | jq -n 'reduce inputs as $cluster (
{};
.[$cluster] = "op://Kubernetes/kubernetes/TALOSCONFIG_" + ($cluster | split("/")[1] | ascii_upcase)
)')
combined=$(echo "$images" | yq eval -j '
. as $images |
'"$clusters"' as $clusters |
'"$configs"' as $configs |
[
$images[] as $image |
$clusters[] as $cluster |
{
image: $image,
cluster: $cluster,
talosconfig: $configs[$cluster]
}
]
')
# Output the combined result
echo "Combined: $combined"
# Save to GITHUB_OUTPUT
echo "matrix=$combined" >> $GITHUB_OUTPUT
- name: Debug Combined Matrix
run: echo "${{ steps.generate-matrix.outputs.matrix }}"

pre-pull-images:
if: ${{ needs.generate-matrix.outputs.matrix != '[]' }}
name: Pre-pull Images
runs-on: ["gha-runner-scale-set"]
needs: ["extract-images"]
needs: ["generate-matrix"]
strategy:
matrix:
images: ${{ fromJSON(needs.extract-images.outputs.matrix) }}
matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }}
max-parallel: 4
fail-fast: false
steps:
- name: Configure 1password
uses: 1password/load-secrets-action/configure@v2
with:
service-account-token: ${{ secrets.ONEPASS_SA_TOKEN }}

- name: Get Secrets
uses: 1password/load-secrets-action@v2
with:
export-env: true
env:
TALOSCONFIG: ${{ matrix.talosconfig }}

- name: Setup mise
uses: jdx/mise-action@v2
with:
Expand Down

0 comments on commit 1a24105

Please sign in to comment.