Skip to content

Commit a1e1316

Browse files
authored
Merge pull request #1303 from oceanprotocol/feat/adapt-node-envs
switch envs, resources are shared on multiple envs and are exclusive
2 parents 8f22b0e + eccfbfd commit a1e1316

19 files changed

Lines changed: 644 additions & 483 deletions

.env.example

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@ export P2P_BOOTSTRAP_NODES=
6565
export P2P_FILTER_ANNOUNCED_ADDRESSES=
6666

6767
## compute
68-
# Example with cross-resource constraints (constraints are optional and backwards-compatible):
69-
# export DOCKER_COMPUTE_ENVIRONMENTS='[{"socketPath":"/var/run/docker.sock","storageExpiry":604800,"maxJobDuration":3600,"minJobDuration":60,"fees":{"1":[{"feeToken":"0x123","prices":[{"id":"cpu","price":1},{"id":"ram","price":0.1},{"id":"disk","price":0.01}]}]},"resources":[{"id":"cpu","total":8,"max":8,"min":1,"constraints":[{"id":"ram","min":1,"max":3},{"id":"disk","min":10,"max":100}]},{"id":"ram","total":32,"max":32,"min":1},{"id":"disk","total":500,"max":500,"min":10},{"id":"gpu","total":4,"max":4,"min":0,"constraints":[{"id":"ram","min":8,"max":32},{"id":"cpu","min":2,"max":4}]}]}]'
68+
# Each environment defines its own resources (CPU, RAM, disk, GPUs) with full configuration.
69+
# CPU, RAM, and disk are per-env exclusive: inUse tracked only within the environment where the job runs.
70+
# A global check ensures the aggregate usage across all environments does not exceed physical capacity.
71+
# GPUs are shared-exclusive: if a job on envA uses gpu0, it shows as in-use on envB too.
72+
# CPU cores are automatically partitioned across environments based on each env's cpu.total.
73+
# CPU and RAM defaults are auto-detected from the system when not configured.
74+
# export DOCKER_COMPUTE_ENVIRONMENTS='[{"socketPath":"/var/run/docker.sock","environments":[{"id":"envA","storageExpiry":604800,"maxJobDuration":3600,"minJobDuration":60,"resources":[{"id":"cpu","total":4,"max":4,"min":1,"type":"cpu"},{"id":"ram","total":16,"max":16,"min":1,"type":"ram"},{"id":"disk","total":500,"max":500,"min":10,"type":"disk"},{"id":"gpu0","total":1,"max":1,"min":0,"type":"gpu","init":{"deviceRequests":{"Driver":"nvidia","DeviceIDs":["0"],"Capabilities":[["gpu"]]}}}],"fees":{"1":[{"feeToken":"0x123","prices":[{"id":"cpu","price":1},{"id":"ram","price":0.1},{"id":"disk","price":0.01},{"id":"gpu0","price":5}]}]}}]}]'
7075
export DOCKER_COMPUTE_ENVIRONMENTS=
7176

7277

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ jobs:
290290
DB_PASSWORD: 'changeme'
291291
MAX_REQ_PER_MINUTE: 320
292292
MAX_CONNECTIONS_PER_MINUTE: 320
293-
DOCKER_COMPUTE_ENVIRONMENTS: '[{"socketPath":"/var/run/docker.sock","resources":[{"id":"disk","total":10}],"storageExpiry":604800,"maxJobDuration":3600,"minJobDuration": 60,"fees":{"8996":[{"prices":[{"id":"cpu","price":1}]}]},"free":{"maxJobDuration":60,"minJobDuration": 10,"maxJobs":3,"resources":[{"id":"cpu","max":1},{"id":"ram","max":1},{"id":"disk","max":1}]}}]'
293+
DOCKER_COMPUTE_ENVIRONMENTS: '[{"socketPath":"/var/run/docker.sock","environments":[{"storageExpiry":604800,"maxJobDuration":3600,"minJobDuration":60,"resources":[{"id":"cpu","total":4,"max":4,"min":1,"type":"cpu"},{"id":"ram","total":10,"max":10,"min":1,"type":"ram"},{"id":"disk","total":10,"max":10,"min":0,"type":"disk"}],"fees":{"8996":[{"prices":[{"id":"cpu","price":1}]}]},"free":{"maxJobDuration":60,"maxJobs":3,"resources":[{"id":"cpu","max":1},{"id":"ram","max":1},{"id":"disk","max":1}]}}]}]'
294294
DOCKER_REGISTRY_AUTHS: ${{ env.DOCKER_REGISTRY_AUTHS }}
295295
- name: Check Ocean Node is running
296296
run: |

config.json

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -93,57 +93,57 @@
9393
"claimDurationTimeout": 3600,
9494
"validateUnsignedDDO": true,
9595
"jwtSecret": "ocean-node-secret",
96+
"enableBenchmark": false,
9697
"dockerComputeEnvironments": [
9798
{
9899
"socketPath": "/var/run/docker.sock",
99-
"resources": [
100+
"environments": [
100101
{
101-
"id": "disk",
102-
"total": 1
103-
}
104-
],
105-
"storageExpiry": 604800,
106-
"maxJobDuration": 3600,
107-
"minJobDuration": 60,
108-
"access": {
109-
"addresses": [],
110-
"accessLists": []
111-
},
112-
"fees": {
113-
"8996": [
114-
{
115-
"prices": [
102+
"storageExpiry": 604800,
103+
"maxJobDuration": 3600,
104+
"minJobDuration": 60,
105+
"resources": [
106+
{
107+
"id": "disk",
108+
"total": 1
109+
}
110+
],
111+
"access": {
112+
"addresses": [],
113+
"accessLists": []
114+
},
115+
"fees": {
116+
"8996": [
116117
{
117-
"id": "cpu",
118-
"price": 1
118+
"prices": [
119+
{
120+
"id": "cpu",
121+
"price": 1
122+
}
123+
]
119124
}
120125
]
121-
}
122-
]
123-
},
124-
"free": {
125-
"maxJobDuration": 3600,
126-
"minJobDuration": 60,
127-
"maxJobs": 3,
128-
"access": {
129-
"addresses": [],
130-
"accessLists": []
131-
},
132-
"resources": [
133-
{
134-
"id": "cpu",
135-
"max": 1
136-
},
137-
{
138-
"id": "ram",
139-
"max": 1
140126
},
141-
{
142-
"id": "disk",
143-
"max": 1
127+
"free": {
128+
"maxJobDuration": 3600,
129+
"maxJobs": 3,
130+
"resources": [
131+
{
132+
"id": "cpu",
133+
"max": 1
134+
},
135+
{
136+
"id": "ram",
137+
"max": 1
138+
},
139+
{
140+
"id": "disk",
141+
"max": 1
142+
}
143+
]
144144
}
145-
]
146-
}
145+
}
146+
]
147147
}
148148
]
149149
}

docs/env.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ The `DOCKER_COMPUTE_ENVIRONMENTS` environment variable should be a JSON array of
203203
- **imageRetentionDays** - how long docker images are kept, in days. Default: 7
204204
- **imageCleanupInterval** - how often to run cleanup for docker images, in seconds. Min: 3600 (1hour), Default: 86400 (24 hours)
205205
- **paymentClaimInterval** - how often to run payment claiming, in seconds. Default: 3600 (1 hour)
206+
- **enableBenchmark** - when set to `true`, the node will auto-create a benchmark compute environment at startup using the system's available resources (CPU, RAM, disk, GPUs). Default: `false`
206207
- **storageExpiry**: Amount of seconds for storage expiry.(Mandatory)
207208
- **maxJobDuration**: Maximum duration in seconds for a job.(Mandatory)
208209
- **minJobDuration**: Minimum duration in seconds for a job.(Mandatory)

scripts/ocean-node-quickstart.sh

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -239,47 +239,51 @@ if [ -z "$DOCKER_COMPUTE_ENVIRONMENTS" ]; then
239239
export DOCKER_COMPUTE_ENVIRONMENTS='[
240240
{
241241
"socketPath": "/var/run/docker.sock",
242-
"resources": [
242+
"environments": [
243243
{
244-
"id": "disk",
245-
"total": 10
246-
}
247-
],
248-
"storageExpiry": 604800,
249-
"maxJobDuration": 36000,
250-
"minJobDuration": 60,
251-
"fees": {
252-
"1": [
253-
{
254-
"feeToken": "0x123",
255-
"prices": [
244+
"storageExpiry": 604800,
245+
"maxJobDuration": 36000,
246+
"minJobDuration": 60,
247+
"resources": [
248+
{
249+
"id": "disk",
250+
"total": 10
251+
}
252+
],
253+
"fees": {
254+
"1": [
256255
{
257-
"id": "cpu",
258-
"price": 1
256+
"feeToken": "0x123",
257+
"prices": [
258+
{
259+
"id": "cpu",
260+
"price": 1
261+
}
262+
]
259263
}
260264
]
261-
}
262-
]
263-
},
264-
"free": {
265-
"maxJobDuration": 360000,
266-
"minJobDuration": 60,
267-
"maxJobs": 3,
268-
"resources": [
269-
{
270-
"id": "cpu",
271-
"max": 1
272-
},
273-
{
274-
"id": "ram",
275-
"max": 1
276265
},
277-
{
278-
"id": "disk",
279-
"max": 1
266+
"free": {
267+
"maxJobDuration": 360000,
268+
"minJobDuration": 60,
269+
"maxJobs": 3,
270+
"resources": [
271+
{
272+
"id": "cpu",
273+
"max": 1
274+
},
275+
{
276+
"id": "ram",
277+
"max": 1
278+
},
279+
{
280+
"id": "disk",
281+
"max": 1
282+
}
283+
]
280284
}
281-
]
282-
}
285+
}
286+
]
283287
}
284288
]'
285289
fi
@@ -628,7 +632,7 @@ if command -v jq &> /dev/null; then
628632

629633
if [ "$GPU_COUNT" -gt 0 ]; then
630634
echo "Detected $GPU_COUNT GPU type(s). Updating configuration..."
631-
DOCKER_COMPUTE_ENVIRONMENTS=$(echo "$DOCKER_COMPUTE_ENVIRONMENTS" | jq --argjson gpus "$DETECTED_GPUS" '.[0].resources += $gpus')
635+
DOCKER_COMPUTE_ENVIRONMENTS=$(echo "$DOCKER_COMPUTE_ENVIRONMENTS" | jq --argjson gpus "$DETECTED_GPUS" '.[0].environments[0].resources += $gpus')
632636
echo "GPUs added to Compute Environment resources."
633637
else
634638
echo "No GPUs detected."

src/@types/C2D/C2D.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,19 @@ export interface ComputeEnvironment extends ComputeEnvironmentBaseConfig {
141141
runMaxWaitTimeFree: number
142142
}
143143

144+
export interface C2DEnvironmentConfig {
145+
id?: string
146+
description?: string
147+
storageExpiry?: number
148+
minJobDuration?: number
149+
maxJobDuration?: number
150+
maxJobs?: number
151+
fees?: ComputeEnvFeesStructure
152+
access?: ComputeAccessList
153+
free?: ComputeEnvironmentFreeOptions
154+
resources?: ComputeResource[]
155+
}
156+
144157
export interface C2DDockerConfig {
145158
socketPath: string
146159
protocol: string
@@ -149,19 +162,12 @@ export interface C2DDockerConfig {
149162
caPath: string
150163
certPath: string
151164
keyPath: string
152-
storageExpiry?: number
153-
maxJobDuration?: number
154-
minJobDuration?: number
155-
maxJobs?: number
156-
fees: ComputeEnvFeesStructure
157-
resources?: ComputeResource[] // optional, owner can overwrite
158-
free?: ComputeEnvironmentFreeOptions
159-
access: ComputeAccessList
160165
imageRetentionDays?: number // Default: 7 days
161166
imageCleanupInterval?: number // Default: 86400 seconds (24 hours)
162167
paymentClaimInterval?: number // Default: 3600 seconds (1 hours)
163168
scanImages?: boolean
164169
scanImageDBUpdateInterval?: number // Default: 12 hours
170+
environments: C2DEnvironmentConfig[]
165171
enableNetwork?: boolean // whether network is enabled for algorithm containers
166172
}
167173

src/@types/OceanNode.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export interface OceanNodeConfig {
140140
jwtSecret?: string
141141
httpCertPath?: string
142142
httpKeyPath?: string
143+
enableBenchmark?: boolean
143144
persistentStorage?: PersistentStorageConfig
144145
}
145146

0 commit comments

Comments
 (0)