Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Refactor pull images #5297

Merged
merged 6 commits into from
Mar 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: "Pre-pull Images"
name: Image Pull

on:
pull_request:
branches: ["main"]
paths: ["kubernetes/main/**"]
paths:
- "kubernetes/main/**"
- "kubernetes/repositories/**"

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
pre-job:
name: Pre-pull Images Pre-Job
setup:
name: Image Pull - Setup
runs-on: ubuntu-latest
outputs:
any_changed: ${{ steps.changed-files.outputs.any_changed }}
Expand All @@ -27,18 +29,18 @@ jobs:
with:
files: kubernetes/main/**

extract-images:
name: Extract Images
needs: pre-job
extract:
if: ${{ needs.setup.outputs.any_changed == 'true' }}
name: Image Pull - Extract Images
needs: setup
runs-on: ubuntu-latest
if: ${{ needs.pre-job.outputs.any_changed == 'true' }}
strategy:
matrix:
branches: ["default", "pull"]
fail-fast: false
outputs:
default: ${{ steps.extract-images.outputs.default }}
pull: ${{ steps.extract-images.outputs.pull }}
default: ${{ steps.images.outputs.default }}
pull: ${{ steps.images.outputs.pull }}
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
Expand All @@ -58,50 +60,64 @@ jobs:
--output-file images.json

- name: Output Images
id: extract-images
# shellcheck disable=SC2086
run: echo "${{ matrix.branches }}=$(jq --compact-output '.' images.json)" >> $GITHUB_OUTPUT
id: images
run: |
echo "${{ matrix.branches }}=$(jq --compact-output '.' images.json)" >> "${GITHUB_OUTPUT}"

{
echo '## Branch ${{ matrix.branches }} images'
echo '```json'
jq '.' images.json
echo '```'
} >> "${GITHUB_STEP_SUMMARY}"

compare-images:
name: Compare Images
compare:
if: ${{ needs.setup.outputs.any_changed == 'true' && needs.extract.outputs.default != needs.extract.outputs.pull }}
name: Image Pull - Compare Images
runs-on: ubuntu-latest
needs: ["pre-job", "extract-images"]
needs: ["setup", "extract"]
outputs:
images: ${{ steps.compare-images.outputs.images }}
if: ${{ needs.pre-job.outputs.any_changed == 'true' && needs.extract-images.outputs.default != needs.extract-images.outputs.pull }}
images: ${{ steps.compare.outputs.images }}
steps:
- name: Compare Images
id: compare-images
id: compare
run: |
images=$(jq --compact-output --null-input \
--argjson f1 '${{ needs.extract-images.outputs.default }}' \
--argjson f2 '${{ needs.extract-images.outputs.pull }}' \
--argjson f1 '${{ needs.extract.outputs.default }}' \
--argjson f2 '${{ needs.extract.outputs.pull }}' \
'$f2 - $f1' \
)
echo "images=${images}" >> "${GITHUB_OUTPUT}"

pre-pull-images:
name: Pre-pull Images
runs-on: ["k8s-homelab-runner"]
needs: ["pre-job", "compare-images"]
{
echo '## New images to Pull'
echo '```json'
echo "${images}" | jq
echo '```'
} >> "${GITHUB_STEP_SUMMARY}"

pull:
if: ${{ needs.setup.outputs.any_changed == 'true' && needs.compare.outputs.images != '[]' }}
name: Image Pull - Pull Images
runs-on: k8s-homelab-runner
needs: ["setup", "compare"]
strategy:
matrix:
images: ${{ fromJSON(needs.compare-images.outputs.images) }}
images: ${{ fromJSON(needs.compare.outputs.images) }}
max-parallel: 4
fail-fast: false
if: ${{ needs.pre-job.outputs.any_changed == 'true' && needs.compare-images.outputs.images != '[]' }}
steps:
- name: Install talosctl
run: curl -fsSL https://talos.dev/install | sh

- name: Pre-pull Image
- name: Pull Image
run: talosctl -n "${NODE_IP}" image pull ${{ matrix.images }}

pre-pull-images-status:
needs: pre-pull-images
name: Pre-pull Images Success
runs-on: ubuntu-latest
status:
if: ${{ always() }}
name: Image Pull - Success
needs: pull
runs-on: ubuntu-latest
steps:
- name: Any jobs failed?
if: ${{ contains(needs.*.result, 'failure') }}
Expand Down