Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker rootless feature flag and its implementation for supporting docke rootless environment #818

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading