Skip to content

Commit

Permalink
Merge pull request #24 from willemolding/willem/indexer-docker
Browse files Browse the repository at this point in the history
Add a dockerfile for the indexer and github actions to push to container registry
  • Loading branch information
willemolding authored Apr 15, 2024
2 parents 02cc369 + 2a28506 commit 2ead7fd
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 2 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Publish Docker images

on:
release:
types: [published]

jobs:
push_fullnode_to_registry:
name: Push fullnode Docker image to fly.io
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: 🔑 Fly Registry Auth
uses: docker/login-action@v1
with:
registry: registry.fly.io
username: x
password: ${{ secrets.FLY_API_TOKEN }}

- name: 🐳 Docker build (fullnode)
uses: docker/build-push-action@v2
with:
context: .
file: ./fullnode.Dockerfile
push: true
tags: registry.fly.io/cartezcash-fullnode:latest
build-args: |
COMMIT_SHA=${{ github.sha }}
push_cartesi_node_to_registry:
name: Push cartesi node Docker image to fly.io
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: 🔑 Fly Registry Auth
uses: docker/login-action@v1
with:
registry: registry.fly.io
username: x
password: ${{ secrets.FLY_API_TOKEN }}

- name: Setup Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: "https://registry.npmjs.org"

- name: Install Sunodo and build
run: |
npm install -g @sunodo/cli
IMAGE_TAG=$(sunodo deploy build --platform linux/amd64 | grep "Application node Docker image" | awk '{print $NF}')
docker push $IMAGE_TAG:registry.fly.io/cartezcash:latest
32 changes: 32 additions & 0 deletions .github/workflows/fly.yml.scratch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Fly.io Deploy

on:
workflow_run:
workflows: ["Publish Docker images"]
types:
- completed

jobs:
deploy-node:
name: Deploy Cartesi node
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
concurrency: deploy-group # optional: ensure only one action runs at a time
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --config fly.toml --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

deploy-fullnode:
name: Deploy fullnode
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
concurrency: deploy-group # optional: ensure only one action runs at a time
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: fflyctl deploy --config fly.fullnode.toml --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
23 changes: 23 additions & 0 deletions fly.fullnode.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
app = "cartezcash-fullnode"

[build]
image = "registry.fly.io/cartezcash-fullnode:latest"

[[services]]
internal_port = 50051
protocol = "tcp"

[[services.ports]]
handlers = ["tls"]
port = "443"

[services.ports.tls_options]
alpn = ["h2"]

[[vm]]
size = "shared-cpu-1x"
memory = "2gb"

[env]
GRPC_SERVER_URL="[::1]:50051"
ROLLUP_HTTP_SERVER_URL="http://cartezcash.internal:8080/graphql"
35 changes: 35 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
app = "cartezcash"

[build]
image = "registry.fly.io/cartezcash:latest"

[http_service]
internal_port = 10000
force_https = true

[http_service.concurrency]
type = "requests"
soft_limit = 200
hard_limit = 250

[[http_service.checks]]
grace_period = "10s"
interval = "30s"
method = "GET"
timeout = "5s"
path = "/healthz"

[[vm]]
size = "shared-cpu-1x"
memory = "2gb"

[env]
CARTESI_BLOCKCHAIN_FINALITY_OFFSET = "1"
CARTESI_BLOCKCHAIN_ID = "11155111"
CARTESI_CONTRACTS_APPLICATION_ADDRESS = "0xb8017DF47f872946A01D3ad392e4c45AB7B67262"
CARTESI_CONTRACTS_APPLICATION_DEPLOYMENT_BLOCK_NUMBER = "5700129"
CARTESI_CONTRACTS_AUTHORITY_ADDRESS = "0x7858f8b09FFC111e9dfb4465ddCEe323654C25c3"
CARTESI_CONTRACTS_HISTORY_ADDRESS = "0xD0ab8247fFc3d161dCCe7ca50B3B5aa78dE52412"
CARTESI_CONTRACTS_INPUT_BOX_ADDRESS = "0x59b22D57D4f067708AB0c00552767405926dc768"
CARTESI_CONTRACTS_INPUT_BOX_DEPLOYMENT_BLOCK_NUMBER = "3963384"
CARTESI_EPOCH_DURATION = "86400"
66 changes: 66 additions & 0 deletions fullnode.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# syntax=docker.io/docker/dockerfile:1
FROM ubuntu:22.04 as base

ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=1.76.0

ARG DEBIAN_FRONTEND=noninteractive
RUN <<EOF
set -e
apt update
apt install -y --no-install-recommends \
build-essential=12.9ubuntu3 \
ca-certificates=20230311ubuntu0.22.04.1 \
wget=1.21.2-2ubuntu1 \
libclang-dev
EOF

RUN set -eux; \
dpkgArch="$(dpkg --print-architecture)"; \
case "${dpkgArch##*-}" in \
amd64) rustArch='x86_64-unknown-linux-gnu'; rustupSha256='0b2f6c8f85a3d02fde2efc0ced4657869d73fccfce59defb4e8d29233116e6db' ;; \
armhf) rustArch='armv7-unknown-linux-gnueabihf'; rustupSha256='f21c44b01678c645d8fbba1e55e4180a01ac5af2d38bcbd14aa665e0d96ed69a' ;; \
arm64) rustArch='aarch64-unknown-linux-gnu'; rustupSha256='673e336c81c65e6b16dcdede33f4cc9ed0f08bde1dbe7a935f113605292dc800' ;; \
i386) rustArch='i686-unknown-linux-gnu'; rustupSha256='e7b0f47557c1afcd86939b118cbcf7fb95a5d1d917bdd355157b63ca00fc4333' ;; \
*) echo >&2 "unsupported architecture: ${dpkgArch}"; exit 1 ;; \
esac; \
url="https://static.rust-lang.org/rustup/archive/1.26.0/${rustArch}/rustup-init"; \
wget "$url"; \
echo "${rustupSha256} *rustup-init" | sha256sum -c -; \
chmod +x rustup-init; \
./rustup-init -y --no-modify-path --profile minimal --default-toolchain $RUST_VERSION --default-host ${rustArch}; \
rm rustup-init; \
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
rustup --version; \
cargo --version; \
rustc --version;

RUN cargo install cargo-chef
WORKDIR /opt/cartesi/cartezcash

### the planner helps cache depdenency builds

FROM base AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

### Builder compiles the service

FROM base as builder
COPY --from=planner /opt/cartesi/cartezcash/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json --no-default-features --features listen-graphql,lightwalletd
COPY . .
RUN cargo build --release --no-default-features --features listen-graphql,lightwalletd

### final image is the dapp itself

FROM ubuntu:22.04

ENV PATH="/opt/cartesi/bin:/opt/cartesi/cartezcash:${PATH}"

WORKDIR /opt/cartesi/cartezcash
COPY --from=builder /opt/cartesi/cartezcash/target/release/cartezcash .

CMD ["cartezcash"]
11 changes: 9 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ run:
run-local:
ROLLUP_HTTP_SERVER_URL=http://127.0.0.1:8080/host-runner GRPC_SERVER_URL="[::1]:50051" cargo run --features lightwalletd

run-local-graphql:
run-fullnode:
ROLLUP_HTTP_SERVER_URL=http://127.0.0.1:8080/graphql GRPC_SERVER_URL="[::1]:50051" cargo run --no-default-features --features listen-graphql,lightwalletd


sunodo-nobackend:
sunodo run --no-backend

##### Docker

build-fullnode-docker:
docker build -f fullnode.Dockerfile -t cartezcash/fullnode:latest .

run-fullnode-docker:
docker run -it --rm -p 50051:50051 -e ROLLUP_HTTP_SERVER_URL=http://host.docker.internal:8080/graphql -e GRPC_SERVER_URL="[::1]:50051" cartezcash/fullnode:latest

##### Interact with dApp via sunodo

@deposit address amount:
Expand Down

0 comments on commit 2ead7fd

Please sign in to comment.