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

Add sanity check for oct endpoints #106

Merged
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
34 changes: 34 additions & 0 deletions .github/actions/slack-webhook-sender/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: slack-webhook-sender
description: 'Sends a slack message plus some more workflow job related fields to a slack webhook endpoint.'
inputs:
message:
description: 'Text that will be send in the json .message field.'
required: true
default: 'Hello, world!'
slack_webhook:
description: 'Slack webhook where the data will be posted.'
required: true
default: ''

runs:
using: 'composite'
steps:
- name: Post message data to slack's webhook url.
shell: bash
env:
MESSAGE: ${{ inputs.message }}
REPO_URL: 'https://github.com/${{ github.repository }}'
COMMIT_URL: 'https://github.com/${{ github.repository }}/commit/${{ github.sha }}'
JOB_URL: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}'
ATTEMPT: ${{ github.run_attempt }}
run: |
data="{ \
\"message\" : \"${MESSAGE}\", \
\"repo_url\" : \"${REPO_URL}\", \
\"job_url\" : \"${JOB_URL}\", \
\"commit_url\": \"${COMMIT_URL}\", \
\"attempt\" : \"${ATTEMPT}\" \
}"

echo "Sending alert message data to slack webhook: $(echo $data | jq)"
curl -X POST --data "${data}" -H 'Content-type: application/json; charset=UTF-8' '${{ inputs.slack_webhook }}'
6 changes: 5 additions & 1 deletion .github/workflows/pre-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ jobs:
run: make lint

- name: make vet
run: make vet
run: make vet

- name: Run endpoint verification script
run: |
./scripts/curl-endpoints.sh
12 changes: 12 additions & 0 deletions .github/workflows/recreate-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ jobs:
username: ${{ secrets.QUAY_ROBOT_USER }}
password: ${{ secrets.QUAY_ROBOT_TOKEN }}

- name: Run endpoint verification script
run: |
./scripts/curl-endpoints.sh

- name: Build and push the latest images for multi-arch
uses: docker/build-push-action@v5
with:
Expand All @@ -47,3 +51,11 @@ jobs:
push: true
tags: |
quay.io/testnetworkfunction/oct:latest


- name: If failed to create the image, send alert msg to dev team.
if: ${{ failure() }}
uses: ./.github/actions/slack-webhook-sender
with:
message: 'Failed to create official latest OCT image. Please check the logs.'
slack_webhook: '${{ secrets.SLACK_ALERT_WEBHOOK_URL }}'
27 changes: 27 additions & 0 deletions scripts/curl-endpoints.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# This script is used to test the endpoints of the API
# to make sure they are alive and healthy

# Define the endpoints
endpoints=(
"https://catalog.redhat.com/api/containers/v1/operators/bundles"
"https://catalog.redhat.com/api/containers/v1/images"
"https://catalog.redhat.com/api/containers/v1/ping"
"https://catalog.redhat.com/api/containers/v1/images?filter=certified==true&page_size=100&page=0&include=data.repositories,data.image_id,data.architecture,data.repositories.manifest_list_digest"
"https://charts.openshift.io/index.yaml"
"https://catalog.redhat.com/api/containers/v1/operators/bundles?filter=organization==certified-operators&page_size=100&page=0"
"https://catalog.redhat.com/api/containers/v1/operators/bundles?filter=organization==certified-operators"
)

# Loop through the endpoints and exit if any of them fail
for endpoint in "${endpoints[@]}"
do
printf "Testing endpoint: $endpoint\n"
curl -s -o /dev/null -w "%{http_code}" $endpoint
printf "\n"
if [ $? -ne 0 ]; then
echo "Failed to reach endpoint: $endpoint"
exit 1
fi
done
Loading