Skip to content

Change running logic for runners to use a workdir in creation #2437

Change running logic for runners to use a workdir in creation

Change running logic for runners to use a workdir in creation #2437

name: Check for new image and create PR
on:
push:
branches:
- main
schedule:
- cron: '0 * * * *' # Runs every hour
env:
ORG_NAME: ${{ github.repository_owner }}
PROD_BRANCH: from-staging-to-prod
jobs:
check-for-updates-for-staging:
strategy:
max-parallel: 1
matrix:
image: [ir-api, jobcontroller, rundetection, runner]
runs-on: ubuntu-latest
steps:
- name: Sleep for 2 seconds
run: sleep 2s
shell: bash
- name: Checkout code
uses: actions/checkout@v4
- name: Check for new image
id: check-image
run: |
# Use Docker Registry API to check for new image
GHCR_TOKEN=$(curl https://ghcr.io/token\?scope\="repository:${ORG_NAME}/${{ matrix.image }}:pull" | jq -r '.token')
LATEST_TAG=$(curl -H "Authorization: Bearer ${GHCR_TOKEN}" https://ghcr.io/v2/${ORG_NAME}/${{ matrix.image }}/tags/list | jq -r '.tags[-1]')
echo "Latest tag: ${LATEST_TAG}"
LATEST_SHA256_VALUE=$(docker manifest inspect ghcr.io/${ORG_NAME}/${{ matrix.image }}:${LATEST_TAG} | jq -r '.config.digest')
LATEST_SHA="${LATEST_SHA256_VALUE#*:}"
echo "Latest sha: ${LATEST_SHA}"
echo "latest-sha=${LATEST_SHA}" >> $GITHUB_OUTPUT
- name: Get staging Kubernetes manifest sha
id: check-manifest-staging
run: |
# Extract current image tag from Kubernetes manifest
# This is just an example, replace with your own logic
if [[ ${{ matrix.image }} == "runner" ]]; then
MANIFEST_PATH=components/jobcontroller/overlays/staging/jobcontroller.yml
CURRENT_SHA=$(sed -n '/- name: RUNNER_SHA/{n;p;}' ${MANIFEST_PATH} | cut -d':' -f2)
else
MANIFEST_PATH=components/${{ matrix.image }}/overlays/staging/${{ matrix.image }}.yml
CURRENT_SHA=$(cat ${MANIFEST_PATH} | grep 'image:' | cut -d':' -f3)
fi
echo "Current sha: ${CURRENT_SHA}"
echo "current-sha=${CURRENT_SHA}" >> $GITHUB_OUTPUT
- name: Update staging kubernetes manifest if current new sha
run: |
# If current tag is different from latest tag, update the manifest
MANIFEST_PATH=components/${{ matrix.image }}/overlays/staging/${{ matrix.image }}.yml
if [[ ${{ matrix.image }} == "runner" ]]; then
MANIFEST_PATH=components/jobcontroller/overlays/staging/jobcontroller.yml
fi
echo "Comparing current sha vs latest sha - "${{ steps.check-manifest.outputs.current-sha }} vs ${{ steps.check-image.outputs.latest-sha }}""
if [[ "${{ steps.check-manifest-staging.outputs.current-sha }}" != "${{ steps.check-image.outputs.latest-sha }}" ]] && [[ "$steps.check-image.outputs.latest-sha" != null ]]; then
# Update Kubernetes manifest with new sha
# This is just an example, replace with your own logic
sed -i "s/"${{ steps.check-manifest-staging.outputs.current-sha }}"/${{ steps.check-image.outputs.latest-sha }}/g" ${MANIFEST_PATH}
fi
# - name: Commit changes for staging to main
# uses: stefanzweifel/git-auto-commit-action@v4
# with:
# commit_message: "Update ${{ matrix.image }} tag to ${{ steps.check-image.outputs.latest-tag }}"
# branch: ${{ github.head_ref }}
# - name: Get production Kubernetes manifest tag
# id: check-manifest-production
# run: |
# # Extract current image tag from Kubernetes manifest
# # This is just an example, replace with your own logic
# MANIFEST_PATH=components/${{ matrix.image }}/overlays/production/${{ matrix.image }}.yml
# CURRENT_TAG=$(cat ${MANIFEST_PATH} | grep 'image:' | cut -d':' -f3)
# echo "Current Tag: ${CURRENT_TAG}"
# echo "current-tag=${CURRENT_TAG}" >> $GITHUB_OUTPUT
#
# - name: Update production kubernetes manifest if new tag was made
# run: |
# # If current tag is different from latest tag, update the manifest
# MANIFEST_PATH=components/${{ matrix.image }}/overlays/production/${{ matrix.image }}.yml
# echo "Comparing current tag vs latest tag - "${{ steps.check-manifest.outputs.current-tag }} vs ${{ steps.check-image.outputs.latest-tag }}""
# if [[ "${{ steps.check-manifest-production.outputs.current-tag }}" != "${{ steps.check-image.outputs.latest-tag }}" ]] && [[ "$steps.check-image.outputs.latest-tag" != null ]]; then
# # Update Kubernetes manifest with new tag
# # This is just an example, replace with your own logic
# sed -i "s/"${{ steps.check-manifest-production.outputs.current-tag }}"/${{ steps.check-image.outputs.latest-tag }}/g" ${MANIFEST_PATH}
# fi
# - name: Create pull request for prod
# uses: peter-evans/[email protected]
# with:
# token: ${{ secrets.GITHUB_TOKEN }}
# commit-message: Update images
# committer: IR-CD-bot <[email protected]>
# author: IR-CD-bot <[email protected]>
# title: Update images for production
# body: This PR updates the image tag in the Kubernetes manifest to the most recently created and the one that should be present in staging.