Skip to content

Commit fa9ac03

Browse files
authored
Add docker rootless feature flag and its implementation for supporting docke rootless environment (#818)
1 parent 549aba0 commit fa9ac03

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

Diff for: index.js

+1
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,

Diff for: lib/pip.js

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

0 commit comments

Comments
 (0)