Skip to content

Commit eac5332

Browse files
committed
Merge branch 'main' into feat/update-c2d-docker-permissions
2 parents 92513ee + 93ffe5a commit eac5332

26 files changed

Lines changed: 913 additions & 287 deletions

.dockerignore

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,17 @@ node_modules
22
/dist
33
logs
44
c2d_storage
5-
.env.local
6-
.env
5+
databases
6+
.env
7+
.env.*
8+
.git
9+
.github
10+
docs
11+
src/test
12+
*.md
13+
*.log
14+
.nyc_output
15+
coverage
16+
docker-compose.yml
17+
elasticsearch-compose.yml
18+
typesense-compose.yml

Dockerfile

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,56 @@
1-
FROM ubuntu:22.04 AS base
2-
RUN apt-get update && apt-get -y install bash curl git wget libatomic1 python3 build-essential
3-
COPY .nvmrc /usr/src/app/
4-
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
5-
ENV NVM_DIR=/usr/local/nvm
6-
RUN mkdir $NVM_DIR
7-
ENV NODE_VERSION=v22.15.0
8-
# Install nvm with node and npm
9-
RUN curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash \
10-
&& source $NVM_DIR/nvm.sh \
11-
&& nvm install $NODE_VERSION \
12-
&& nvm alias default $NODE_VERSION \
13-
&& nvm use default
14-
ENV NODE_PATH=$NVM_DIR/$NODE_VERSION/lib/node_modules
15-
ENV PATH=$NVM_DIR/versions/node/$NODE_VERSION/bin:$PATH
16-
ENV IPFS_GATEWAY='https://ipfs.io/'
17-
ENV ARWEAVE_GATEWAY='https://arweave.net/'
18-
19-
FROM base AS builder
20-
COPY package*.json /usr/src/app/
21-
COPY scripts/ /usr/src/app/scripts/
22-
WORKDIR /usr/src/app/
1+
FROM node:22.15.0-bookworm@sha256:a1f1274dadd49738bcd4cf552af43354bb781a7e9e3bc984cfeedc55aba2ddd8 AS builder
2+
RUN apt-get update && apt-get install -y --no-install-recommends \
3+
python3 \
4+
build-essential \
5+
libatomic1 \
6+
git \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
WORKDIR /usr/src/app
10+
COPY package*.json ./
11+
COPY scripts/ ./scripts/
2312
RUN npm ci
13+
COPY . .
14+
RUN npm run build && npm prune --omit=dev
15+
16+
17+
FROM node:22.15.0-bookworm-slim@sha256:557e52a0fcb928ee113df7e1fb5d4f60c1341dbda53f55e3d815ca10807efdce AS runner
18+
RUN apt-get update && apt-get install -y --no-install-recommends \
19+
dumb-init \
20+
gosu \
21+
libatomic1 \
22+
&& rm -rf /var/lib/apt/lists/*
23+
24+
ENV NODE_ENV=production \
25+
IPFS_GATEWAY='https://ipfs.io/' \
26+
ARWEAVE_GATEWAY='https://arweave.net/' \
27+
P2P_ipV4BindTcpPort=9000 \
28+
P2P_ipV4BindWsPort=9001 \
29+
P2P_ipV6BindTcpPort=9002 \
30+
P2P_ipV6BindWsPort=9003 \
31+
P2P_ipV4BindWssPort=9005 \
32+
HTTP_API_PORT=8000
33+
34+
EXPOSE 9000 9001 9002 9003 9005 8000
35+
36+
# GID of the docker group on the host. Needs to match so the node user can access
37+
# /var/run/docker.sock for compute jobs. Default is 999 (common on Debian/Ubuntu).
38+
# Override at build time if your host differs: docker build --build-arg DOCKER_GID=$(getent group docker | cut -d: -f3) .
39+
ARG DOCKER_GID=999
40+
RUN groupadd -g ${DOCKER_GID} docker && usermod -aG docker node
41+
42+
WORKDIR /usr/src/app
43+
44+
COPY --chown=node:node --from=builder /usr/src/app/dist ./dist
45+
COPY --chown=node:node --from=builder /usr/src/app/node_modules ./node_modules
46+
COPY --chown=node:node --from=builder /usr/src/app/schemas ./schemas
47+
COPY --chown=node:node --from=builder /usr/src/app/package.json ./
48+
COPY --chown=node:node --from=builder /usr/src/app/config.json ./
49+
50+
RUN mkdir -p databases c2d_storage logs
2451

52+
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
53+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
2554

26-
FROM base AS runner
27-
COPY . /usr/src/app
28-
WORKDIR /usr/src/app/
29-
COPY --from=builder /usr/src/app/node_modules/ /usr/src/app/node_modules/
30-
RUN npm run build
31-
ENV P2P_ipV4BindTcpPort=9000
32-
EXPOSE 9000
33-
ENV P2P_ipV4BindWsPort=9001
34-
EXPOSE 9001
35-
ENV P2P_ipV6BindTcpPort=9002
36-
EXPOSE 9002
37-
ENV P2P_ipV6BindWsPort=9003
38-
EXPOSE 9003
39-
ENV P2P_ipV4BindWssPort=9005
40-
EXPOSE 9005
41-
ENV HTTP_API_PORT=8000
42-
EXPOSE 8000
43-
ENV NODE_ENV='production'
44-
CMD ["npm","run","start"]
55+
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
56+
CMD ["node", "--max-old-space-size=28784", "--trace-warnings", "--experimental-specifier-resolution=node", "dist/index.js"]

docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Fix ownership of directories that may be mounted as volumes (owned by root).
5+
# Runs as root, then drops to 'node' user via gosu.
6+
chown -R node:node /usr/src/app/databases /usr/src/app/c2d_storage /usr/src/app/logs 2>/dev/null || true
7+
8+
exec gosu node dumb-init -- "$@"

docs/compute-pricing.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ This guide explains how to configure your node’s Docker compute environments a
55
## Overview
66

77
- **Configuration**: Define compute environments via the `DOCKER_COMPUTE_ENVIRONMENTS` environment variable (JSON) or via `config.json` under `dockerComputeEnvironments`.
8+
- **Environment**: Is a group of resources, payment and accesslists.
89
- **Resources**: Each environment declares resources (e.g. `cpu`, `ram`, `disk`, and optionally GPUs). You must declare a `disk` resource.
910
- **Pricing**: For each chain and fee token, you set a `price` per resource. Cost is computed as **price × amount × duration (in minutes, rounded up)**.
11+
- **Free**: Environments which does not require a payment for the resources, but most likley are very limited in terms of resources available and job duration.
12+
- **Image building**: **Free jobs cannot build images** (Dockerfiles are not allowed). For **paid jobs**, **image build time counts toward billable duration** and also consumes the job’s `maxJobDuration`.
1013

1114
## Pricing Units
1215

docs/env.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ The `DOCKER_COMPUTE_ENVIRONMENTS` environment variable should be a JSON array of
136136
[
137137
{
138138
"socketPath": "/var/run/docker.sock",
139+
"scanImages": true,
140+
"enableNetwork": false,
139141
"imageRetentionDays": 7,
140142
"imageCleanupInterval": 86400,
141143
"resources": [
@@ -194,6 +196,9 @@ The `DOCKER_COMPUTE_ENVIRONMENTS` environment variable should be a JSON array of
194196
#### Configuration Options
195197

196198
- **socketPath**: Path to the Docker socket (e.g., docker.sock).
199+
- **scanImages**: Whether Docker images should be scanned for vulnerabilities using Trivy. If enabled and critical vulnerabilities are found, the C2D job is rejected.
200+
- **scanImageDBUpdateInterval**: How often to update the vulnerability database, in seconds. Default: 43200 (12 hours)
201+
- **enableNetwork**: Whether networking is enabled for algorithm containers. Default: false
197202
- **imageRetentionDays** - how long docker images are kept, in days. Default: 7
198203
- **imageCleanupInterval** - how often to run cleanup for docker images, in seconds. Min: 3600 (1hour), Default: 86400 (24 hours)
199204
- **paymentClaimInterval** - how often to run payment claiming, in seconds. Default: 3600 (1 hour)
@@ -218,6 +223,7 @@ The `DOCKER_COMPUTE_ENVIRONMENTS` environment variable should be a JSON array of
218223
- **maxJobDuration**: Maximum duration in seconds for a free job.
219224
- **minJobDuration**: Minimum duration in seconds for a free job.
220225
- **maxJobs**: Maximum number of simultaneous free jobs.
226+
- **allowImageBuild**: If building images is allowed on free envs. Default: false
221227
- **access**: Access control configuration for free compute jobs. Works the same as the main `access` field.
222228
- **addresses**: Array of Ethereum addresses allowed to run free compute jobs.
223229
- **accessLists**: Array of AccessList contract addresses for free compute access control.

0 commit comments

Comments
 (0)