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

update docker instructions #27

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading