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

feat(python): redirect pip cache to renovate #17038

Merged
merged 2 commits into from
Aug 8, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Array [
"LC_ALL": "en_US",
"NO_PROXY": "localhost",
"PATH": "/tmp/path",
"PIP_CACHE_DIR": "/tmp/renovate/cache/others/pip",
},
"maxBuffer": 10485760,
"timeout": 900000,
Expand All @@ -38,6 +39,7 @@ Array [
"LC_ALL": "en_US",
"NO_PROXY": "localhost",
"PATH": "/tmp/path",
"PIP_CACHE_DIR": "/tmp/renovate/cache/others/pip",
},
"maxBuffer": 10485760,
"timeout": 900000,
Expand All @@ -61,6 +63,7 @@ Array [
"LC_ALL": "en_US",
"NO_PROXY": "localhost",
"PATH": "/tmp/path",
"PIP_CACHE_DIR": "/tmp/renovate/cache/others/pip",
},
"maxBuffer": 10485760,
"timeout": 900000,
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/manager/pip-compile/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ describe('modules/manager/pip-compile/artifacts', () => {
'docker run --rm --name=renovate_sidecar --label=renovate_child ' +
'-v "/tmp/github/some/repo":"/tmp/github/some/repo" ' +
'-v "/tmp/renovate/cache":"/tmp/renovate/cache" ' +
'-e PIP_CACHE_DIR ' +
'-e BUILDPACK_CACHE_DIR ' +
'-w "/tmp/github/some/repo" ' +
'renovate/sidecar ' +
Expand Down Expand Up @@ -216,6 +217,7 @@ describe('modules/manager/pip-compile/artifacts', () => {
'docker run --rm --name=renovate_sidecar --label=renovate_child ' +
'-v "/tmp/github/some/repo":"/tmp/github/some/repo" ' +
'-v "/tmp/renovate/cache":"/tmp/renovate/cache" ' +
'-e PIP_CACHE_DIR ' +
'-e BUILDPACK_CACHE_DIR ' +
'-w "/tmp/github/some/repo" ' +
'renovate/sidecar ' +
Expand Down
4 changes: 4 additions & 0 deletions lib/modules/manager/pip-compile/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { exec } from '../../../util/exec';
import type { ExecOptions } from '../../../util/exec/types';
import {
deleteLocalFile,
ensureCacheDir,
readLocalFile,
writeLocalFile,
} from '../../../util/fs';
Expand Down Expand Up @@ -130,6 +131,9 @@ export async function updateArtifacts({
constraint,
},
],
extraEnv: {
PIP_CACHE_DIR: await ensureCacheDir('pip'),
},
};
logger.debug({ cmd }, 'pip-compile command');
await exec(cmd, execOptions);
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/manager/pip_requirements/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ describe('modules/manager/pip_requirements/artifacts', () => {
it('supports docker mode', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
fs.readLocalFile.mockResolvedValueOnce('new content');
fs.ensureCacheDir.mockResolvedValueOnce('/tmp/cache');
const execSnapshots = mockExecAll();

expect(
Expand Down Expand Up @@ -161,6 +162,7 @@ describe('modules/manager/pip_requirements/artifacts', () => {
'docker run --rm --name=renovate_sidecar --label=renovate_child ' +
'-v "/tmp/github/some/repo":"/tmp/github/some/repo" ' +
'-v "/tmp/renovate/cache":"/tmp/renovate/cache" ' +
'-e PIP_CACHE_DIR ' +
'-e BUILDPACK_CACHE_DIR ' +
'-w "/tmp/github/some/repo" ' +
'renovate/sidecar ' +
Expand Down
5 changes: 4 additions & 1 deletion lib/modules/manager/pip_requirements/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TEMPORARY_ERROR } from '../../../constants/error-messages';
import { logger } from '../../../logger';
import { exec } from '../../../util/exec';
import type { ExecOptions } from '../../../util/exec/types';
import { readLocalFile } from '../../../util/fs';
import { ensureCacheDir, readLocalFile } from '../../../util/fs';
import { newlineRegex, regEx } from '../../../util/regex';
import type { UpdateArtifact, UpdateArtifactsResult } from '../types';

Expand Down Expand Up @@ -48,6 +48,9 @@ export async function updateArtifacts({
toolConstraints: [
{ toolName: 'python', constraint: config.constraints?.python },
],
extraEnv: {
PIP_CACHE_DIR: await ensureCacheDir('pip'),
},
};
await exec(cmd, execOptions);
const newContent = await readLocalFile(packageFileName, 'utf8');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Array [
},
},
Object {
"cmd": "docker run --rm --name=renovate_sidecar --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/renovate/cache\\":\\"/tmp/renovate/cache\\" -e PIPENV_CACHE_DIR -e BUILDPACK_CACHE_DIR -w \\"/tmp/github/some/repo\\" renovate/sidecar bash -l -c \\"install-tool python 3.10.2 && pip install --user pipenv && pipenv lock\\"",
"cmd": "docker run --rm --name=renovate_sidecar --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/renovate/cache\\":\\"/tmp/renovate/cache\\" -e PIPENV_CACHE_DIR -e PIP_CACHE_DIR -e BUILDPACK_CACHE_DIR -w \\"/tmp/github/some/repo\\" renovate/sidecar bash -l -c \\"install-tool python 3.10.2 && pip install --user pipenv && pipenv lock\\"",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand All @@ -125,6 +125,7 @@ Array [
"NO_PROXY": "localhost",
"PATH": "/tmp/path",
"PIPENV_CACHE_DIR": "/tmp/renovate/cache/others/pipenv",
"PIP_CACHE_DIR": "/tmp/renovate/cache/others/pip",
},
"maxBuffer": 10485760,
"timeout": 900000,
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/manager/pipenv/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ describe('modules/manager/pipenv/artifacts', () => {
fs.ensureCacheDir.mockResolvedValueOnce(
'/tmp/renovate/cache/others/pipenv'
);
fs.ensureCacheDir.mockResolvedValueOnce('/tmp/renovate/cache/others/pip');
fs.readLocalFile.mockResolvedValueOnce(JSON.stringify(pipFileLock));
const execSnapshots = mockExecAll();
git.getRepoStatus.mockResolvedValue({
Expand All @@ -158,6 +159,7 @@ describe('modules/manager/pipenv/artifacts', () => {
fs.ensureCacheDir.mockResolvedValueOnce(
'/tmp/renovate/cache/others/pipenv'
);
fs.ensureCacheDir.mockResolvedValueOnce('/tmp/renovate/cache/others/pip');
fs.readLocalFile.mockResolvedValueOnce(JSON.stringify(pipFileLock));
const execSnapshots = mockExecAll();
git.getRepoStatus.mockResolvedValue({
Expand Down
1 change: 1 addition & 0 deletions lib/modules/manager/pipenv/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export async function updateArtifacts({
cwdFile: pipfileName,
extraEnv: {
PIPENV_CACHE_DIR: await ensureCacheDir('pipenv'),
PIP_CACHE_DIR: await ensureCacheDir('pip'),
},
docker: {
image: 'sidecar',
Expand Down
12 changes: 10 additions & 2 deletions lib/modules/manager/poetry/__snapshots__/artifacts.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Array [
"LC_ALL": "en_US",
"NO_PROXY": "localhost",
"PATH": "/tmp/path",
"PIP_CACHE_DIR": "/tmp/cache/others/pip",
"POETRY_HTTP_BASIC_FOUR_OH_FOUR_PASSWORD": "passwordFour",
"POETRY_HTTP_BASIC_ONE_PASSWORD": "passwordOne",
"POETRY_HTTP_BASIC_ONE_USERNAME": "usernameOne",
Expand Down Expand Up @@ -54,6 +55,7 @@ Array [
"LC_ALL": "en_US",
"NO_PROXY": "localhost",
"PATH": "/tmp/path",
"PIP_CACHE_DIR": "/tmp/cache/others/pip",
"POETRY_HTTP_BASIC_ONE_PASSWORD": "scoped-password",
},
"maxBuffer": 10485760,
Expand All @@ -78,6 +80,7 @@ Array [
"LC_ALL": "en_US",
"NO_PROXY": "localhost",
"PATH": "/tmp/path",
"PIP_CACHE_DIR": "/tmp/cache/others/pip",
},
"maxBuffer": 10485760,
"timeout": 900000,
Expand All @@ -101,6 +104,7 @@ Array [
"LC_ALL": "en_US",
"NO_PROXY": "localhost",
"PATH": "/tmp/path",
"PIP_CACHE_DIR": "/tmp/cache/others/pip",
},
"maxBuffer": 10485760,
"timeout": 900000,
Expand All @@ -124,7 +128,7 @@ Array [
},
},
Object {
"cmd": "docker run --rm --name=renovate_sidecar --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/cache\\":\\"/tmp/cache\\" -e BUILDPACK_CACHE_DIR -w \\"/tmp/github/some/repo\\" renovate/sidecar bash -l -c \\"install-tool python 1.2.0 && pip install --user 'poetry>=1.0' && poetry update --lock --no-interaction dep1\\"",
"cmd": "docker run --rm --name=renovate_sidecar --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/cache\\":\\"/tmp/cache\\" -e PIP_CACHE_DIR -e BUILDPACK_CACHE_DIR -w \\"/tmp/github/some/repo\\" renovate/sidecar bash -l -c \\"install-tool python 1.2.0 && pip install --user 'poetry>=1.0' && poetry update --lock --no-interaction dep1\\"",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand All @@ -137,6 +141,7 @@ Array [
"LC_ALL": "en_US",
"NO_PROXY": "localhost",
"PATH": "/tmp/path",
"PIP_CACHE_DIR": "/tmp/cache/others/pip",
},
"maxBuffer": 10485760,
"timeout": 900000,
Expand All @@ -160,7 +165,7 @@ Array [
},
},
Object {
"cmd": "docker run --rm --name=renovate_sidecar --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/cache\\":\\"/tmp/cache\\" -e BUILDPACK_CACHE_DIR -w \\"/tmp/github/some/repo\\" renovate/sidecar bash -l -c \\"install-tool python 1.2.0 && pip install --user 'poetry>=1.0' && poetry update --lock --no-interaction dep1\\"",
"cmd": "docker run --rm --name=renovate_sidecar --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/cache\\":\\"/tmp/cache\\" -e PIP_CACHE_DIR -e BUILDPACK_CACHE_DIR -w \\"/tmp/github/some/repo\\" renovate/sidecar bash -l -c \\"install-tool python 1.2.0 && pip install --user 'poetry>=1.0' && poetry update --lock --no-interaction dep1\\"",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand All @@ -173,6 +178,7 @@ Array [
"LC_ALL": "en_US",
"NO_PROXY": "localhost",
"PATH": "/tmp/path",
"PIP_CACHE_DIR": "/tmp/cache/others/pip",
},
"maxBuffer": 10485760,
"timeout": 900000,
Expand All @@ -196,6 +202,7 @@ Array [
"LC_ALL": "en_US",
"NO_PROXY": "localhost",
"PATH": "/tmp/path",
"PIP_CACHE_DIR": "/tmp/cache/others/pip",
},
"maxBuffer": 10485760,
"timeout": 900000,
Expand All @@ -219,6 +226,7 @@ Array [
"LC_ALL": "en_US",
"NO_PROXY": "localhost",
"PATH": "/tmp/path",
"PIP_CACHE_DIR": "/tmp/cache/others/pip",
},
"maxBuffer": 10485760,
"timeout": 900000,
Expand Down
9 changes: 5 additions & 4 deletions lib/modules/manager/poetry/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { exec } from '../../../util/exec';
import type { ExecOptions } from '../../../util/exec/types';
import {
deleteLocalFile,
ensureCacheDir,
getSiblingFileName,
readLocalFile,
writeLocalFile,
Expand Down Expand Up @@ -175,10 +176,10 @@ export async function updateArtifacts({
const constraint = getPythonConstraint(existingLockFileContent, config);
const poetryVersion =
config.constraints?.poetry ?? getPoetryRequirement(newPackageFileContent);
const extraEnv = getSourceCredentialVars(
newPackageFileContent,
packageFileName
);
const extraEnv = {
...getSourceCredentialVars(newPackageFileContent, packageFileName),
PIP_CACHE_DIR: await ensureCacheDir('pip'),
};

const execOptions: ExecOptions = {
cwdFile: packageFileName,
Expand Down