diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..eb436f9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.env +dist +node_modules \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4472b9c..a5870b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ -FROM oven/bun +FROM node:alpine +WORKDIR /home +COPY package*.json ./ +RUN npm ci COPY . . -RUN bun install -ENTRYPOINT [ "bun", "./index.ts" ] \ No newline at end of file +ENTRYPOINT ["npm", "start"] \ No newline at end of file diff --git a/README.md b/README.md index f0fc0a3..ade30b8 100644 --- a/README.md +++ b/README.md @@ -231,4 +231,21 @@ SELECT * FROM block_meta LIMIT 10; └───────────┴─────────────────────┴───────────────────┴──────────────────────────────────────────────┴──────────────────────────────────────────────┘ 10 rows in set. Elapsed: 0.001 sec. Processed 8.19 thousand rows, 1.18 MB (5.51 million rows/s., 793.31 MB/s.) +``` + +## Docker environment + +Pull from GitHub Container registry +```bash +docker pull ghcr.io/pinax-network/substreams-sink-csv:latest +``` + +Run with `.env` file +```bash +docker run -it --rm --env-file .env -v $PWD:/home ghcr.io/pinax-network/substreams-sink-csv:latest +``` + +Build from source +```bash +docker build -t substreams-sink-csv . ``` \ No newline at end of file diff --git a/index.ts b/index.ts index b9e56ab..7ed916d 100644 --- a/index.ts +++ b/index.ts @@ -35,9 +35,9 @@ export async function action(options: CSVRunOptions ) { // Cursor const moduleHash = await getModuleHash(options); console.log(JSON.stringify({manifest: options.manifest, moduleName: options.moduleName, moduleHash})); - const { name, cursorFile, clockFile, sessionFile } = parseFilename(moduleHash, options); + const { name, dirname, cursorFile, clockFile, sessionFile } = parseFilename(moduleHash, options); const startCursor = fs.existsSync(cursorFile) ? fs.readFileSync(cursorFile, "utf8") : ''; - console.log(JSON.stringify({name, cursorFile, clockFile, sessionFile})); + console.log(JSON.stringify({name, dirname, cursorFile, clockFile, sessionFile})); // CSV writer (append) const clockWriter = fs.createWriteStream(clockFile, {flags: "a"}); diff --git a/src/parseFilename.ts b/src/parseFilename.ts index 360f5c3..0ae9aaa 100644 --- a/src/parseFilename.ts +++ b/src/parseFilename.ts @@ -12,16 +12,17 @@ export function parseFilename(moduleHash: string, options: CSVRunOptions) { const cursorFile = `${name}.cursor`; const clockFile = `${name}.clock`; const sessionFile = `${name}.session`; - return { name, cursorFile, clockFile, sessionFile }; + return { name, dirname, cursorFile, clockFile, sessionFile }; } // auto-generate filename (--.csv) const network = parseNetwork(options.substreamsEndpoint); const name = `${network}-${moduleHash}-${options.moduleName}` + const dirname = import.meta.dirname; const cursorFile = `${name}.cursor`; const clockFile = `${name}.clock`; const sessionFile = `${name}.session`; - return { name, cursorFile, clockFile, sessionFile }; + return { name, dirname, cursorFile, clockFile, sessionFile }; } export function parseNetwork(endpoint: string) {