From b35016dac106fc7e6f3ac2fadefa51cf0877f7ef Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Date: Mon, 27 May 2024 17:41:55 +0800 Subject: [PATCH] ci: add docker images, update docs --- .dockerignore | 6 ++++ .env.example | 6 ++++ .github/dependabot.yaml | 6 ++++ .github/workflows/docker.yaml | 56 +++++++++++++++++++++++++++++++++++ Dockerfile | 27 +++++++++++++++++ README.md | 47 +++++++++++++++++++++++++++++ config.toml | 12 ++++++++ 7 files changed, 160 insertions(+) create mode 100644 .dockerignore create mode 100644 .env.example create mode 100644 .github/dependabot.yaml create mode 100644 .github/workflows/docker.yaml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fe128d5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +/** +!/cmd +!/internal +!/LICENSE +!/config.toml +!/go.* \ No newline at end of file diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..e77be79 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +TRACKER_CORE__POOL_SIZE= +TRACKER_CHAIN__ARCHIVE_NODE= +TRACKER_CHAIN__WS_ENDPOINT= +TRACKER_CHAIN__RPC_ENDPOINT= +TRACKER_CHAIN__CHAINID= +TRACKER_CHAIN__START_BLOCK= \ No newline at end of file diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml new file mode 100644 index 0000000..f1b219b --- /dev/null +++ b/.github/dependabot.yaml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 0000000..fc0d076 --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,56 @@ +name: release + +on: + push: + tags: + - "v*" + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Check out repo + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Login to GHCR Docker registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set outputs + run: | + echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV \ + && echo "RELEASE_SHORT_COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + + - name: Build and push image + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./Dockerfile + platforms: linux/amd64 + push: true + build-args: | + BUILD=${{ env.RELEASE_SHORT_COMMIT }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + tags: | + ghcr.io/grassrootseconomics/celo-tracker:latest + ghcr.io/grassrootseconomics/celo-tracker:${{ env.RELEASE_TAG }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..59cd6f3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM golang:1.22.3-bookworm as build + +ENV CGO_ENABLED=1 + +ARG BUILDPLATFORM +ARG TARGETPLATFORM +ARG BUILD=dev + +RUN echo "Building on $BUILDPLATFORM, building for $TARGETPLATFORM" +WORKDIR /build + +COPY . . +RUN go mod download +RUN go build -o celo-tracker -ldflags="-X main.build=${BUILD} -s -w" cmd/* + +FROM debian:bookworm-slim + +ENV DEBIAN_FRONTEND=noninteractive + +WORKDIR /service + +COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=build /build/* . + +EXPOSE 5001 + +CMD ["./celo-tracker"] diff --git a/README.md b/README.md index 2c3d783..3c5c406 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,53 @@ It applies deduplication at the NATS level, making it safe to run in a distribut ## Getting Started +### Prerequisites + +* Git +* Docker +* NATS server +* Access to a Celo RPC node + +### 1. Build the Docker image + +We provide pre-built images for `linux/amd64`. See the packages tab on Github. + +If you are on any other platform: + +```bash +git clone https://github.com/grassrootseconomics/celo-tracker.git +cd celo-tracker +docker buildx build --build-arg BUILD=$(git rev-parse --short HEAD) --tag celo-tracker:$(git rev-parse --short HEAD) --tag celo-tracker:latest . +docker images +``` + +### 2. Run NATS + +```bash +cd dev +docker compose up -d +docker ps +``` + +### 3. Update config values + +See `.env.example` on how to override default values defined in `config.toml` using env varaibles. Alternatively, mount your own config.toml either during build time or Docker runtime. + +```bash +# Override only specific config values +nano .env.example +mv .env.example .env +``` + +Refer to [`config.toml`](config.toml) to understand different config value settings. + + +### 4. Run the tracker + +```bash +docker run --env-file .env -p 127.0.0.1:5001:5001 celo-tracker:latest +``` + ## Caveats * Reverted transactions older than 10 minutes will be skipped due to the trie potentially missing. To override this behavior, use an archive node and set `chain.archive_node` to `true`. diff --git a/config.toml b/config.toml index 816c998..ff490a5 100644 --- a/config.toml +++ b/config.toml @@ -1,19 +1,31 @@ [api] +# Exposes /debug and /stats address = ":5001" [core] +# Use a specific cache implementation cache_type = "map" +# Use a specific db implementation db_type = "bolt" +# Tune max go routines that can process blocks +# Defaults to (nproc * 3) pool_size = 0 +# If you are using an archive node, set this to true archive_node = false [chain] ws_endpoint = "wss://forno.celo.org/ws" rpc_endpoint = "https://forno.celo.org" +# Defaults to Celo mainnet +# At the moment only support Celo based blockchains chainid = 42220 +# This will start a backfill if set to any other value +# Ideally this should remain 0 start_block = 0 [bootstrap] +# This will bootstrap the cache on which addresses to track +# Grassroots Economics specific registries that autoload all other smart contracts ge_registries = [ "0xd1FB944748aca327a1ba036B082993D9dd9Bfa0C", "0x0cc9f4fff962def35bb34a53691180b13e653030",