Skip to content
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
21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ networks:

services:
### Dependencies
prestart-hook:
image: curlimages/curl-base:latest
container_name: prestart-hook
entrypoint: ["/bin/sh", "-c", "apk add --no-cache bash && /bin/bash /prestart_hook.sh"]
volumes:
- ./scripts/prestart_hook.sh:/prestart_hook.sh
networks:
- router_net

pg:
image: postgres:latest
ports:
Expand Down Expand Up @@ -86,6 +95,18 @@ services:
start_period: 5s
timeout: 5s

poststart-hook:
image: curlimages/curl-base:latest
container_name: poststart-hook
depends_on:
hyperswitch-server:
condition: service_healthy # Ensures it only starts when `hyperswitch-server` is healthy
entrypoint: ["/bin/sh", "-c", "apk add --no-cache bash jq && /bin/bash /poststart_hook.sh"]
volumes:
- ./scripts/poststart_hook.sh:/poststart_hook.sh
networks:
- router_net

hyperswitch-producer:
image: docker.juspay.io/juspaydotin/hyperswitch-producer:standalone
pull_policy: always
Expand Down
65 changes: 65 additions & 0 deletions scripts/poststart_hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#! /usr/bin/env bash
set -euo pipefail

# Configuration
PLATFORM="docker-compose" # Change to "helm" or "cdk" as needed
VERSION="unknown"
STATUS=""
SERVER_BASE_URL="http://hyperswitch-server:8080"
HYPERSWITCH_HEALTH_URL="${SERVER_BASE_URL}/health"
HYPERSWITCH_DEEP_HEALTH_URL="${SERVER_BASE_URL}/health/ready"
WEBHOOK_URL="https://hyperswitch.gateway.scarf.sh/${PLATFORM}"

# Fetch health status
echo "Fetching app server health status..."
HEALTH_RESPONSE=$(curl --silent --fail "${HYPERSWITCH_HEALTH_URL}") || HEALTH_RESPONSE="connection_error"

if [[ "${HEALTH_RESPONSE}" == "connection_error" ]]; then
STATUS="error"
ERROR_MESSAGE="404 response"

curl --get "${WEBHOOK_URL}" \
--data-urlencode "version=${VERSION}" \
--data-urlencode "status=${STATUS}" \
--data-urlencode "error_message=${ERROR_MESSAGE}"

echo "Webhook sent with connection error."
exit 0
fi

# Fetch Hyperswitch version
VERSION=$(curl --silent --output /dev/null --request GET --write-out '%header{x-hyperswitch-version}' "${HYPERSWITCH_DEEP_HEALTH_URL}" | sed 's/-dirty$//')

echo "Fetching Hyperswitch health status..."
HEALTH_RESPONSE=$(curl --silent "${HYPERSWITCH_DEEP_HEALTH_URL}")

# Prepare curl command
CURL_COMMAND=("curl" "--get" "${WEBHOOK_URL}" "--data-urlencode" "version=${VERSION}")

# Check if the response contains an error
if [[ "$(echo "${HEALTH_RESPONSE}" | jq --raw-output '.error')" != 'null' ]]; then
STATUS="error"
ERROR_TYPE=$(echo "${HEALTH_RESPONSE}" | jq --raw-output '.error.type')
ERROR_MESSAGE=$(echo "${HEALTH_RESPONSE}" | jq --raw-output '.error.message')
ERROR_CODE=$(echo "${HEALTH_RESPONSE}" | jq --raw-output '.error.code')

CURL_COMMAND+=(
"--data-urlencode" "status=${STATUS}"
"--data-urlencode" "error_type=${ERROR_TYPE}"
"--data-urlencode" "error_message=${ERROR_MESSAGE}"
"--data-urlencode" "error_code=${ERROR_CODE}"
)
else
STATUS="success"
CURL_COMMAND+=("--data-urlencode" "status=${STATUS}")

for key in $(echo "${HEALTH_RESPONSE}" | jq --raw-output 'keys_unsorted[]'); do
value=$(echo "${HEALTH_RESPONSE}" | jq --raw-output --arg key "${key}" '.[$key]')
CURL_COMMAND+=("--data-urlencode" "'${key}=${value}'")
done
fi

# Send the webhook request
bash -c "${CURL_COMMAND[*]}"

echo "Webhook notification sent."
14 changes: 14 additions & 0 deletions scripts/prestart_hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#! /usr/bin/env bash
set -euo pipefail

# Define the URL and parameters
PLATFORM="docker-compose"
WEBHOOK_URL="https://hyperswitch.gateway.scarf.sh/${PLATFORM}"
VERSION="unknown"
STATUS="initiated"

# Send the GET request
curl --get "${WEBHOOK_URL}" --data-urlencode "version=${VERSION}" --data-urlencode "status=${STATUS}"

# Print confirmation
echo "Request sent to ${WEBHOOK_URL} with version=${VERSION} and status=${STATUS}"
Loading