Skip to content
Snippets Groups Projects
Commit e9a15059 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

adapt code for env vars

parent 3bf8e2c3
No related branches found
No related tags found
No related merge requests found
# === 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 DB_PASSWORD=my_db_password
# === HASURA ===
HASURA_GRAPHQL_ADMIN_SECRET=my_hasura_password HASURA_GRAPHQL_ADMIN_SECRET=my_hasura_password
HASURA_LISTEN_PORT=8765 HASURA_LISTEN_PORT=8765
#!/bin/sh
# exports .env variables to be used by an other process
set -a
source ./.env
set +a
\ No newline at end of file
...@@ -13,7 +13,7 @@ RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile ...@@ -13,7 +13,7 @@ RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
# datapod image # datapod image
FROM base FROM base
COPY --from=deps /app/node_modules /app/node_modules 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 # TODO build image only for indexer without app
...@@ -22,3 +22,4 @@ CMD ["npx", "tsx", "src/scripts/hello.ts"] ...@@ -22,3 +22,4 @@ CMD ["npx", "tsx", "src/scripts/hello.ts"]
# build and run for test # build and run for test
# docker buildx build . -t test-datapod # docker buildx build . -t test-datapod
# docker run --rm -it test-datapod # docker run --rm -it test-datapod
# CMD ["pnpm", "exec", "tsx", "src/scripts/hello.ts"]
...@@ -15,7 +15,7 @@ TODO use in prod with docker ...@@ -15,7 +15,7 @@ TODO use in prod with docker
## Dev ## Dev
To install dev dependencies Install dev dependencies
```sh ```sh
# use node version 20 # use node version 20
...@@ -24,7 +24,7 @@ nvm use 20 ...@@ -24,7 +24,7 @@ nvm use 20
pnpm install pnpm install
``` ```
Then start a kubo node with pubsub Start a kubo node with pubsub and postgres/hasura
```sh ```sh
# start kubo node TODO put this in the docker # start kubo node TODO put this in the docker
...@@ -33,7 +33,25 @@ ipfs daemon --enable-pubsub-experiment ...@@ -33,7 +33,25 @@ ipfs daemon --enable-pubsub-experiment
docker compose up -d 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 ## Doc
......
...@@ -6,7 +6,7 @@ After exporting the data to json files with the Rust script from `v2s-datapod`. ...@@ -6,7 +6,7 @@ After exporting the data to json files with the Rust script from `v2s-datapod`.
```sh ```sh
# doImport() # doImport()
# takes about 200 seconds (4 minutes) # 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. 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. ...@@ -20,6 +20,6 @@ This will make easier to insert this data in any AMT or other data structure.
```sh ```sh
# doAllCplusCidsToAMT() # doAllCplusCidsToAMT()
# takes about 180 seconds # takes about 180 seconds
time npx tsx src/scripts/cesium-plus-import.ts time pnpm exec tsx src/scripts/cesium-plus-import.ts
# bafyreiffn3kkrakf7qj5m3wepsoxjwcojmesfyoexsvsovx23nhbfqu6bq # bafyreiffn3kkrakf7qj5m3wepsoxjwcojmesfyoexsvsovx23nhbfqu6bq
``` ```
\ No newline at end of file
...@@ -5,5 +5,5 @@ Then start pubsub collector and database indexer with: ...@@ -5,5 +5,5 @@ Then start pubsub collector and database indexer with:
```sh ```sh
# start the collector and indexer # start the collector and indexer
npx tsx src/indexer/start.ts pnpm exec tsx src/indexer/start.ts
``` ```
...@@ -5,9 +5,12 @@ import pg from 'pg' ...@@ -5,9 +5,12 @@ import pg from 'pg'
import { kubo } from '../kubo' import { kubo } from '../kubo'
import type { CplusProfile } from '../cesium-plus' import type { CplusProfile } from '../cesium-plus'
// TODO proper env // define form env
const 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 // group query and param builder to limit error
...@@ -19,8 +22,10 @@ interface QueryBuilder { ...@@ -19,8 +22,10 @@ interface QueryBuilder {
// initialize client // initialize client
const { Client } = pg const { Client } = pg
export const client = new Client({ export const client = new Client({
user: 'postgres', host: env.DB_HOST,
password: env['DB_PASSWORD'] port: env.DB_PORT,
user: env.DB_USER,
password: env.DB_PASSWORD
}) })
await client.connect() await client.connect()
......
...@@ -2,13 +2,20 @@ import { create } from 'kubo-rpc-client' ...@@ -2,13 +2,20 @@ import { create } from 'kubo-rpc-client'
import type { IPFSHTTPClient } from 'kubo-rpc-client' import type { IPFSHTTPClient } from 'kubo-rpc-client'
import { CID } from 'multiformats' import { CID } from 'multiformats'
// connect to the default API address http://localhost:5001 // env
export const kubo: IPFSHTTPClient = create({ url: new URL('http://127.0.0.1:5001') }) 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 { export function exploreUrl(cid: CID): string {
return `${explorerUrl()}/explore/ipfs/${cid}` return EXPLORER_URL + '/explore/ipfs/' + cid
} }
export function gatewayUrl(cid: CID): string {
export function explorerUrl(): string { return KUBO_GATEWAY + '/ipfs/' + cid
return 'http://127.0.0.1:5001/ipfs/bafybeidf7cpkwsjkq6xs3r6fbbxghbugilx3jtezbza7gua3k5wjixpmba/#'
} }
console.log('Hello World!') console.log('Hello World!')
console.log('HASURA_LISTEN_PORT')
console.log(process.env.HASURA_LISTEN_PORT)
<script setup lang="ts"> <script setup lang="ts">
import { ref, type Ref } from 'vue' import { ref, type Ref } from 'vue'
import { kubo, explorerUrl } from '@/kubo' import { kubo, EXPLORER_URL } from '@/kubo'
// import { type StatResult } from 'ipfs-core-types/repo'
import prettyBytes from 'pretty-bytes' 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() { async function refresh() {
stats.value = await kubo.repo.stat() stats.value = await kubo.repo.stat()
...@@ -27,7 +27,7 @@ refresh() ...@@ -27,7 +27,7 @@ refresh()
</p> </p>
<p> <p>
for more info see for more info see
<a :href="explorerUrl()" target="_blank">explorer</a> <a :href="EXPLORER_URL" target="_blank">explorer</a>
</p> </p>
</div> </div>
</template> </template>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment