Skip to content

Commit ab0daac

Browse files
committed
Initial commit
1 parent 48f1245 commit ab0daac

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# `cardano-node-ogmios` Docker Sync GitHub Action
2+
Use this action to sync an instance of `cardano-node-ogmios` into a cache to
3+
enable integration testing within a GitHub Workflow. As demonstrated in the
4+
[Ogmios repository](), the [network synchronization workflow]() synchronizes a testnet instance
5+
every six hours, which is then pushed to a cache used in the [continuous integration workflow]().
6+
7+
8+
['Ogmios repository']: https://github.com/CardanoSolutions/ogmios
9+
[network synchronization workflow]: https://github.com/CardanoSolutions/ogmios/blob/master/.github/workflows/network-synchronization.yaml
10+
[continuous integration workflow]: https://github.com/CardanoSolutions/ogmios/blob/master/.github/workflows/continuous-integration.yaml

action.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: cardano-node-ogmios-docker-sync
2+
description: Synchronize cardano-node-ogmios using Docker
3+
inputs:
4+
container-name:
5+
description: Docker container name
6+
required: false
7+
default: cardano-node-ogmios
8+
db-dir:
9+
description: Path to the host db mount
10+
required: true
11+
network:
12+
description: Cardano network
13+
required: true
14+
ogmios-port:
15+
description: Mapped host Ogmios port
16+
required: false
17+
default: '1337'
18+
repository:
19+
description: Docker repository
20+
required: false
21+
default: cardanosolutions/cardano-node-ogmios
22+
version:
23+
description: Ogmios version
24+
required: false
25+
default: latest
26+
runs:
27+
using: composite
28+
steps:
29+
- name: 🔵 Set Docker Image
30+
id: docker-image
31+
shell: bash
32+
run: |
33+
echo "::set-output name=value::${{ inputs.repository }}:${{ inputs.version }}-${{ inputs.network }}"
34+
35+
- name: 📥 Pull Image
36+
run: |
37+
docker pull ${{ steps.docker-image.outputs.value }}
38+
shell: bash
39+
40+
- name: ⟲ Sync
41+
run: |
42+
docker run -d --name ${{ inputs.container-name }} -p ${{ inputs.ogmios-port }}:1337 -v ${{ inputs.db-dir }}:/db ${{ steps.docker-image.outputs.value }}
43+
./scripts/wait-for-sync.sh ${{ inputs.ogmios-port }} 1
44+
shell: bash
45+
46+
- name: 🧹 Cleanup
47+
run: |
48+
docker stop ${{ inputs.container-name }}
49+
docker rm ${{ inputs.container-name }}
50+
docker rmi ${{ steps.docker-image.outputs.value }}
51+
shell: bash

scripts/wait-for-sync.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env bash
2+
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
7+
# wait-for-sync.sh
8+
#
9+
# Wait for an ogmios / cardano-node to be synchronized with the network, up to a given threshold.
10+
#
11+
# Usage: ./wait-for-sync.sh OGMIOS_PORT THRESHOLD
12+
#
13+
# Examples:
14+
# ./wait-for-sync.sh 1337 1
15+
# ./wait-for-sync.sh 1338 0.95
16+
17+
18+
set -eo pipefail
19+
20+
exitWithUsage () {
21+
echo -e "Error: missing argument(s)!\n"
22+
echo -e "Usage: $0 OGMIOS_PORT THRESHOLD"
23+
echo -e " Wait until a running Ogmios server at OGMIOS_PORT reaches THRESHOLD network synchronization.\n"
24+
echo -e "Example: \n $0 1338 0.95"
25+
exit 1
26+
}
27+
28+
OGMIOS_PORT=$1
29+
if [ -z "$OGMIOS_PORT" ]; then
30+
exitWithUsage
31+
fi
32+
33+
THRESHOLD=$2
34+
if [ -z "$THRESHOLD" ]; then
35+
exitWithUsage
36+
fi
37+
38+
URL=http://localhost:$OGMIOS_PORT/health
39+
40+
showProgress () {
41+
N="$1"
42+
PER=$(printf "%.3f\n" "$(bc <<< "$N * 100")")
43+
LEN=$(printf "%.0f\n" "$(bc <<< "$N * 50")")
44+
45+
BAR=""
46+
for ((i=1; i<=$LEN; i++))
47+
do
48+
BAR="$BAR"
49+
done
50+
for ((i=$LEN; i<=50; i++))
51+
do
52+
BAR="$BAR "
53+
done
54+
55+
echo -en "Network synchronization: [$BAR] $PER%\r"
56+
}
57+
58+
for (( ;; ))
59+
do
60+
HEALTH=$(curl -sS $URL)
61+
NETWORK_SYNCHRONIZATION=$(sed 's/.*"networkSynchronization":\([0-9]\+\.\?[0-9]*\).*/\1/' <<< $HEALTH)
62+
63+
RE='^[0-9]+\.?[0-9]*$'
64+
if ! [[ $NETWORK_SYNCHRONIZATION =~ $RE ]] ; then
65+
echo "error: unexpected response from /health endpoint: $HEALTH"
66+
exit 1
67+
fi
68+
69+
showProgress $NETWORK_SYNCHRONIZATION
70+
PREDICATE=$(bc <<< "$NETWORK_SYNCHRONIZATION >= $THRESHOLD")
71+
72+
if [ "$PREDICATE" -eq 1 ]; then
73+
exit 0
74+
else
75+
sleep 5
76+
fi
77+
done

0 commit comments

Comments
 (0)