Skip to content

Commit e567c66

Browse files
committed
Change network (bridge), fix bug, add uid/gid
1 parent e44dd5e commit e567c66

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

functions/redisCommand.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ var log4js = require('log4js');
66
var createJobMessage = require('../common/jobMessage.js').createJobMessage;
77
var os = require('os');
88

9+
// Used to run worker containers as local user (should be set in the Hyperflow container)
10+
const uid = process.env.USER_ID;
11+
const gid = process.env.USER_GID;
12+
913
// limit of parallel jobs
1014
const MAX_PARALLELISM = process.env.HF_VAR_REDIS_CMD_MAX_PARALLELISM || 10;
1115
// how long to sleep in the case max parallelism is achieved
@@ -50,14 +54,20 @@ async function redisCommand(ins, outs, context, cb) {
5054
// if 'container' is present, run through Docker, mounting all directories if necessary
5155
if (!work_dir) { work_dir=process.cwd; }
5256
if (context.container) {
53-
cmd = 'docker run --network container:redis --name ' + context.name + "_" + context.taskId.replace(/:/g, '_');
57+
cmd = 'docker run --network hyperflow-net --name ' + context.name + "_" + context.taskId.replace(/:/g, '_');
5458
if (input_dir) cmd += ' -v ' + input_dir + ':/input_dir ';
5559
if (work_dir) cmd += ' -v ' + work_dir + ':/work_dir ';
5660
if (output_dir) cmd += ' -v ' + output_dir + ':/output_dir ';
57-
cmd += ' -e HF_LOG_NODE_NAME="' + os.hostname() + '"';
61+
if (uid && gid) {
62+
cmd += ` --user ${uid}:${gid}`;
63+
} else {
64+
console.warn("⚠️ HOST_UID/HOST_GID not set — running job container as default user");
65+
}
66+
cmd += ' -e HF_LOG_NODE_NAME="' + os.hostname() + '" ';
5867
cmd += context.container + ' hflow-job-execute';
5968
} else cmd = 'hflow-job-execute'
6069

70+
6171
try {
6272
// if hyperflow also runs in container, chdir doesn't make sense
6373
if (work_dir && !process.env.HF_VAR_HFLOW_IN_CONTAINER) { process.chdir(work_dir); }

0 commit comments

Comments
 (0)