From 03f5622beaddc31e7fd93e90558f4e2495dc47f0 Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Wed, 5 Jul 2023 18:15:05 +0800 Subject: [PATCH] Add Gitea CI workflow * use dedicated access token for pulling private repos Co-authored-by: Thomas E Lackey --- .gitea/workflows/test.yml | 89 ++++++++++++++++++++++++++++++++++++ Dockerfile | 19 ++++---- go.mod | 6 +-- go.sum | 8 ++-- scripts/integration-setup.sh | 27 +++++++++++ test/compose.yml | 5 +- test/stack-refs.txt | 1 + 7 files changed, 135 insertions(+), 20 deletions(-) create mode 100644 .gitea/workflows/test.yml create mode 100755 scripts/integration-setup.sh create mode 100644 test/stack-refs.txt diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml new file mode 100644 index 0000000..f0f4a35 --- /dev/null +++ b/.gitea/workflows/test.yml @@ -0,0 +1,89 @@ +name: Test + +on: + pull_request: + branches: '*' + push: + branches: + - main + - ci-test + +# Needed until we can incorporate docker startup into the executor container +env: + DOCKER_HOST: unix:///var/run/dind.sock + +jobs: + unit-tests: + name: "Run unit tests" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version-file: 'go.mod' + check-latest: true + - name: "Run dockerd" + run: | + dockerd -H $DOCKER_HOST --userland-proxy=false & + sleep 5 + - name: "Run DB container" + run: | + docker compose -f test/compose.yml up --wait + - name: "Set up Gitea access token" + env: + TOKEN: ${{ secrets.CICD_REPO_TOKEN }} + run: | + git config --global url."https://$TOKEN:@git.vdb.to/".insteadOf https://git.vdb.to/ + - name: "Run tests" + run: go test -v ./... + + integration-tests: + name: "Run integration tests" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + path: ./plugeth-statediff + # TODO: replace with release + - uses: actions/checkout@v3 + with: + repository: cerc-io/plugeth + ref: statediff-wip + path: ./plugeth + - name: "Run dockerd" + run: dockerd -H $DOCKER_HOST --userland-proxy=false & + # These images need access tokens configured + - name: "Build docker image" + env: + TOKEN: ${{ secrets.CICD_REPO_TOKEN }} + run: | + [[ -n "$TOKEN" ]] + docker build ./plugeth-statediff -t cerc/plugeth-statediff:local \ + --build-arg GIT_VDBTO_TOKEN="$TOKEN" + docker build ./plugeth -t cerc/plugeth:local \ + --build-arg GIT_VDBTO_TOKEN="$TOKEN" + + - name: "Install stack-orchestrator" + uses: actions/checkout@v3 + with: + repository: roysc/stack-orchestrator + ref: plugeth-testing + path: ./stack-orchestrator + - run: | + apt-get update && apt-get install -y python3-pip + pip install ./stack-orchestrator + - name: "Run testnet stack" + working-directory: ./plugeth-statediff + run: ./scripts/integration-setup.sh + - name: "Clone system-tests" + uses: actions/checkout@v3 + with: + repository: cerc-io/system-tests + ref: main + path: ./system-tests + - name: "Run tests" + working-directory: ./system-tests + run: | + pip install pytest + pip install -r requirements.txt + pytest -v -k test_basic_db diff --git a/Dockerfile b/Dockerfile index 7601be5..9b3ed2c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,21 @@ -# Using the same base golang image as geth -FROM golang:1.20-alpine as builder +# Using the same base golang image as plugeth +FROM golang:1.20-alpine3.18 as builder RUN apk add --no-cache gcc musl-dev binutils-gold linux-headers git -WORKDIR /plugeth-statediff/ +# Configure creds for gitea +ARG GIT_VDBTO_TOKEN # Get and cache deps -COPY go.mod . -COPY go.sum . -RUN go mod download +WORKDIR /plugeth-statediff/ +COPY go.mod go.sum ./ +RUN if [ -n "$GIT_VDBTO_TOKEN" ]; then git config --global url."https://$GIT_VDBTO_TOKEN:@git.vdb.to/".insteadOf "https://git.vdb.to/"; fi && \ + go mod download && \ + rm -f ~/.gitconfig -ADD . . +COPY . . RUN go build --tags linkgeth --buildmode=plugin --trimpath -o statediff.so ./main -FROM alpine:latest +FROM alpine:3.18 COPY --from=builder /plugeth-statediff/statediff.so /usr/local/lib/ diff --git a/go.mod b/go.mod index 31f956b..f62d7fd 100644 --- a/go.mod +++ b/go.mod @@ -122,8 +122,6 @@ require ( ) replace ( - // github.com/ethereum/go-ethereum => ../plugeth - // github.com/openrelayxyz/plugeth-utils => ../plugeth-utils - github.com/ethereum/go-ethereum => git.vdb.to/cerc-io/plugeth v0.0.0-20230629081247-feb6ccc72b3f - github.com/openrelayxyz/plugeth-utils => git.vdb.to/cerc-io/plugeth-utils v0.0.0-20230622072028-1d3da8ce80ee + github.com/ethereum/go-ethereum => git.vdb.to/cerc-io/plugeth v0.0.0-20230710223804-34971d65a36a + github.com/openrelayxyz/plugeth-utils => git.vdb.to/cerc-io/plugeth-utils v0.0.0-20230706160122-cd41de354c46 ) diff --git a/go.sum b/go.sum index 1d9c3e8..75c1adc 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -git.vdb.to/cerc-io/plugeth v0.0.0-20230629081247-feb6ccc72b3f h1:QGxQXUa53S1Ci+gp17zjw5TI62q4fyZ/PTvHQ72FxZw= -git.vdb.to/cerc-io/plugeth v0.0.0-20230629081247-feb6ccc72b3f/go.mod h1:odpOaIpK01aVThIoAuw9YryLBJeHYOsDn9Mxm4LhB5s= -git.vdb.to/cerc-io/plugeth-utils v0.0.0-20230622072028-1d3da8ce80ee h1:DJ1bR/2k7PopUtchEoTw5QHV1DHb9p0ubcb3yKJc10I= -git.vdb.to/cerc-io/plugeth-utils v0.0.0-20230622072028-1d3da8ce80ee/go.mod h1:p5Jc8deG2yxXI8DzmrH3kHNEwlQqcOQS0pmGulsqg+M= +git.vdb.to/cerc-io/plugeth v0.0.0-20230710223804-34971d65a36a h1:R3DoXSTTXc0xc3M/hOFppVitj1lk1cn2VWTsZloYZ/8= +git.vdb.to/cerc-io/plugeth v0.0.0-20230710223804-34971d65a36a/go.mod h1:odpOaIpK01aVThIoAuw9YryLBJeHYOsDn9Mxm4LhB5s= +git.vdb.to/cerc-io/plugeth-utils v0.0.0-20230706160122-cd41de354c46 h1:KYcbbne/RXd7AuxbUd/3hgk1jPN+33k2CKiNsUsMCC0= +git.vdb.to/cerc-io/plugeth-utils v0.0.0-20230706160122-cd41de354c46/go.mod h1:VpDN61dxy64zGff05F0adujR5enD/JEdXBkTQ+PaIsQ= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= diff --git a/scripts/integration-setup.sh b/scripts/integration-setup.sh new file mode 100755 index 0000000..29c41ab --- /dev/null +++ b/scripts/integration-setup.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +set -eux + +cluster="${1:-test}" +laconic_so="${LACONIC_SO:-laconic-so} --stack fixturenet-plugeth-tx --verbose" + +CONFIG_DIR=$(readlink -f "${CONFIG_DIR:-$(mktemp -d)}") + +# By default assume we are running in the project root +export CERC_REPO_BASE_DIR="${CERC_REPO_BASE_DIR:-$(realpath $(git rev-parse --show-toplevel)/..)}" + +# v5 migrations only go up to version 18 +echo CERC_STATEDIFF_DB_GOOSE_MIN_VER=18 >> $CONFIG_DIR/stack.env + +# Build and deploy a cluster with only what we need from the stack +$laconic_so setup-repositories \ + --exclude github.com/dboreham/foundry,github.com/cerc-io/tx-spammer,github.com/cerc-io/ipld-eth-server,git.vdb.to/cerc-io/plugeth,git.vdb.to/cerc-io/plugeth-statediff \ + --branches-file ./test/stack-refs.txt + +$laconic_so build-containers \ + --exclude cerc/ipld-eth-server,cerc/keycloak,cerc/tx-spammer,cerc/foundry,cerc/plugeth,cerc/plugeth-statediff + +$laconic_so deploy \ + --exclude foundry,keycloak,tx-spammer,ipld-eth-server \ + --env-file $CONFIG_DIR/stack.env \ + --cluster "$cluster" up diff --git a/test/compose.yml b/test/compose.yml index ec4a5dc..a9581fd 100644 --- a/test/compose.yml +++ b/test/compose.yml @@ -1,5 +1,3 @@ -version: "3.2" - services: migrations: restart: on-failure @@ -16,12 +14,11 @@ services: ipld-eth-db: image: timescale/timescaledb:latest-pg14 restart: always - command: ["postgres", "-c", "log_statement=all"] environment: POSTGRES_USER: "vdbm" POSTGRES_DB: "cerc_testing" POSTGRES_PASSWORD: "password" ports: - - "127.0.0.1:8077:5432" + - 127.0.0.1:8077:5432 volumes: - ../indexer/database/file:/file_indexer diff --git a/test/stack-refs.txt b/test/stack-refs.txt new file mode 100644 index 0000000..bb2c2d0 --- /dev/null +++ b/test/stack-refs.txt @@ -0,0 +1 @@ +github.com/cerc-io/ipld-eth-db v5.0.2-alpha