diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b05406d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +dist +node_modules +.env +data diff --git a/.env.defaults b/.env.defaults index 350ac67..6eae2cf 100644 --- a/.env.defaults +++ b/.env.defaults @@ -1,5 +1,14 @@ +# Select the indexer that you want to execute +#INDEXER=spl-token + +# Only for SPL-Lending indexer +#LENDING_ID=port + +# Only for SPL-Token indexer +#SPL_TOKEN_MINTS=kinXdEcpDQeHPEuQnqmUgtYykqKGVFq6CeVX5iAHJq6 +#SPL_TOKEN_ACCOUNTS= + SOLANA_RPC=http://solrpc1.aleph.cloud:7725/ -SPL_TOKEN_MINTS=kinXdEcpDQeHPEuQnqmUgtYykqKGVFq6CeVX5iAHJq6 SOLANA_MAIN_PUBLIC_RPC=https://api.mainnet-beta.solana.com # 16 GB RAM for node.js diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 62aa221..e1b96d5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,18 +3,10 @@ on: types: [ labeled ] jobs: - clean: - if: ${{ github.event.label.name == 'deploy' }} - runs-on: ubuntu-latest - steps: - - name: Cleanup Artifacts - uses: glassechidna/artifact-cleaner@master - build: if: ${{ github.event.label.name == 'deploy' }} runs-on: ubuntu-latest name: Build the indexer image - needs: clean steps: - name: Checkout uses: actions/checkout@v3 @@ -32,11 +24,20 @@ jobs: tags: indexer-framework:latest outputs: type=docker,dest=/tmp/indexer-framework.tar build-args: | - INDEXER=spl-lending + INDEXER=XXXXXX - name: Load image run: | docker load --input /tmp/indexer-framework.tar - - name: Show Docker images list + - name: Show Docker running containers + run: | + docker ps + - name: Remove Docker running container + run: | + docker container rm -f buildx_buildkit_mybuilder0 + - name: Remove Docker useless images + run: | + docker image rm c0851e6e0d6c 354472a37893 + - name: Show Docker images list after removing run: | docker image list - name: Tar Docker image contents @@ -76,7 +77,7 @@ jobs: # - uses: aleph-im/aleph-github-actions/publish-runtime@main # id: publish-runtime # with: -# fs_path: ./rootfs.squashfs -# private-key: ${{ secrets.WALLET_PRIVATE_KEY }} -# runtime_hash: XXXXXX -# indexer: spl-lending +# private_key: ${{ secrets.WALLET_PRIVATE_KEY }} +# runtime_filename: rootfs.squashfs +# docker_compose_url: https://raw.githubusercontent.com/aleph-im/solana-indexer-library/main/packages/spl-token/deploy/docker-compose.yml +# env_url: https://raw.githubusercontent.com/aleph-im/solana-indexer-library/main/packages/spl-token/deploy/.env diff --git a/.gitignore b/.gitignore index a1b3dee..0d54230 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ node_modules -.env +/.env device.key data/ .vscode @@ -12,4 +12,4 @@ logs.log # "Lockfiles for apps, but not for packages." https://twitter.com/sindresorhus/status/878240818363981827 # Doesn't work with "lerna version" -# /packages/**/package-lock.json \ No newline at end of file +# /packages/**/package-lock.json diff --git a/Dockerfile b/Dockerfile index c12c367..4e4f773 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,23 @@ -FROM node:16-alpine +FROM node:16-alpine AS appbuild +ARG INDEXER +ENV INDEXER=$INDEXER WORKDIR /app - COPY . . + RUN npm ci +FROM node:16-alpine +ARG INDEXER +ENV INDEXER=$INDEXER +WORKDIR /app + +COPY package*.json ./ + +COPY --from=appbuild /app/packages/${INDEXER}/dist ./packages/${INDEXER}/dist +COPY --from=appbuild /app/packages/${INDEXER}/node_modules ./packages/${INDEXER}/node_modules +COPY --from=appbuild /app/cmd.sh ./cmd.sh + EXPOSE 8080 ENV NODE_ENV=production -CMD ["./cmd.sh"] \ No newline at end of file +CMD ["./cmd.sh"] diff --git a/README.md b/README.md index 041c17f..4d7e125 100644 --- a/README.md +++ b/README.md @@ -30,22 +30,23 @@ There are three way's to create your indexer after you create a new project: - Label your PR with the `deploy` tag. - The GitHub action will be triggered, and you will be able to download the final root filesystem of your indexer, ready to be pushed to Aleph network. - You will find this rootfs file inside `Actions` -> `"Name of your last commit"` -> `Artifacts` -> `rootfs.squashfs`. -- Download it, **upload this `rootfs.squashfs` runtime file to IPFS, pin it,** and you will be ready to proceed with the deployment. +- This `rootfs.squashfs` runtime file will be used for the deployment. ### Deploying with GitHub Actions **_Using this method you will need to store you wallet private key's inside GitHub Secrets._** - Go to repository `Secrets` tab and add a new one like `WALLET_PRIVATE_KEY`. -- Inside `.github/workflows/main.yml` file, uncomment the last action that is commented and ensure to replace `XXXXXX` with the IPFS hash of your `rootfs.squashfs` file uploaded: +- Inside `.github/workflows/main.yml` file, uncomment the last action that is commented and ensure to replace `https://XXXXXXXXX/docker-compose.yml` with the URL of your `docker-compose.yml` +file that you will use and also replace `https://XXXXXXXXX/.env` with the URL of your `.env` file to use : ```yml - uses: aleph-im/aleph-github-actions/publish-runtime@main id: publish-runtime with: - fs_path: ./rootfs.squashfs + runtime_filename: rootfs.squashfs private-key: ${{ secrets.WALLET_PRIVATE_KEY }} - runtime_hash: XXXXXX - indexer: spl-lending + docker_compose_url: https://XXXXXXXXX/docker-compose.yml + env_url: https://XXXXXXXXX/.env ``` - Pushing this new changes with a PR or a simple commit to the repository, the GitHub action will be triggered. - Once the action finishes successfully, inside `Actions` -> `"Name of your last commit"` -> `Generate runtime` job -> `Publish runtime` step, you will be able to see the VM address: @@ -65,12 +66,20 @@ https://aleph.sh/vm/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ```shell aleph pin RUNTIME_HASH --private-key WALLET_PRIVATE_KEY ``` +- Get the `item_hash` field of the resulting message. We will use it in the next steps as `RUNTIME_ITEM_HASH` - Download the program files in the current directory through [here](https://github.com/aleph-im/aleph-github-actions/tree/main/publish-runtime). -- Deploy the program inside a persistent VM at Aleph network (changing INDEXER by your indexer name): +- Enter the folder just downloaded: ```shell -aleph program ./program "run.sh INDEXER" --persistent --private-key WALLET_PRIVATE_KEY --runtime RUNTIME_HASH +cd publish-runtime ``` +- Replace inside `program` folder the `.env` and `docker_compose.yml` files with the needed for your indexer. You can +find some example here [here](https://github.com/aleph-im/aleph-github-actions/tree/main/publish-runtime/examples) +- Deploy the program inside a persistent VM at Aleph network passing the needed parameters: +```shell +aleph program ./program "run.sh" --persistent --private-key WALLET_PRIVATE_KEY --runtime RUNTIME_ITEM_HASH +``` +- When the console prompt to add a persistent volume, press `y` and specify the volume parameters. - Once command finishes, you will be able to see the VM address: ``` -https://aleph-vm-lab.aleph.cloud/vm/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +https://aleph.sh/vm/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ``` diff --git a/cmd.sh b/cmd.sh index d58b57c..6821152 100755 --- a/cmd.sh +++ b/cmd.sh @@ -1,3 +1,3 @@ #!/bin/sh -node --max-old-space-size=51200 packages/${INDEXER}/dist/run.js \ No newline at end of file +node --max-old-space-size=16384 packages/${INDEXER}/dist/run.js diff --git a/packages/spl-token/deploy/.env b/packages/spl-token/deploy/.env new file mode 100644 index 0000000..72f744c --- /dev/null +++ b/packages/spl-token/deploy/.env @@ -0,0 +1,5 @@ +INDEXER=spl-token +SPL_TOKEN_MINTS=3UCMiSnkcnkPE1pgQ5ggPCBv6dXgVUy16TmMUe1WpG9x +SOLANA_RPC=http://solrpc1.aleph.cloud:7725/ +INDEXER_DATA_PATH=/app/data +INDEXER_INSTANCES=1 diff --git a/packages/spl-token/deploy/docker-compose.yml b/packages/spl-token/deploy/docker-compose.yml new file mode 100644 index 0000000..d09601d --- /dev/null +++ b/packages/spl-token/deploy/docker-compose.yml @@ -0,0 +1,24 @@ +version: '2' + +services: + indexer: + image: indexer-framework:latest + volumes: + - /opt/indexer.data:/app/data:rw + extra_hosts: + - host.docker.internal:host-gateway + ports: + - "8080:8080" + environment: + - INDEXER=${INDEXER} + - LENDING_ID=${LENDING_ID} + - SPL_TOKEN_MINTS=${SPL_TOKEN_MINTS} + - SPL_TOKEN_ACCOUNTS=${SPL_TOKEN_ACCOUNTS} + - SOLANA_RPC=${SOLANA_RPC} + - INDEXER_DATA_PATH=${INDEXER_DATA_PATH} + - INDEXER_INSTANCES=${INDEXER_INSTANCES} + # - INDEXER_TCP_PORT=7900 + # ports: + # - 7900:7900 + # - 7901:7901 + network_mode: bridge diff --git a/packages/spl-token/run.ts b/packages/spl-token/run.ts index bee3f72..e85df21 100644 --- a/packages/spl-token/run.ts +++ b/packages/spl-token/run.ts @@ -11,7 +11,7 @@ async function main() { const mainDomainPath = path.join(__dirname, './src/domain/main.js') const apiSchemaPath = path.join(__dirname, './src/api/index.js') - const instances = Number(config.INDEXER_INSTANCES || 2) + const instances = Number(config.INDEXER_INSTANCES || 1) const apiPort = Number(config.INDEXER_API_PORT || 8080) const tcpUrls = config.INDEXER_TCP_URLS || undefined const natsUrl = config.INDEXER_NATS_URL || undefined diff --git a/packages/spl-token/src/domain/main.ts b/packages/spl-token/src/domain/main.ts index 5412d2f..cdba0e3 100644 --- a/packages/spl-token/src/domain/main.ts +++ b/packages/spl-token/src/domain/main.ts @@ -68,6 +68,7 @@ export default class MainDomain const options = { account, + blockchainId: Blockchain.Solana, meta: { type: SPLTokenType.Account, mint: mint }, index: { transactions: { @@ -88,6 +89,7 @@ export default class MainDomain await this.addToken(mint) const options = { account: mint, + blockchainId: Blockchain.Solana, meta: { type: SPLTokenType.Mint, mint }, index: { transactions: { diff --git a/tsconfig.json b/tsconfig.json index d38b747..bf67903 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "target": "ES2021", "lib": [ - "ESNext", + "ESNext" ], "module": "esnext", "esModuleInterop": true, @@ -13,8 +13,9 @@ "moduleResolution": "node", "resolveJsonModule": true, "outDir": "dist", + "inlineSourceMap": true, "declarationMap": true, - "allowJs": true, + "allowJs": true }, "exclude": [ "node_modules", @@ -25,4 +26,4 @@ "**/__tests__", "**/__mocks__" ] -} \ No newline at end of file +}