Skip to content

Commit 53d76b0

Browse files
committed
feat: add docker rootless feature flag and its implementation for supporting docke rootless environment
1 parent 1b0faae commit 53d76b0

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class ServerlessPythonRequirements {
5050
dockerBuildCmdExtraArgs: [],
5151
dockerRunCmdExtraArgs: [],
5252
dockerExtraFiles: [],
53+
dockerRootless: false,
5354
useStaticCache: true,
5455
useDownloadCache: true,
5556
cacheLocation: false,

lib/pip.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,17 @@ async function installRequirements(targetFolder, pluginInstance) {
327327
}
328328
// Install requirements with pip
329329
// Set the ownership of the current folder to user
330-
pipCmds.push([
331-
'chown',
332-
'-R',
333-
`${process.getuid()}:${process.getgid()}`,
334-
'/var/task',
335-
]);
330+
// If you use docker-rootless, you don't need to set the ownership
331+
if (options.dockerRootless !== true) {
332+
pipCmds.push([
333+
'chown',
334+
'-R',
335+
`${process.getuid()}:${process.getgid()}`,
336+
'/var/task',
337+
]);
338+
} else {
339+
pipCmds.push(['chown', '-R', '0:0', '/var/task']);
340+
}
336341
} else {
337342
// Use same user so --cache-dir works
338343
dockerCmd.push('-u', await getDockerUid(bindPath, pluginInstance));
@@ -345,12 +350,16 @@ async function installRequirements(targetFolder, pluginInstance) {
345350
if (process.platform === 'linux') {
346351
if (options.useDownloadCache) {
347352
// Set the ownership of the download cache dir back to user
348-
pipCmds.push([
349-
'chown',
350-
'-R',
351-
`${process.getuid()}:${process.getgid()}`,
352-
dockerDownloadCacheDir,
353-
]);
353+
if (options.dockerRootless !== true) {
354+
pipCmds.push([
355+
'chown',
356+
'-R',
357+
`${process.getuid()}:${process.getgid()}`,
358+
dockerDownloadCacheDir,
359+
]);
360+
} else {
361+
pipCmds.push(['chown', '-R', '0:0', dockerDownloadCacheDir]);
362+
}
354363
}
355364
}
356365

0 commit comments

Comments
 (0)