Skip to content

Commit adb000c

Browse files
Prepare chunkstorm for production (#1)
PR Blobscan/blobscan#793 adds support to store blobs in the Swarm network by using chunkstorm, and hence splitting, stamping and distributing chunks to multiple Bee nodes. This PR adds basic features to integrate this solution into our environments: - Added support for loading keystore (using KEYSTORE_PATH and KEYSTORE_PASSWORD variables) - Added env var STAMPERSTORE_PATH to configure stamperstore location - Support loading variables for .env file - Added Dockerfile - Added basic logger - Cleanup: remove depth param which was unused - Changed default port to 3050 (configurable using the PORT variable) - Renamed TARGET variable to BEE_ENDPOINT - Added github action for linting Related ticket: Blobscan/blobscan#750 --------- Co-authored-by: xfja <franjimenezaguilera@gmail.com>
1 parent 3c8cb7b commit adb000c

File tree

13 files changed

+3056
-334
lines changed

13 files changed

+3056
-334
lines changed

.dockerignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Version control
2+
.git
3+
.gitignore
4+
5+
# Dependencies
6+
node_modules
7+
npm-debug.log
8+
9+
# Environment variables
10+
.env
11+
.env.*
12+
13+
# Build outputs
14+
dist
15+
16+
# Development files
17+
*.test.ts
18+
*.spec.ts
19+
test
20+
tests
21+
coverage
22+
23+
# IDE specific files
24+
.idea
25+
.vscode
26+
*.swp
27+
*.swo
28+
29+
# OS specific files
30+
.DS_Store
31+
Thumbs.db

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
PRIVATE_KEY=0x1234567812345678123456781234567812345678123456781234567812345678
2+
BATCH_ID=0x1234567812345678123456781234567812345678123456781234567812345678
3+
BEE_ENDPOINT=http://localhost:1633

.eslintrc.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"plugins": ["@typescript-eslint"],
5+
"extends": [
6+
"eslint:recommended",
7+
"plugin:@typescript-eslint/recommended"
8+
],
9+
"env": {
10+
"node": true,
11+
"es6": true
12+
},
13+
"parserOptions": {
14+
"ecmaVersion": 2020,
15+
"sourceType": "module"
16+
},
17+
"rules": {
18+
"no-console": "warn",
19+
"no-unused-vars": "off",
20+
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }],
21+
"@typescript-eslint/explicit-module-boundary-types": "off",
22+
"@typescript-eslint/no-explicit-any": "warn"
23+
}
24+
}

.github/workflows/lint.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
lint:
11+
name: Lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '20'
20+
cache: 'npm'
21+
22+
- name: Install dependencies
23+
run: npm ci
24+
25+
- name: Run ESLint
26+
run: npm run lint
27+
28+
- name: Check TypeScript
29+
run: npx tsc --noEmit

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ node_modules
22
dist
33
*.bin
44
*.txt
5-
*.log
5+
*.log
6+
.env

Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
FROM node:20-alpine AS builder
3+
4+
WORKDIR /app
5+
6+
ENV NODE_ENV=production
7+
8+
COPY package*.json ./
9+
10+
RUN npm install
11+
12+
COPY tsconfig.json ./
13+
COPY src ./src
14+
15+
RUN npm run build
16+
17+
FROM node:20-alpine
18+
19+
LABEL maintainer="Blobscan Team"
20+
LABEL org.opencontainers.image.title="ChunkStorm"
21+
LABEL org.opencontainers.image.description="Simple Node.js server that splits, stamps and distributes chunks to multiple Bee nodes."
22+
LABEL org.opencontainers.image.created="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
23+
24+
ENV NODE_ENV=production
25+
ENV STAMPERSTORE_PATH=/app/stamperstore
26+
27+
WORKDIR /app
28+
RUN addgroup --system --gid 1001 nodejs && \
29+
adduser --system --uid 1001 --ingroup nodejs --shell /bin/sh nodeuser && \
30+
chown -R nodeuser:nodejs /app
31+
32+
COPY package*.json ./
33+
34+
RUN npm ci --only=production && npm cache clean --force
35+
36+
COPY --from=builder --chown=nodeuser:nodejs /app/dist ./dist
37+
38+
USER nodeuser
39+
40+
EXPOSE 3050
41+
42+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
43+
CMD wget --no-verbose --tries=1 --spider http://localhost:3050/health || exit 1
44+
45+
CMD ["node", "dist/index.js"]

0 commit comments

Comments
 (0)