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

Improvement of Docker build process #8

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0978171
Make the spl-token compatible with the multi-chain framework version
nesitor Jan 18, 2023
be06d3b
Fixed exported type.
nesitor Jan 20, 2023
bab3bb6
Fixed last changes of the framework
nesitor Jan 23, 2023
21047a5
Merge branch 'main' into feature/multi_chain
nesitor Jan 30, 2023
911fdaf
Added ts config to allow debug.
nesitor Jan 30, 2023
48e8ca6
Fixed small issues and put .env.defaults beautiful.
nesitor Jan 30, 2023
7881d78
Improve Docker image to be lighter.
nesitor Jan 30, 2023
c218b1f
Removed un-needed dependency.
nesitor Jan 30, 2023
98be601
Improve the docker build to remove useless docker images
nesitor Jan 30, 2023
f25138e
Debug docker image list
nesitor Jan 30, 2023
1699468
Remove un-needed node_modules folder.
nesitor Jan 30, 2023
9d3a04f
Change image names by it's ids.
nesitor Jan 30, 2023
491aada
Show complete list of containers also.
nesitor Jan 30, 2023
ce29552
First stop the container and remove the un-needed image
nesitor Jan 30, 2023
f32866b
Added missing pipe.
nesitor Jan 30, 2023
7299728
Change image names again for it's ids.
nesitor Jan 30, 2023
1ee7c38
Split the job in two parts.
nesitor Jan 30, 2023
5e6a36b
Added needed package.json file.
nesitor Jan 30, 2023
9f24031
Update workflow with last changes and README file.
nesitor Jan 31, 2023
3cbf660
Put a revealed private key to test
nesitor Jan 31, 2023
c486472
Put it in string format.
nesitor Jan 31, 2023
3e455ff
Use the correct secret.
nesitor Jan 31, 2023
a91983a
Leave the workflow for general use.
nesitor Feb 2, 2023
8cfffe3
Merge branch 'main' into feature/multi_chain
nesitor Feb 2, 2023
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
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist
node_modules
.env
data
11 changes: 10 additions & 1 deletion .env.defaults
Original file line number Diff line number Diff line change
@@ -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
Expand Down
29 changes: 15 additions & 14 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules
.env
/.env
device.key
data/
.vscode
Expand All @@ -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
# /packages/**/package-lock.json
19 changes: 16 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
CMD ["./cmd.sh"]
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
```
2 changes: 1 addition & 1 deletion cmd.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

node --max-old-space-size=51200 packages/${INDEXER}/dist/run.js
node --max-old-space-size=16384 packages/${INDEXER}/dist/run.js
5 changes: 5 additions & 0 deletions packages/spl-token/deploy/.env
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions packages/spl-token/deploy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion packages/spl-token/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions packages/spl-token/src/domain/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default class MainDomain

const options = {
account,
blockchainId: Blockchain.Solana,
meta: { type: SPLTokenType.Account, mint: mint },
index: {
transactions: {
Expand All @@ -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: {
Expand Down
7 changes: 4 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "ES2021",
"lib": [
"ESNext",
"ESNext"
],
"module": "esnext",
"esModuleInterop": true,
Expand All @@ -13,8 +13,9 @@
"moduleResolution": "node",
"resolveJsonModule": true,
"outDir": "dist",
"inlineSourceMap": true,
"declarationMap": true,
"allowJs": true,
"allowJs": true
},
"exclude": [
"node_modules",
Expand All @@ -25,4 +26,4 @@
"**/__tests__",
"**/__mocks__"
]
}
}