diff --git a/.env.example b/.env.example index 7e38aab1ee86d11d2d4eafb02b3d2f71b6ee2e86..9b74d2c14f9fb8a892c0c56d73ffe34d95c133b1 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,12 @@ -# === POSTGRES / HASURA === +# === IPFS === +KUBO_RPC="http://127.0.0.1:5001" + +# === POSTGRES === +DB_HOST=localhost +DB_PORT=5432 +DB_USER=postgres DB_PASSWORD=my_db_password + +# === HASURA === HASURA_GRAPHQL_ADMIN_SECRET=my_hasura_password HASURA_LISTEN_PORT=8765 diff --git a/.env.sh b/.env.sh new file mode 100755 index 0000000000000000000000000000000000000000..ed16168d37b723fe5c04e09de585b0c54ce4296c --- /dev/null +++ b/.env.sh @@ -0,0 +1,5 @@ +#!/bin/sh +# exports .env variables to be used by an other process +set -a +source ./.env +set +a \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4425beafb64442a67d3e78aedc09f2f3ffcb8072..aecb3ace57906e432f5326289525db50a63d2c25 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile # datapod image FROM base COPY --from=deps /app/node_modules /app/node_modules -CMD ["npx", "tsx", "src/scripts/hello.ts"] +CMD ["pnpm", "exec", "tsx", "src/indexer/start.ts"] # TODO build image only for indexer without app @@ -22,3 +22,4 @@ CMD ["npx", "tsx", "src/scripts/hello.ts"] # build and run for test # docker buildx build . -t test-datapod # docker run --rm -it test-datapod +# CMD ["pnpm", "exec", "tsx", "src/scripts/hello.ts"] diff --git a/README.md b/README.md index 08d69369f92d56d4276117d5a5a8508c0f5be0e8..162bf3c4550c093c9b07d9b40377a2ea974fcf6f 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ TODO use in prod with docker ## Dev -To install dev dependencies +Install dev dependencies ```sh # use node version 20 @@ -24,7 +24,7 @@ nvm use 20 pnpm install ``` -Then start a kubo node with pubsub +Start a kubo node with pubsub and postgres/hasura ```sh # start kubo node TODO put this in the docker @@ -33,7 +33,25 @@ ipfs daemon --enable-pubsub-experiment docker compose up -d ``` -Then start what you want (indexer, dev tool, c+ import) according to the following doc. +Copy edit and load your `.env` file + +```sh +# copy from template +cp .env.example .env +# adapt .env file then export variables +source .env.sh +``` + +And start what you want (indexer, dev tool, c+ import...) + +```sh +# run dev tool app +pnpm dev +# run given script +pnpm exec tsx ./src/script/hello.ts +``` + +More detail in the doc below. ## Doc diff --git a/doc/cesium-plus-import.md b/doc/cesium-plus-import.md index 65df4e3bed28039e7eed855e68ee1d4e868f0348..cdc64e68e33093dc28f2f653ae67500394922997 100644 --- a/doc/cesium-plus-import.md +++ b/doc/cesium-plus-import.md @@ -6,7 +6,7 @@ After exporting the data to json files with the Rust script from `v2s-datapod`. ```sh # doImport() # takes about 200 seconds (4 minutes) -time npx tsx src/scripts/cesium-plus-import.ts +time pnpm exec tsx src/scripts/cesium-plus-import.ts ``` You can then manually pin the cid according to the command output. @@ -20,6 +20,6 @@ This will make easier to insert this data in any AMT or other data structure. ```sh # doAllCplusCidsToAMT() # takes about 180 seconds -time npx tsx src/scripts/cesium-plus-import.ts +time pnpm exec tsx src/scripts/cesium-plus-import.ts # bafyreiffn3kkrakf7qj5m3wepsoxjwcojmesfyoexsvsovx23nhbfqu6bq ``` \ No newline at end of file diff --git a/doc/start-indexer.md b/doc/start-indexer.md index 56df5939a94e5ea25779eae22d2b5c0654188303..274e517b8194f51f3420b5dcb3dfd212817eeaa7 100644 --- a/doc/start-indexer.md +++ b/doc/start-indexer.md @@ -5,5 +5,5 @@ Then start pubsub collector and database indexer with: ```sh # start the collector and indexer -npx tsx src/indexer/start.ts +pnpm exec tsx src/indexer/start.ts ``` diff --git a/src/indexer/database.ts b/src/indexer/database.ts index b796caf2c1e421731b318882054da66cdf515572..e82ecaf3b6e1dcbba14af55254b89c314abaa691 100644 --- a/src/indexer/database.ts +++ b/src/indexer/database.ts @@ -5,9 +5,12 @@ import pg from 'pg' import { kubo } from '../kubo' import type { CplusProfile } from '../cesium-plus' -// TODO proper env +// define form env const env = { - DB_PASSWORD: 'my_db_password' + DB_HOST: process.env.DB_HOST || 'localhost', + DB_PORT: parseInt(process.env.DB_PORT || '0') || 5432, + DB_USER: process.env.DB_USER || 'postgres', + DB_PASSWORD: process.env.DB_PASSWORD || 'my_db_password' } // group query and param builder to limit error @@ -19,8 +22,10 @@ interface QueryBuilder { // initialize client const { Client } = pg export const client = new Client({ - user: 'postgres', - password: env['DB_PASSWORD'] + host: env.DB_HOST, + port: env.DB_PORT, + user: env.DB_USER, + password: env.DB_PASSWORD }) await client.connect() diff --git a/src/kubo.ts b/src/kubo.ts index f991071f964c1a42bd81165abb590846a0a4d932..507985bbdef2d97e9574353d7a0104868e27c82f 100644 --- a/src/kubo.ts +++ b/src/kubo.ts @@ -2,13 +2,20 @@ import { create } from 'kubo-rpc-client' import type { IPFSHTTPClient } from 'kubo-rpc-client' import { CID } from 'multiformats' -// connect to the default API address http://localhost:5001 -export const kubo: IPFSHTTPClient = create({ url: new URL('http://127.0.0.1:5001') }) +// env +var process : NodeJS.Process | undefined = typeof(process) == "undefined" ? undefined : process +const KUBO_RPC = process?.env.KUBO_RPC || 'http://127.0.0.1:5001' +const KUBO_GATEWAY = process?.env.KUBO_GATEWAY || 'http://127.0.0.1:8080' +// create a RPC client +export const kubo: IPFSHTTPClient = create({ url: new URL(KUBO_RPC) }) + +// explorer resources +const EXPLORER_CID = 'bafybeidf7cpkwsjkq6xs3r6fbbxghbugilx3jtezbza7gua3k5wjixpmba' +export const EXPLORER_URL = KUBO_RPC + '/ipfs/' + EXPLORER_CID + '/#' export function exploreUrl(cid: CID): string { - return `${explorerUrl()}/explore/ipfs/${cid}` + return EXPLORER_URL + '/explore/ipfs/' + cid } - -export function explorerUrl(): string { - return 'http://127.0.0.1:5001/ipfs/bafybeidf7cpkwsjkq6xs3r6fbbxghbugilx3jtezbza7gua3k5wjixpmba/#' +export function gatewayUrl(cid: CID): string { + return KUBO_GATEWAY + '/ipfs/' + cid } diff --git a/src/scripts/hello.ts b/src/scripts/hello.ts index 7e2c8770c1329cdfe108eae4e4f22ddf84d516d9..6a9ed8fd411b018a2ae3f182e02e1dd3601f6a98 100644 --- a/src/scripts/hello.ts +++ b/src/scripts/hello.ts @@ -1 +1,3 @@ console.log('Hello World!') +console.log('HASURA_LISTEN_PORT') +console.log(process.env.HASURA_LISTEN_PORT) diff --git a/src/views/KuboView.vue b/src/views/KuboView.vue index dd12c5f595839946c0a71e594e5e889ffc63d85f..d6801e833b7dbe8a72cd31636eb8b4968610995e 100644 --- a/src/views/KuboView.vue +++ b/src/views/KuboView.vue @@ -1,10 +1,10 @@ <script setup lang="ts"> import { ref, type Ref } from 'vue' -import { kubo, explorerUrl } from '@/kubo' -// import { type StatResult } from 'ipfs-core-types/repo' +import { kubo, EXPLORER_URL } from '@/kubo' import prettyBytes from 'pretty-bytes' +// import { type StatResult } from 'ipfs-core-types/repo' -const stats: Ref<StatResult> = ref(null) +const stats: Ref<any> = ref(null) // Ref<StatResult> async function refresh() { stats.value = await kubo.repo.stat() @@ -27,7 +27,7 @@ refresh() </p> <p> for more info see - <a :href="explorerUrl()" target="_blank">explorer</a> + <a :href="EXPLORER_URL" target="_blank">explorer</a> </p> </div> </template>