diff --git a/lib/modules/manager/pip-compile/__snapshots__/artifacts.spec.ts.snap b/lib/modules/manager/pip-compile/__snapshots__/artifacts.spec.ts.snap index 9bd760cce96e1b1bd028d46da74717e71da1d5de..5dc20e1ff92d4592540d3779482f0ebb188cae49 100644 --- a/lib/modules/manager/pip-compile/__snapshots__/artifacts.spec.ts.snap +++ b/lib/modules/manager/pip-compile/__snapshots__/artifacts.spec.ts.snap @@ -68,75 +68,3 @@ Array [ }, ] `; - -exports[`modules/manager/pip-compile/artifacts supports docker mode 1`] = ` -Array [ - Object { - "cmd": "docker pull renovate/python", - "options": Object { - "encoding": "utf-8", - }, - }, - Object { - "cmd": "docker ps --filter name=renovate_python -aq", - "options": Object { - "encoding": "utf-8", - }, - }, - Object { - "cmd": "docker run --rm --name=renovate_python --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/renovate/cache\\":\\"/tmp/renovate/cache\\" -e BUILDPACK_CACHE_DIR -w \\"/tmp/github/some/repo\\" renovate/python bash -l -c \\"pip install --user pip-tools && pip-compile requirements.in\\"", - "options": Object { - "cwd": "/tmp/github/some/repo", - "encoding": "utf-8", - "env": Object { - "BUILDPACK_CACHE_DIR": "/tmp/renovate/cache/buildpack", - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - }, - "maxBuffer": 10485760, - "timeout": 900000, - }, - }, -] -`; - -exports[`modules/manager/pip-compile/artifacts uses pipenv version from config 1`] = ` -Array [ - Object { - "cmd": "docker pull renovate/python", - "options": Object { - "encoding": "utf-8", - }, - }, - Object { - "cmd": "docker ps --filter name=renovate_python -aq", - "options": Object { - "encoding": "utf-8", - }, - }, - Object { - "cmd": "docker run --rm --name=renovate_python --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/renovate/cache\\":\\"/tmp/renovate/cache\\" -e BUILDPACK_CACHE_DIR -w \\"/tmp/github/some/repo\\" renovate/python bash -l -c \\"pip install --user pip-tools1.2.3 && pip-compile requirements.in\\"", - "options": Object { - "cwd": "/tmp/github/some/repo", - "encoding": "utf-8", - "env": Object { - "BUILDPACK_CACHE_DIR": "/tmp/renovate/cache/buildpack", - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - }, - "maxBuffer": 10485760, - "timeout": 900000, - }, - }, -] -`; diff --git a/lib/modules/manager/pip-compile/artifacts.spec.ts b/lib/modules/manager/pip-compile/artifacts.spec.ts index 21a6992dde224d62b5b897397c591a0a91fa7059..44614d2d0d637f322b2062daadcff7c7c26f7d38 100644 --- a/lib/modules/manager/pip-compile/artifacts.spec.ts +++ b/lib/modules/manager/pip-compile/artifacts.spec.ts @@ -27,6 +27,8 @@ const adminConfig: RepoGlobalConfig = { }; const dockerAdminConfig = { ...adminConfig, binarySource: 'docker' }; +process.env.BUILDPACK = 'true'; + const config: UpdateArtifactsConfig = {}; const lockMaintenanceConfig = { ...config, isLockFileMaintenance: true }; @@ -56,7 +58,7 @@ describe('modules/manager/pip-compile/artifacts', () => { it('returns null if unchanged', async () => { fs.readFile.mockResolvedValueOnce('content' as any); const execSnapshots = mockExecAll(); - fs.readFile.mockReturnValueOnce('content' as any); + fs.readFile.mockResolvedValueOnce('content' as any); expect( await updateArtifacts({ packageFileName: 'requirements.in', @@ -74,7 +76,7 @@ describe('modules/manager/pip-compile/artifacts', () => { git.getRepoStatus.mockResolvedValue({ modified: ['requirements.txt'], } as StatusResult); - fs.readFile.mockReturnValueOnce('New requirements.txt' as any); + fs.readFile.mockResolvedValueOnce('New requirements.txt' as any); expect( await updateArtifacts({ packageFileName: 'requirements.in', @@ -92,16 +94,62 @@ describe('modules/manager/pip-compile/artifacts', () => { git.getRepoStatus.mockResolvedValue({ modified: ['requirements.txt'], } as StatusResult); - fs.readFile.mockReturnValueOnce('new lock' as any); + fs.readFile.mockResolvedValueOnce('new lock' as any); expect( await updateArtifacts({ packageFileName: 'requirements.in', updatedDeps: [], newPackageFileContent: 'some new content', - config, + config: { ...config, constraints: { python: '3.10.2' } }, }) ).not.toBeNull(); - expect(execSnapshots).toMatchSnapshot(); + + expect(execSnapshots).toMatchObject([ + { cmd: 'docker pull renovate/sidecar' }, + { cmd: 'docker ps --filter name=renovate_sidecar -aq' }, + { + 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 BUILDPACK_CACHE_DIR ' + + '-w "/tmp/github/some/repo" ' + + 'renovate/sidecar ' + + 'bash -l -c "' + + 'install-tool python 3.10.2 ' + + '&& ' + + 'pip install --user pip-tools ' + + '&& ' + + 'pip-compile requirements.in' + + '"', + }, + ]); + }); + + it('supports iunstall mode', async () => { + GlobalConfig.set({ ...adminConfig, binarySource: 'install' }); + const execSnapshots = mockExecAll(); + git.getRepoStatus.mockResolvedValue({ + modified: ['requirements.txt'], + } as StatusResult); + fs.readFile.mockResolvedValueOnce('new lock' as any); + expect( + await updateArtifacts({ + packageFileName: 'requirements.in', + updatedDeps: [], + newPackageFileContent: 'some new content', + config: { ...config, constraints: { python: '3.10.2' } }, + }) + ).not.toBeNull(); + + expect(execSnapshots).toMatchObject([ + { cmd: 'install-tool python 3.10.2' }, + { cmd: 'pip install --user pip-tools' }, + { + cmd: 'pip-compile requirements.in', + options: { cwd: '/tmp/github/some/repo' }, + }, + ]); }); it('catches errors', async () => { @@ -147,16 +195,39 @@ describe('modules/manager/pip-compile/artifacts', () => { git.getRepoStatus.mockResolvedValue({ modified: ['requirements.txt'], } as StatusResult); - fs.readFile.mockReturnValueOnce('new lock' as any); + fs.readFile.mockResolvedValueOnce('new lock' as any); expect( await updateArtifacts({ packageFileName: 'requirements.in', updatedDeps: [], newPackageFileContent: 'some new content', - config: { ...config, constraints: { pipTools: '1.2.3' } }, + config: { + ...config, + constraints: { python: '3.10.2', pipTools: '==1.2.3' }, + }, }) ).not.toBeNull(); - expect(execSnapshots).toMatchSnapshot(); + + expect(execSnapshots).toMatchObject([ + { cmd: 'docker pull renovate/sidecar' }, + { cmd: 'docker ps --filter name=renovate_sidecar -aq' }, + { + 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 BUILDPACK_CACHE_DIR ' + + '-w "/tmp/github/some/repo" ' + + 'renovate/sidecar ' + + 'bash -l -c "' + + 'install-tool python 3.10.2 ' + + '&& ' + + 'pip install --user pip-tools==1.2.3 ' + + '&& ' + + 'pip-compile requirements.in' + + '"', + }, + ]); }); describe('constructPipCompileCmd()', () => { diff --git a/lib/modules/manager/pip-compile/artifacts.ts b/lib/modules/manager/pip-compile/artifacts.ts index 9eb6843a199804e9e03a829df93c89020be69926..34b92468958e6b8547cf87349c5be69a38bb04ff 100644 --- a/lib/modules/manager/pip-compile/artifacts.ts +++ b/lib/modules/manager/pip-compile/artifacts.ts @@ -114,18 +114,22 @@ export async function updateArtifacts({ inputFileName, outputFileName ); - const tagConstraint = getPythonConstraint(config); + const constraint = getPythonConstraint(config); const pipToolsConstraint = getPipToolsConstraint(config); const execOptions: ExecOptions = { cwdFile: inputFileName, docker: { - image: 'python', - tagConstraint, - tagScheme: 'pep440', + image: 'sidecar', }, preCommands: [ `pip install --user ${quote(`pip-tools${pipToolsConstraint}`)}`, ], + toolConstraints: [ + { + toolName: 'python', + constraint, + }, + ], }; logger.debug({ cmd }, 'pip-compile command'); await exec(cmd, execOptions);