Skip to content

Commit

Permalink
Merge pull request #27 from pinax-network/docker
Browse files Browse the repository at this point in the history
update docker instructions
  • Loading branch information
DenisCarriere authored Mar 7, 2024
2 parents f03e960 + 15490e1 commit 13c8551
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
dist
node_modules
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
ENTRYPOINT ["npm", "start"]
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
```
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"});
Expand Down
5 changes: 3 additions & 2 deletions src/parseFilename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<network>-<moduleHash>-<moduleName>.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) {
Expand Down

0 comments on commit 13c8551

Please sign in to comment.