Skip to content

Commit

Permalink
feat: Add docker rootless feature flag and its implementation for sup…
Browse files Browse the repository at this point in the history
…porting docke rootless environment
  • Loading branch information
kimsehwan96 committed Feb 10, 2024
1 parent 1b0faae commit aa3b05e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ServerlessPythonRequirements {
dockerBuildCmdExtraArgs: [],
dockerRunCmdExtraArgs: [],
dockerExtraFiles: [],
dockerRootless: false,
useStaticCache: true,
useDownloadCache: true,
cacheLocation: false,
Expand Down
33 changes: 21 additions & 12 deletions lib/pip.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,17 @@ async function installRequirements(targetFolder, pluginInstance) {
}
// Install requirements with pip
// Set the ownership of the current folder to user
pipCmds.push([
'chown',
'-R',
`${process.getuid()}:${process.getgid()}`,
'/var/task',
]);
// If you use docker-rootless, you don't need to set the ownership
if (options.dockerRootless !== true) {
pipCmds.push([
'chown',
'-R',
`${process.getuid()}:${process.getgid()}`,
'/var/task',
]);
} else {
pipCmds.push(['chown', '-R', '0:0', '/var/task']);
}
} else {
// Use same user so --cache-dir works
dockerCmd.push('-u', await getDockerUid(bindPath, pluginInstance));
Expand All @@ -345,12 +350,16 @@ async function installRequirements(targetFolder, pluginInstance) {
if (process.platform === 'linux') {
if (options.useDownloadCache) {
// Set the ownership of the download cache dir back to user
pipCmds.push([
'chown',
'-R',
`${process.getuid()}:${process.getgid()}`,
dockerDownloadCacheDir,
]);
if (options.dockerRootless !== true) {
pipCmds.push([
'chown',
'-R',
`${process.getuid()}:${process.getgid()}`,
dockerDownloadCacheDir,
]);
} else {
pipCmds.push(['chown', '-R', '0:0', dockerDownloadCacheDir]);
}
}
}

Expand Down

0 comments on commit aa3b05e

Please sign in to comment.