From fcbe60f2c6248798cd497448a7a1bcc77dc5e916 Mon Sep 17 00:00:00 2001 From: Willem Olding Date: Mon, 15 Apr 2024 12:19:48 +1000 Subject: [PATCH 1/2] add depoloyment actions --- .github/workflows/fly.yml | 28 +++++++++++++++++ fly.fullnode.toml | 23 ++++++++++++++ fly.toml | 35 +++++++++++++++++++++ fullnode.Dockerfile | 66 +++++++++++++++++++++++++++++++++++++++ justfile | 11 +++++-- 5 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/fly.yml create mode 100644 fly.fullnode.toml create mode 100644 fly.toml create mode 100644 fullnode.Dockerfile diff --git a/.github/workflows/fly.yml b/.github/workflows/fly.yml new file mode 100644 index 0000000..5af8976 --- /dev/null +++ b/.github/workflows/fly.yml @@ -0,0 +1,28 @@ +name: Fly Deploy +on: + push: + branches: + - main +jobs: + deploy-node: + name: Deploy Cartesi node + 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 + 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 }} + \ No newline at end of file diff --git a/fly.fullnode.toml b/fly.fullnode.toml new file mode 100644 index 0000000..2505cc9 --- /dev/null +++ b/fly.fullnode.toml @@ -0,0 +1,23 @@ +app = "cartezcash-fullnode" + +[build] +image = "registry.fly.io/cartezcash-fullnode" + +[[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..a648bfd --- /dev/null +++ b/fly.toml @@ -0,0 +1,35 @@ +app = "cartezcash" + +[build] +image = "registry.fly.io/cartezcash" + +[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: From 2a285064d897c73228f3e34616b28684d8c7708a Mon Sep 17 00:00:00 2001 From: Willem Olding Date: Mon, 15 Apr 2024 13:42:49 +1000 Subject: [PATCH 2/2] add example workflow to publish docker images --- .github/workflows/docker.yml | 56 +++++++++++++++++++ .../workflows/{fly.yml => fly.yml.scratch} | 14 +++-- fly.fullnode.toml | 2 +- fly.toml | 2 +- 4 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/docker.yml rename .github/workflows/{fly.yml => fly.yml.scratch} (76%) 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 b/.github/workflows/fly.yml.scratch similarity index 76% rename from .github/workflows/fly.yml rename to .github/workflows/fly.yml.scratch index 5af8976..772617a 100644 --- a/.github/workflows/fly.yml +++ b/.github/workflows/fly.yml.scratch @@ -1,11 +1,15 @@ -name: Fly Deploy +name: Fly.io Deploy + on: - push: - branches: - - main + 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: @@ -17,6 +21,7 @@ jobs: 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: @@ -25,4 +30,3 @@ jobs: - run: fflyctl deploy --config fly.fullnode.toml --remote-only env: FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} - \ No newline at end of file diff --git a/fly.fullnode.toml b/fly.fullnode.toml index 2505cc9..494f3fc 100644 --- a/fly.fullnode.toml +++ b/fly.fullnode.toml @@ -1,7 +1,7 @@ app = "cartezcash-fullnode" [build] -image = "registry.fly.io/cartezcash-fullnode" +image = "registry.fly.io/cartezcash-fullnode:latest" [[services]] internal_port = 50051 diff --git a/fly.toml b/fly.toml index a648bfd..ccf3950 100644 --- a/fly.toml +++ b/fly.toml @@ -1,7 +1,7 @@ app = "cartezcash" [build] -image = "registry.fly.io/cartezcash" +image = "registry.fly.io/cartezcash:latest" [http_service] internal_port = 10000