Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update examples and qa script #1392

Merged
merged 4 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 46 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
resolver = "2"
members = [
"examples/fuel-explorer/fuel-explorer",
"examples/hello-world-native/hello-indexer-native",
"examples/hello-world/hello-indexer",
"examples/hello-world/hello-world-data",
"examples/hello-world/hello-world-node",
"examples/greetings-native/greetings-native-indexer",
"examples/greetings/greetings-data",
"examples/greetings/greetings-fuel-client",
"examples/greetings/greetings-indexer",
"examples/hello-world/hello-world",
"packages/fuel-indexer-api-server",
"packages/fuel-indexer-benchmarks",
"packages/fuel-indexer-database",
Expand Down
2 changes: 1 addition & 1 deletion ci/Dockerfile.fuel-node
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ COPY --from=builder /build/target/release/fuel-node .
COPY --from=builder /build/target/release/fuel-node.d .
COPY --from=builder /build/packages/fuel-indexer-tests/test-chain-config.json .
COPY --from=builder /build/packages/fuel-indexer-tests/contracts/fuel-indexer-test/out/debug/fuel-indexer-test.bin .
COPY --from=builder /build/examples/hello-world/contracts/greeting/out/debug/greeting.bin .
COPY --from=builder /build/examples/greetings/contracts/greeting/out/debug/greeting.bin .
27 changes: 14 additions & 13 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,20 @@ OPTIONS:
-V, --version Print version information

SUBCOMMANDS:
auth Authenticate against an indexer service
build Build an indexer
check Check for Fuel indexer components
deploy Deploy an indexer to an indexer service
help Print this message or the help of the given subcommand(s)
kill Kill the indexer process. Note that this command will kill any process listening
on the default indexer port or the port specified by the `--port` flag
new Create a new indexer project in a new directory
postgres Fuel Postgres Orchestrator
remove Stop and remove a running indexer
start Standalone binary for the Fuel indexer service
status Check the status of a registered indexer

auth Authenticate against an indexer service
build Build an indexer
check Check for Fuel indexer components
deploy Deploy an indexer to an indexer service
help Print this message or the help of the given subcommand(s)
kill Kill the indexer process. Note that this command will kill any process
listening on the default indexer port or the port specified by the `--port`
flag
new Create a new indexer project in a new directory
postgres Fuel Postgres Orchestrator
remove Stop and remove a running indexer
run-native Run a native indexer
start Standalone binary for the Fuel indexer service
status Check the status of a registered indexer
```

#### [➡️ For more details on how to build Fuel indexers, read the docs! ➡️](https://docs.fuel.network/docs/indexer/)
Expand Down
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
- [remove](./forc-index/remove.md)
- [start](./forc-index/start.md)
- [status](./forc-index/status.md)
- [run-native](./forc-index/run-native.md)
- [forc postgres](./forc-postgres/index.md)
- [create](./forc-postgres/create.md)
- [drop](./forc-postgres/drop.md)
Expand Down
27 changes: 2 additions & 25 deletions docs/src/forc-index/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,6 @@

`forc index` is the recommended method for end users to interact with the Fuel indexer. After you have installed `fuelup`, you can run the `forc index help` command in your terminal to view the available commands.

```text
forc index help
```

```text
USAGE:
forc-index <SUBCOMMAND>

OPTIONS:
-h, --help Print help information
-V, --version Print version information

SUBCOMMANDS:
auth Authenticate against an indexer service
build Build an indexer
check Check for Fuel indexer components
deploy Deploy an indexer to an indexer service
help Print this message or the help of the given subcommand(s)
kill Kill the indexer process. Note that this command will kill any process listening
on the default indexer port or the port specified by the `--port` flag
new Create a new indexer project in a new directory
postgres Fuel Postgres Orchestrator
remove Stop and remove a running indexer
start Standalone binary for the Fuel indexer service
status Check the status of a registered indexer
```text,ignore
{{#include ./../../README.md 59:84}}
```
45 changes: 45 additions & 0 deletions docs/src/forc-index/run-native.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# `forc index run-native`

Run a native indexer.

```bash
forc index run-native --path . -- --run-migrations --postgres-host localhost
```

```text
Run a native indexer

USAGE:
forc-index run-native [OPTIONS] [-- <ARGS>...]

ARGS:
<ARGS>...
Extra passed to `fuel-indexer run`

Example usage: `forc-index run-native --path . -- --run-migrations --stop-idle-indexers`

OPTIONS:
--bin <BIN>
Path to native indexer binary (if not using default location).

-d, --debug
Build artifacts with the debug profile.

-h, --help
Print help information

--locked
Ensure that the Cargo.lock file is up-to-date.

-m, --manifest <MANIFEST>
Manifest file name of indexer being built.

-p, --path <PATH>
Path to the indexer project.

--skip-build
Do not build before deploying.

-v, --verbose
Enable verbose output.
```
2 changes: 1 addition & 1 deletion examples/fuel-explorer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ docker compose up --build
### Deploy the indexer

```bash
forc index deploy --path hello-indexer --url http://0.0.0.0:29987
forc index deploy --path greetings --url http://0.0.0.0:29987
```

### Interact
Expand Down
81 changes: 81 additions & 0 deletions examples/greetings-native/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Stage 1: Build
FROM --platform=$BUILDPLATFORM tonistiigi/xx AS xx
FROM --platform=$BUILDPLATFORM rust:1.72.1 AS chef

ARG TARGETPLATFORM
RUN cargo install cargo-chef
WORKDIR /build/

COPY --from=xx / /

# hadolint ignore=DL3008
RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
build-essential \
clang \
cmake \
gcc \
git \
libclang-dev \
lld \
llvm \
pkg-config

RUN xx-apt-get update && \
xx-apt-get install -y binutils g++ libc6-dev && \
apt-get clean

FROM chef AS planner
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

# Stage 2: build binaries
FROM chef AS builder
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
COPY --from=planner /build/recipe.json recipe.json

ENV SQLX_OFFLINE=true

RUN xx-cargo chef cook --release -p greetings_native_indexer --recipe-path recipe.json
COPY . .
RUN xx-cargo build --release -p greetings_native_indexer \
&& xx-verify ./target/$(xx-cargo --print-target-triple)/release/greetings_native_indexer \
&& mv ./target/$(xx-cargo --print-target-triple)/release/greetings_native_indexer ./target/release/greetings_native_indexer \
&& mv ./target/$(xx-cargo --print-target-triple)/release/greetings_native_indexer.d ./target/release/greetings_native_indexer.d

# Stage 3: Run
FROM ubuntu:22.04 AS run

WORKDIR /root/

RUN DEBIAN_FRONTEND=noninteractive apt-get update -y \
&& apt-get install -y --no-install-recommends \
tzdata \
ca-certificates \
libpq-dev \
wget \
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y

COPY --from=builder /build/target/release/greetings_native_indexer .
COPY --from=builder /build/target/release/greetings_native_indexer.d .
COPY --from=builder /build/examples/greetings-native/greetings-native-indexer .
COPY --from=builder /build/examples/greetings/contracts/greeting/out/debug/greeting-abi.json .

# Since unlike WASM indexers, native indexers can't be deployed, we need to
# write the specific asset paths to the manifest, as well as the manifest itself.
#
# We only have to do this because the example is contained within the project worksapce (and it's
# manifest asset paths are relative to that workspace root). You wouldn't need to do this otherwise.
RUN echo "namespace: fuellabs\n\
fuel_client: ~\n\
graphql_schema: schema/greetings_native_indexer.schema.graphql\n\
abi: greetings-abi.son\n\
start_block: ~\n\
end_block: ~\n\
contract_id: fuel1q6sj2srt0u40jdqg2lvvnspyuhse9rs2s2fv9nmv0hqjcrdc7sqsfpwv9x\n\
identifier: greetings_native\n\
module: native\n\
resumable: true" > greetings_native_indexer.manifest.yaml
60 changes: 60 additions & 0 deletions examples/greetings-native/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# greetings-native

A simple program that demonstrates the full Fuel indexer experience.

## Usage

> NOTE: Commands are run from `fuel-indexer/examples/greetings-native`

### Spin up containers

Build image locally

```bash
docker compose up
```

Spin up containers for the Postgres database server and the indexer service.

> IMPORTANT: Ensure that any local Postgres instance on port 5432 is stopped.

```bash
docker compose up
```

### Deploy the indexer

> Note that since this example uses native execution (as opposed to WASM execution), there is no need to
> "deploy" the indexer. You'll notice that your indexer is already running inside your Docker container.

### Interact

Trigger some test data by simulating a contract call.

```bash
cargo run -p greetings-data --bin greetings-data -- --host 0.0.0.0:4000
```

### Validate

Ensure that test data was indexed via a GraphQL query:
1. Open this GraphQL playground link http://192.168.1.34:29987/api/playground/fuellabs/greetings-native_indexer
2. Submit the following query

```graphql
query {
transaction {
hash
block {
hash
height
}
}
}
```

> IMPORTANT: Since this example uses a dockerized indexer service, with the GraphQL
> web server being bound at interface `0.0.0.0` your LAN IP might differ from the
> `192.168.1.34` mentioned above.
>
> On *nix platforms you can typically find your LAN IP via `ifconfig | grep inet`
Loading
Loading