From 7a343a3c3152d358f4f902503ed3b2e16bf11bf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matev=C5=BE=20Jekovec?= Date: Thu, 26 Oct 2023 00:43:49 +0200 Subject: [PATCH] feat: Add test for sapphire- and emerald-dev images --- .github/workflows/docker-dev.yml | 23 +++++++++++++++++++++- docker/emerald-dev/test.sh | 26 +++++++++++++++++++++++++ docker/sapphire-dev/test.sh | 33 ++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100755 docker/emerald-dev/test.sh create mode 100755 docker/sapphire-dev/test.sh diff --git a/.github/workflows/docker-dev.yml b/.github/workflows/docker-dev.yml index 5b91153c..2265f560 100644 --- a/.github/workflows/docker-dev.yml +++ b/.github/workflows/docker-dev.yml @@ -4,6 +4,9 @@ on: push: branches: - main + pull_request: + branches: + - main jobs: docker: @@ -33,7 +36,24 @@ jobs: run: | echo "VERSION=$(date +%Y-%m-%d-git$(git rev-parse --short HEAD))" >> $GITHUB_ENV - - name: Build and push + - name: Build + uses: docker/build-push-action@v5 + with: + build-args: | + VERSION=${{ env.VERSION }} + context: . + file: docker/${{ matrix.docker_image }}/Dockerfile + tags: | + ghcr.io/oasisprotocol/${{ matrix.docker_image }}:local + load: true + + - name: Test + timeout-minutes: 5 + working-directory: docker/${{ matrix.docker_image }} + run: ./test.sh + + - name: Push + if: ${{ github.event_name == 'push' }} uses: docker/build-push-action@v5 with: build-args: | @@ -49,6 +69,7 @@ jobs: org.opencontainers.image.revision=${{ github.sha }} - name: Prune old ghcr.io/oasisprotocol/${{ matrix.docker_image }} images + if: ${{ github.event_name == 'push' }} uses: vlaurin/action-ghcr-prune@v0.5.0 with: token: ${{ secrets.GITHUB_TOKEN }} diff --git a/docker/emerald-dev/test.sh b/docker/emerald-dev/test.sh new file mode 100755 index 00000000..f6137e30 --- /dev/null +++ b/docker/emerald-dev/test.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -euo pipefail + +TAG=${TAG:-ghcr.io/oasisprotocol/emerald-dev:local} +NAME="emerald-dev-test" + +cleanup() { + # Print standard output content. + docker logs "${NAME}" || true + # Stop the docker container. + docker stop "${NAME}" >/dev/null || true +} + +trap cleanup INT TERM + +docker run -itd --rm -p8545:8545 --name "${NAME}" "${TAG}" -test-mnemonic >/dev/null + +# Check, if depositing tokens to test accounts worked. +while true; do + OUT=$(curl -s -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65", "latest"],"id":1}' http://localhost:8545 || true) + echo $OUT | grep -q 0x21e19e0c9bab2400000 && break + sleep 1 +done + +cleanup diff --git a/docker/sapphire-dev/test.sh b/docker/sapphire-dev/test.sh new file mode 100755 index 00000000..c79cdb7b --- /dev/null +++ b/docker/sapphire-dev/test.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -euo pipefail + +TAG=${TAG:-ghcr.io/oasisprotocol/sapphire-dev:local} +NAME="sapphire-dev-test" + +cleanup() { + # Print standard output content. + docker logs "${NAME}" || true + # Stop the docker container. + docker stop "${NAME}" >/dev/null || true +} + +trap cleanup INT TERM + +docker run -itd --rm -p8545:8545 --name "${NAME}" "${TAG}" -test-mnemonic >/dev/null + +# Check, if depositing tokens to test accounts worked. +while true; do + OUT=$(curl -s -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65", "latest"],"id":1}' http://localhost:8545 || true) + echo $OUT | grep -q 0x21e19e0c9bab2400000 && break + sleep 1 +done + +# Check, if public ephemeral key needed for c10l contracts exists. +while true; do + OUT=$(curl -s -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"oasis_callDataPublicKey","params":[],"id":2}' http://localhost:8545 || true) + echo $OUT | grep -q checksum && break + sleep 1 +done + +cleanup