diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..6baf9a5 --- /dev/null +++ b/.github/workflows/docker.yml @@ -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 diff --git a/.github/workflows/fly.yml.scratch b/.github/workflows/fly.yml.scratch new file mode 100644 index 0000000..772617a --- /dev/null +++ b/.github/workflows/fly.yml.scratch @@ -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 }} diff --git a/fly.fullnode.toml b/fly.fullnode.toml new file mode 100644 index 0000000..494f3fc --- /dev/null +++ b/fly.fullnode.toml @@ -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" diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..ccf3950 --- /dev/null +++ b/fly.toml @@ -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" diff --git a/fullnode.Dockerfile b/fullnode.Dockerfile new file mode 100644 index 0000000..f08c164 --- /dev/null +++ b/fullnode.Dockerfile @@ -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 <&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"] diff --git a/justfile b/justfile index 5a9fa16..2591466 100644 --- a/justfile +++ b/justfile @@ -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: