Skip to content

Commit a34eb5f

Browse files
committed
Merge branch 'main' into feat/adapt-node-envs
2 parents ef028cb + 65a89dc commit a34eb5f

4 files changed

Lines changed: 31 additions & 15 deletions

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @alexcos20 @bogdanfazakas @giurgiur99 @denisiuriet @ndrpp @andreip136
1+
* @alexcos20 @bogdanfazakas @giurgiur99 @dnsi0 @ndrpp @andreip136

Dockerfile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@ ENV NODE_ENV=production \
3333

3434
EXPOSE 9000 9001 9002 9003 9005 8000
3535

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
36+
# Docker group membership is handled at runtime in docker-entrypoint.sh by
37+
# inspecting the GID of /var/run/docker.sock, so it works across hosts.
4138

4239
WORKDIR /usr/src/app
4340

docker-entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,15 @@ set -e
55
# Runs as root, then drops to 'node' user via gosu.
66
chown -R node:node /usr/src/app/databases /usr/src/app/c2d_storage /usr/src/app/logs 2>/dev/null || true
77

8+
# Add node user to the docker group matching the host's /var/run/docker.sock GID,
9+
# so compute jobs can access the socket regardless of the host's docker GID.
10+
if [ -S /var/run/docker.sock ]; then
11+
SOCK_GID=$(stat -c '%g' /var/run/docker.sock)
12+
if ! getent group "$SOCK_GID" > /dev/null 2>&1; then
13+
groupadd -g "$SOCK_GID" dockerhost 2>/dev/null || true
14+
fi
15+
DOCKER_GROUP=$(getent group "$SOCK_GID" | cut -d: -f1)
16+
usermod -aG "$DOCKER_GROUP" node
17+
fi
18+
819
exec gosu node dumb-init -- "$@"

src/components/c2d/compute_engine_docker.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ import { dockerRegistrysAuth, dockerRegistryAuth } from '../../@types/OceanNode.
6666
import { EncryptMethod } from '../../@types/fileObject.js'
6767
import { ZeroAddress } from 'ethers'
6868

69+
const C2D_CONTAINER_UID = 1000
70+
const C2D_CONTAINER_GID = 1000
71+
6972
const trivyImage = 'aquasec/trivy:0.69.3' // Use pinned versions for safety
7073

7174
export class C2DEngineDocker extends C2DEngine {
@@ -1532,7 +1535,7 @@ export class C2DEngineDocker extends C2DEngine {
15321535
if (!jobRes[0].isRunning) return null
15331536
try {
15341537
const job = jobRes[0]
1535-
const container = await this.docker.getContainer(job.jobId + '-algoritm')
1538+
const container = this.docker.getContainer(job.jobId + '-algoritm')
15361539
const details = await container.inspect()
15371540
if (details.State.Running === false) return null
15381541
return await container.logs({
@@ -1791,6 +1794,8 @@ export class C2DEngineDocker extends C2DEngine {
17911794
// create the container
17921795
const mountVols: any = { '/data': {} }
17931796
const hostConfig: HostConfig = {
1797+
// limit number of Pids container can spawn, to avoid flooding
1798+
PidsLimit: 512,
17941799
Mounts: [
17951800
{
17961801
Type: 'volume',
@@ -1832,9 +1837,10 @@ export class C2DEngineDocker extends C2DEngine {
18321837
AttachStdin: false,
18331838
AttachStdout: true,
18341839
AttachStderr: true,
1835-
Tty: true,
1840+
Tty: false,
18361841
OpenStdin: false,
18371842
StdinOnce: false,
1843+
User: `${C2D_CONTAINER_UID}:${C2D_CONTAINER_GID}`,
18381844
Volumes: mountVols,
18391845
HostConfig: hostConfig
18401846
}
@@ -1849,8 +1855,10 @@ export class C2DEngineDocker extends C2DEngine {
18491855
containerInfo.HostConfig.Devices = advancedConfig.Devices
18501856
if (advancedConfig.GroupAdd)
18511857
containerInfo.HostConfig.GroupAdd = advancedConfig.GroupAdd
1852-
if (advancedConfig.SecurityOpt)
1853-
containerInfo.HostConfig.SecurityOpt = advancedConfig.SecurityOpt
1858+
containerInfo.HostConfig.SecurityOpt = [
1859+
'no-new-privileges',
1860+
...(advancedConfig.SecurityOpt ?? [])
1861+
]
18541862
if (advancedConfig.Binds) containerInfo.HostConfig.Binds = advancedConfig.Binds
18551863
containerInfo.HostConfig.CapDrop = ['ALL']
18561864
for (const cap of advancedConfig.CapDrop ?? []) {
@@ -1910,7 +1918,7 @@ export class C2DEngineDocker extends C2DEngine {
19101918
let container
19111919
let details
19121920
try {
1913-
container = await this.docker.getContainer(job.jobId + '-algoritm')
1921+
container = this.docker.getContainer(job.jobId + '-algoritm')
19141922
details = await container.inspect()
19151923
} catch (e) {
19161924
console.error(
@@ -2015,7 +2023,7 @@ export class C2DEngineDocker extends C2DEngine {
20152023
job.statusText = C2DStatusText.JobSettle
20162024
let container
20172025
try {
2018-
container = await this.docker.getContainer(job.jobId + '-algoritm')
2026+
container = this.docker.getContainer(job.jobId + '-algoritm')
20192027
} catch (e) {
20202028
CORE_LOGGER.debug('Could not retrieve container: ' + e.message)
20212029
job.isRunning = false
@@ -2213,7 +2221,7 @@ export class C2DEngineDocker extends C2DEngine {
22132221
this.releaseCpus(job.jobId)
22142222

22152223
try {
2216-
const container = await this.docker.getContainer(job.jobId + '-algoritm')
2224+
const container = this.docker.getContainer(job.jobId + '-algoritm')
22172225
if (container) {
22182226
if (job.status !== C2DStatusNumber.AlgorithmFailed) {
22192227
writeFileSync(
@@ -2939,7 +2947,7 @@ export class C2DEngineDocker extends C2DEngine {
29392947

29402948
if (existsSync(destination)) {
29412949
// now, upload it to the container
2942-
const container = await this.docker.getContainer(job.jobId + '-algoritm')
2950+
const container = this.docker.getContainer(job.jobId + '-algoritm')
29432951

29442952
try {
29452953
// await container2.putArchive(destination, {
@@ -3027,7 +3035,7 @@ export class C2DEngineDocker extends C2DEngine {
30273035
}
30283036

30293037
// delete output folders
3030-
await this.deleteOutputFolder(job)
3038+
this.deleteOutputFolder(job)
30313039
// delete the job
30323040
await this.db.deleteJob(job.jobId)
30333041
return true

0 commit comments

Comments
 (0)