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

feat(ci): ETL sync scheduled job #1408

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
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
49 changes: 0 additions & 49 deletions .github/workflows/.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ on:
default: ''
required: false
type: string
# etl:
# description: Run the cronjob and verify results? [true|false]
# default: false
# required: false
# type: boolean
tag:
description: Container tag; usually PR number
default: ${{ github.event.number }}
Expand Down Expand Up @@ -141,8 +136,6 @@ jobs:
- name: sync
file: sync/openshift.deploy.yml
overwrite: true
parameters:
# post_rollout: ${{ inputs.etl == 'true' && 'oc create job ${{ env.RUN_JOB }} --from=cronjob/${{ env.CRONJOB }}' || ''}}

steps:
- uses: bcgov-nr/[email protected]
Expand All @@ -167,45 +160,3 @@ jobs:
verification_retry_seconds: "20"
- id: trigger
run: echo "triggered=${{ steps.deploys.outputs.triggered }}" >> $GITHUB_OUTPUT

verify:
name: Verify ETL
if: inputs.etl == 'true' && needs.init.outputs.triggered == 'true'
environment: ${{ inputs.environment }}
needs: [deploy, init]
runs-on: ubuntu-latest
steps:
- name: Override OpenShift version
env:
OC: https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable-4.13/openshift-client-linux.tar.gz
run: |
curl --silent ${{ env.OC }} | tar -xzvf - oc
oc version
working-directory: /usr/local/bin/

- name: Job
run: |
# Run and verify job

# Login
oc login --token=${{ secrets.oc_token }} --server=${{ vars.oc_server }}
oc project ${{ secrets.oc_namespace }} #Safeguard!

# Create job
CRONJOB=${{ github.event.repository.name }}-${{ inputs.target }}-sync
RUN_JOB=${CRONJOB}-${{ github.run_number }}-${{ github.run_attempt}}
oc create job ${RUN_JOB} --from=cronjob/${CRONJOB}

# Follow
oc wait --for=jsonpath='{.status.failed}'=4 job/${RUN_JOB} --timeout=10m || true
oc logs -l job-name=${RUN_JOB} --tail=50 --follow

# Results and exit code
oc get job ${RUN_JOB}

if [ $(oc get job ${RUN_JOB} -o jsonpath='{.status.ready}') -eq 0 ]; then
echo "Job successful!"
else
echo "Job failed!"
exit 1
fi
51 changes: 51 additions & 0 deletions .github/workflows/sync-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Scheduled ETL Sync

on:
schedule: [cron: "0 */2 * * *"] # Every other hour on the hour
workflow_dispatch:

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

jobs:
sync:
name: Sync
runs-on: ubuntu-latest
environment: test
steps:
- name: Override OpenShift version
env:
OC: https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable-4.13/openshift-client-linux.tar.gz
run: |
curl --silent ${{ env.OC }} | tar -xzvf - oc
oc version
working-directory: /usr/local/bin/

- name: ETL Sync
run: |
# Run and verify job

# Login
oc login --token=${{ secrets.oc_token }} --server=${{ vars.oc_server }}
oc project ${{ secrets.oc_namespace }} #Safeguard!

# Create job
CRONJOB=${{ github.event.repository.name }}-test-sync
RUN_JOB=${CRONJOB}-$(nr-spar: date +"%Y-%m-%d_%H:%M:%S")
oc create job ${RUN_JOB} --from=cronjob/${CRONJOB}

# Follow
oc wait --for=jsonpath='{.status.failed}'=4 job/${RUN_JOB} --timeout=10m || true
oc logs -l job-name=${RUN_JOB} --tail=50 --follow

# Results
oc get job ${RUN_JOB}

# Handle exit code
if [ $(oc get job ${RUN_JOB} -o jsonpath='{.status.ready}') -eq 0 ]; then
echo "Job successful!"
else
echo "Job failed!"
exit 1
fi
Loading