diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 93727452..0df4deec 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -25,7 +25,7 @@ jobs: name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Build and push + name: Build and push for mercury-server uses: docker/build-push-action@v5 with: context: . @@ -33,7 +33,7 @@ jobs: push: true tags: commerceblockx/mercury-server:latest - - name: Build and push + name: Build and push for token-server uses: docker/build-push-action@v5 with: context: . @@ -41,10 +41,18 @@ jobs: push: true tags: commerceblockx/token-server:latest - - name: Build and push + name: Build and pushh for mercury-explorer uses: docker/build-push-action@v5 with: context: . file: ./explorer/Dockerfile push: true tags: commerceblockx/mercury-explorer:latest + - + name: Build and push for keylist-cronjob + uses: docker/build-push-action@v5 + with: + context: . + file: ./keylistCron/Dockerfile + push: true + tags: commerceblockx/keylist-cronjob:latest diff --git a/keylistCron/Dockerfile b/keylistCron/Dockerfile new file mode 100644 index 00000000..1bf53ecd --- /dev/null +++ b/keylistCron/Dockerfile @@ -0,0 +1,11 @@ +FROM alpine:latest + +RUN apk update && apk add --no-cache curl postgresql-client jq +WORKDIR /app + +COPY ../keylistCron/send_commitment.sh . + +RUN chmod +x /app/send_commitment.sh + +# CMD to run cron and keep container running +CMD ["sh", "send_commitment.sh"] diff --git a/keylistCron/crontab.txt b/keylistCron/crontab.txt new file mode 100644 index 00000000..f4af5f7f --- /dev/null +++ b/keylistCron/crontab.txt @@ -0,0 +1 @@ +0 0 * * * /app/send_commitment.sh \ No newline at end of file diff --git a/keylistCron/send_commitment.sh b/keylistCron/send_commitment.sh new file mode 100644 index 00000000..aec8d2cb --- /dev/null +++ b/keylistCron/send_commitment.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Fetch keylist JSON from the provided URL +KEYLIST_JSON=$(curl -sSL "$KEYLIST_URL" | jq -r '.list_keyinfo' | sed 's/"/\\"/g') + +# Check if the GET request was successful +if [[ $? -ne 0 ]]; then + echo "Error: Failed to retrieve keylist JSON from $KEYLIST_URL" + exit 1 +fi + +# Calculate SHA256 hash of the keylist JSON +KEYLIST_HASH=$(echo "$KEYLIST_JSON" | sha256sum | awk '{print $1}') + +# Construct the POST request body +PAYLOAD="{ + \"position\": \"$POSITION\", + \"token\": \"$TOKEN\", + \"commitment\": \"$KEYLIST_HASH\" +}" + +# Send POST request to mainstay slot +curl --header "Content-Type: application/json" --request POST --data "$PAYLOAD" "$MAINSTAY_URL" + +# Check if the POST request was successful +if [[ $? -ne 0 ]]; then + echo "Error: Failed to send attestation data to $MAINSTAY_URL" + exit 1 +fi + +echo "Keylist $KEYLIST_HASH attestation completed successfully!" + +# Connect to the database and save the keylist JSON +PG_COMMAND="PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -p $DB_PORT -d $DB_NAME -U $DB_USER -c \"CREATE TABLE IF NOT EXISTS keylist_info ( json_data TEXT NOT NULL, keylist_hash TEXT NOT NULL ); INSERT INTO keylist_info (json_data, keylist_hash) VALUES ('$KEYLIST_JSON', '$KEYLIST_HASH');\"" + +# Execute the PostgreSQL command +eval "$PG_COMMAND" + +# Check if the command was successful +if [[ $? -ne 0 ]]; then + echo "Error: Failed to save keylist JSON to the database" + exit 1 +fi + +echo "Keylist JSON saved to the database successfully!"