diff --git a/lib/config/admin.ts b/lib/config/admin.ts index 73f289d209476153391e823c43c0949ff961fc8a..83eb5bdfcae1060afdbb0caea55582a0aa0bf8de 100644 --- a/lib/config/admin.ts +++ b/lib/config/admin.ts @@ -8,6 +8,7 @@ const repoAdminOptions = [ 'allowPostUpgradeCommandTemplating', 'allowScripts', 'allowedPostUpgradeCommands', + 'binarySource', 'customEnvVariables', 'dockerChildPrefix', 'dockerImagePrefix', diff --git a/lib/config/types.ts b/lib/config/types.ts index bd56a58505b444e53877110a431d7ec6c3b32ca4..8109381fb2ab5fb0d210eba26e9025b20d411631 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -90,6 +90,7 @@ export interface RepoAdminConfig { allowPostUpgradeCommandTemplating?: boolean; allowScripts?: boolean; allowedPostUpgradeCommands?: string[]; + binarySource?: 'docker' | 'global'; customEnvVariables?: Record<string, string>; dockerChildPrefix?: string; dockerImagePrefix?: string; diff --git a/lib/manager/bundler/artifacts.spec.ts b/lib/manager/bundler/artifacts.spec.ts index 05cf2d6ca7c56e4ecb50ee278e91d839f59e3afe..f9abf89ec00784f62831501489c79c4146c6d846 100644 --- a/lib/manager/bundler/artifacts.spec.ts +++ b/lib/manager/bundler/artifacts.spec.ts @@ -5,8 +5,6 @@ import { fs, git, mocked } from '../../../test/util'; import { setAdminConfig } from '../../config/admin'; import type { RepoAdminConfig } from '../../config/types'; import * as _datasource from '../../datasource'; -import { setExecConfig } from '../../util/exec'; -import { BinarySource } from '../../util/exec/common'; import * as docker from '../../util/exec/docker'; import * as _env from '../../util/exec/env'; import type { StatusResult } from '../../util/git'; @@ -37,7 +35,7 @@ const adminConfig: RepoAdminConfig = { const config: UpdateArtifactsConfig = {}; describe('bundler.updateArtifacts()', () => { - beforeEach(async () => { + beforeEach(() => { jest.resetAllMocks(); jest.resetModules(); @@ -47,7 +45,6 @@ describe('bundler.updateArtifacts()', () => { bundlerHostRules.findAllAuthenticatable.mockReturnValue([]); docker.resetPrefetchedImages(); - await setExecConfig(adminConfig as never); setAdminConfig(adminConfig); }); afterEach(() => { @@ -101,6 +98,7 @@ describe('bundler.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('works explicit global binarySource', async () => { + setAdminConfig({ ...adminConfig, binarySource: 'global' }); fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); fs.writeLocalFile.mockResolvedValueOnce(null as never); fs.readLocalFile.mockResolvedValueOnce(null); @@ -114,20 +112,16 @@ describe('bundler.updateArtifacts()', () => { packageFileName: 'Gemfile', updatedDeps: ['foo', 'bar'], newPackageFileContent: 'Updated Gemfile content', - config: { - ...config, - binarySource: BinarySource.Global, - }, + config, }) ).toMatchSnapshot(); expect(execSnapshots).toMatchSnapshot(); }); describe('Docker', () => { - beforeEach(async () => { - jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); - await setExecConfig({ + beforeEach(() => { + setAdminConfig({ ...adminConfig, - binarySource: BinarySource.Docker, + binarySource: 'docker', }); }); it('.ruby-version', async () => { @@ -151,15 +145,13 @@ describe('bundler.updateArtifacts()', () => { packageFileName: 'Gemfile', updatedDeps: ['foo', 'bar'], newPackageFileContent: 'Updated Gemfile content', - config: { - ...config, - binarySource: BinarySource.Docker, - }, + config, }) ).toMatchSnapshot(); expect(execSnapshots).toMatchSnapshot(); }); it('constraints options', async () => { + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); fs.writeLocalFile.mockResolvedValueOnce(null as never); datasource.getPkgReleases.mockResolvedValueOnce({ @@ -181,7 +173,6 @@ describe('bundler.updateArtifacts()', () => { newPackageFileContent: 'Updated Gemfile content', config: { ...config, - binarySource: BinarySource.Docker, constraints: { ruby: '1.2.5', bundler: '3.2.1', @@ -192,6 +183,7 @@ describe('bundler.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('invalid constraints options', async () => { + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); fs.writeLocalFile.mockResolvedValueOnce(null as never); datasource.getPkgReleases.mockResolvedValueOnce({ @@ -213,7 +205,6 @@ describe('bundler.updateArtifacts()', () => { newPackageFileContent: 'Updated Gemfile content', config: { ...config, - binarySource: BinarySource.Docker, constraints: { ruby: 'foo', bundler: 'bar', @@ -225,6 +216,7 @@ describe('bundler.updateArtifacts()', () => { }); it('injects bundler host configuration environment variables', async () => { + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); fs.writeLocalFile.mockResolvedValueOnce(null as never); fs.readLocalFile.mockResolvedValueOnce('1.2.0'); @@ -257,16 +249,14 @@ describe('bundler.updateArtifacts()', () => { packageFileName: 'Gemfile', updatedDeps: ['foo', 'bar'], newPackageFileContent: 'Updated Gemfile content', - config: { - ...config, - binarySource: BinarySource.Docker, - }, + config, }) ).toMatchSnapshot(); expect(execSnapshots).toMatchSnapshot(); }); it('injects bundler host configuration as command with bundler < 2', async () => { + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); fs.writeLocalFile.mockResolvedValueOnce(null as never); fs.readLocalFile.mockResolvedValueOnce('1.2.0'); @@ -301,7 +291,6 @@ describe('bundler.updateArtifacts()', () => { newPackageFileContent: 'Updated Gemfile content', config: { ...config, - binarySource: BinarySource.Docker, constraints: { bundler: '1.2', }, @@ -312,6 +301,7 @@ describe('bundler.updateArtifacts()', () => { }); it('injects bundler host configuration as command with bundler >= 2', async () => { + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); fs.writeLocalFile.mockResolvedValueOnce(null as never); fs.readLocalFile.mockResolvedValueOnce('1.2.0'); @@ -346,7 +336,6 @@ describe('bundler.updateArtifacts()', () => { newPackageFileContent: 'Updated Gemfile content', config: { ...config, - binarySource: BinarySource.Docker, constraints: { bundler: '2.1', }, @@ -357,6 +346,7 @@ describe('bundler.updateArtifacts()', () => { }); it('injects bundler host configuration as command with bundler == latest', async () => { + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); fs.writeLocalFile.mockResolvedValueOnce(null as never); fs.readLocalFile.mockResolvedValueOnce('1.2.0'); @@ -389,10 +379,7 @@ describe('bundler.updateArtifacts()', () => { packageFileName: 'Gemfile', updatedDeps: ['foo', 'bar'], newPackageFileContent: 'Updated Gemfile content', - config: { - ...config, - binarySource: BinarySource.Docker, - }, + config, }) ).toMatchSnapshot(); expect(execSnapshots).toMatchSnapshot(); diff --git a/lib/manager/cargo/artifacts.spec.ts b/lib/manager/cargo/artifacts.spec.ts index a2c8bf0fc32388ee90fff1ccae7296ab1debed99..829f3be4b6cc3205994e3414136d93131648000f 100644 --- a/lib/manager/cargo/artifacts.spec.ts +++ b/lib/manager/cargo/artifacts.spec.ts @@ -5,8 +5,6 @@ import { envMock, mockExecAll } from '../../../test/exec-util'; import { git, mocked } from '../../../test/util'; import { setAdminConfig } from '../../config/admin'; import type { RepoAdminConfig } from '../../config/types'; -import { setExecConfig } from '../../util/exec'; -import { BinarySource } from '../../util/exec/common'; import * as docker from '../../util/exec/docker'; import * as _env from '../../util/exec/env'; import type { UpdateArtifactsConfig } from '../types'; @@ -30,12 +28,11 @@ const adminConfig: RepoAdminConfig = { }; describe('.updateArtifacts()', () => { - beforeEach(async () => { + beforeEach(() => { jest.resetAllMocks(); jest.resetModules(); env.getChildProcessEnv.mockReturnValue(envMock.basic); - await setExecConfig(adminConfig as never); setAdminConfig(adminConfig); docker.resetPrefetchedImages(); }); @@ -136,8 +133,7 @@ describe('.updateArtifacts()', () => { it('returns updated Cargo.lock with docker', async () => { fs.stat.mockResolvedValueOnce({ name: 'Cargo.lock' } as any); - jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); - await setExecConfig({ ...adminConfig, binarySource: BinarySource.Docker }); + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); git.getFile.mockResolvedValueOnce('Old Cargo.lock'); const execSnapshots = mockExecAll(exec); fs.readFile.mockResolvedValueOnce('New Cargo.lock' as any); diff --git a/lib/manager/cocoapods/__snapshots__/artifacts.spec.ts.snap b/lib/manager/cocoapods/__snapshots__/artifacts.spec.ts.snap index a0579ac4f55f2529892ddb4c3eb235637f865e9d..af1a2350d6120b19f3e2fb940704a7ca0141d624 100644 --- a/lib/manager/cocoapods/__snapshots__/artifacts.spec.ts.snap +++ b/lib/manager/cocoapods/__snapshots__/artifacts.spec.ts.snap @@ -15,12 +15,6 @@ exports[`.updateArtifacts() catches write error 2`] = `Array []`; exports[`.updateArtifacts() dynamically selects Docker image tag 1`] = ` Array [ - Object { - "cmd": "docker ps --filter label=renovate_child -aq", - "options": Object { - "encoding": "utf-8", - }, - }, Object { "cmd": "docker pull renovate/cocoapods:1.2.4", "options": Object { @@ -57,12 +51,6 @@ Array [ exports[`.updateArtifacts() falls back to the \`latest\` Docker image tag 1`] = ` Array [ - Object { - "cmd": "docker ps --filter label=renovate_child -aq", - "options": Object { - "encoding": "utf-8", - }, - }, Object { "cmd": "docker pull renovate/cocoapods:latest", "options": Object { @@ -177,12 +165,6 @@ Array [ exports[`.updateArtifacts() returns updated Podfile 2`] = ` Array [ - Object { - "cmd": "docker ps --filter label=renovate_child -aq", - "options": Object { - "encoding": "utf-8", - }, - }, Object { "cmd": "docker pull renovate/cocoapods", "options": Object { @@ -248,12 +230,6 @@ Array [ exports[`.updateArtifacts() returns updated Podfile and Pods files 2`] = ` Array [ - Object { - "cmd": "docker ps --filter label=renovate_child -aq", - "options": Object { - "encoding": "utf-8", - }, - }, Object { "cmd": "docker ps --filter name=renovate_cocoapods -aq", "options": Object { diff --git a/lib/manager/cocoapods/artifacts.spec.ts b/lib/manager/cocoapods/artifacts.spec.ts index 2944f67e22553af8fe0c5ac5d6b8ad26c10cf239..b3e4fc6d0fe55a5977b6df037003c95afc94608f 100644 --- a/lib/manager/cocoapods/artifacts.spec.ts +++ b/lib/manager/cocoapods/artifacts.spec.ts @@ -6,8 +6,6 @@ import { git, mocked } from '../../../test/util'; import { setAdminConfig } from '../../config/admin'; import type { RepoAdminConfig } from '../../config/types'; import * as _datasource from '../../datasource'; -import { setExecConfig } from '../../util/exec'; -import { BinarySource } from '../../util/exec/common'; import * as _env from '../../util/exec/env'; import type { StatusResult } from '../../util/git'; import type { UpdateArtifactsConfig } from '../types'; @@ -35,11 +33,10 @@ const adminConfig: RepoAdminConfig = { }; describe('.updateArtifacts()', () => { - beforeEach(async () => { + beforeEach(() => { jest.resetAllMocks(); env.getChildProcessEnv.mockReturnValue(envMock.basic); - await setExecConfig(adminConfig as never); setAdminConfig(adminConfig); datasource.getPkgReleases.mockResolvedValue({ @@ -127,7 +124,7 @@ describe('.updateArtifacts()', () => { }); it('returns updated Podfile', async () => { const execSnapshots = mockExecAll(exec); - await setExecConfig({ ...adminConfig, binarySource: BinarySource.Docker }); + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); fs.readFile.mockResolvedValueOnce('Old Podfile' as any); git.getRepoStatus.mockResolvedValueOnce({ modified: ['Podfile.lock'], @@ -145,7 +142,7 @@ describe('.updateArtifacts()', () => { }); it('returns updated Podfile and Pods files', async () => { const execSnapshots = mockExecAll(exec); - await setExecConfig({ ...adminConfig, binarySource: BinarySource.Docker }); + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); fs.readFile.mockResolvedValueOnce('Old Manifest.lock' as any); fs.readFile.mockResolvedValueOnce('New Podfile' as any); fs.readFile.mockResolvedValueOnce('Pods manifest' as any); @@ -198,7 +195,7 @@ describe('.updateArtifacts()', () => { it('dynamically selects Docker image tag', async () => { const execSnapshots = mockExecAll(exec); - await setExecConfig({ ...adminConfig, binarySource: BinarySource.Docker }); + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); fs.readFile.mockResolvedValueOnce('COCOAPODS: 1.2.4' as any); @@ -219,7 +216,7 @@ describe('.updateArtifacts()', () => { it('falls back to the `latest` Docker image tag', async () => { const execSnapshots = mockExecAll(exec); - await setExecConfig({ ...adminConfig, binarySource: BinarySource.Docker }); + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); fs.readFile.mockResolvedValueOnce('COCOAPODS: 1.2.4' as any); datasource.getPkgReleases.mockResolvedValueOnce({ diff --git a/lib/manager/composer/artifacts.spec.ts b/lib/manager/composer/artifacts.spec.ts index 23218407a9d28f8e5f4da269697319ef68644191..07f21e9dfa58d6611bf7d40bf4834cf732dbb07b 100644 --- a/lib/manager/composer/artifacts.spec.ts +++ b/lib/manager/composer/artifacts.spec.ts @@ -10,8 +10,6 @@ import { } from '../../constants/platforms'; import * as _datasource from '../../datasource'; import * as datasourcePackagist from '../../datasource/packagist'; -import { setExecConfig } from '../../util/exec'; -import { BinarySource } from '../../util/exec/common'; import * as docker from '../../util/exec/docker'; import type { StatusResult } from '../../util/git'; import * as hostRules from '../../util/host-rules'; @@ -46,11 +44,10 @@ const repoStatus = partial<StatusResult>({ }); describe('.updateArtifacts()', () => { - beforeEach(async () => { + beforeEach(() => { jest.resetAllMocks(); jest.resetModules(); env.getChildProcessEnv.mockReturnValue(envMock.basic); - await setExecConfig(adminConfig as never); docker.resetPrefetchedImages(); hostRules.clear(); setAdminConfig(adminConfig); @@ -202,8 +199,7 @@ describe('.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('supports docker mode', async () => { - jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); - await setExecConfig({ ...adminConfig, binarySource: BinarySource.Docker }); + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); fs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); const execSnapshots = mockExecAll(exec); @@ -234,6 +230,7 @@ describe('.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('supports global mode', async () => { + setAdminConfig({ ...adminConfig, binarySource: 'global' }); fs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); const execSnapshots = mockExecAll(exec); fs.readLocalFile.mockReturnValueOnce('New composer.lock' as any); @@ -246,10 +243,7 @@ describe('.updateArtifacts()', () => { packageFileName: 'composer.json', updatedDeps: [], newPackageFileContent: '{}', - config: { - ...config, - binarySource: BinarySource.Global, - }, + config, }) ).not.toBeNull(); expect(execSnapshots).toMatchSnapshot(); diff --git a/lib/manager/gomod/artifacts.spec.ts b/lib/manager/gomod/artifacts.spec.ts index 0d5f5db94803288170c46f37189b90102e721ee9..49033cba6c9d1ade2162b777a942ffaea2cc972e 100644 --- a/lib/manager/gomod/artifacts.spec.ts +++ b/lib/manager/gomod/artifacts.spec.ts @@ -5,8 +5,6 @@ import { envMock, mockExecAll } from '../../../test/exec-util'; import { git, mocked } from '../../../test/util'; import { setAdminConfig } from '../../config/admin'; import type { RepoAdminConfig } from '../../config/types'; -import { setExecConfig } from '../../util/exec'; -import { BinarySource } from '../../util/exec/common'; import * as docker from '../../util/exec/docker'; import * as _env from '../../util/exec/env'; import type { StatusResult } from '../../util/git'; @@ -57,13 +55,12 @@ const goEnv = { }; describe('.updateArtifacts()', () => { - beforeEach(async () => { + beforeEach(() => { jest.resetAllMocks(); jest.resetModules(); delete process.env.GOPATH; env.getChildProcessEnv.mockReturnValue({ ...envMock.basic, ...goEnv }); - await setExecConfig(adminConfig as never); setAdminConfig(adminConfig); docker.resetPrefetchedImages(); }); @@ -154,8 +151,7 @@ describe('.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('supports docker mode without credentials', async () => { - jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); - await setExecConfig({ ...adminConfig, binarySource: BinarySource.Docker }); + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); fs.readFile.mockResolvedValueOnce('Current go.sum' as any); fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename const execSnapshots = mockExecAll(exec); @@ -168,15 +164,13 @@ describe('.updateArtifacts()', () => { packageFileName: 'go.mod', updatedDeps: [], newPackageFileContent: gomod1, - config: { - ...config, - binarySource: BinarySource.Docker, - }, + config, }) ).not.toBeNull(); expect(execSnapshots).toMatchSnapshot(); }); it('supports global mode', async () => { + setAdminConfig({ ...adminConfig, binarySource: 'global' }); fs.readFile.mockResolvedValueOnce('Current go.sum' as any); fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename const execSnapshots = mockExecAll(exec); @@ -189,17 +183,13 @@ describe('.updateArtifacts()', () => { packageFileName: 'go.mod', updatedDeps: [], newPackageFileContent: gomod1, - config: { - ...config, - binarySource: BinarySource.Global, - }, + config, }) ).not.toBeNull(); expect(execSnapshots).toMatchSnapshot(); }); it('supports docker mode with credentials', async () => { - jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); - await setExecConfig({ ...adminConfig, binarySource: BinarySource.Docker }); + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); hostRules.find.mockReturnValueOnce({ token: 'some-token', }); @@ -215,17 +205,13 @@ describe('.updateArtifacts()', () => { packageFileName: 'go.mod', updatedDeps: [], newPackageFileContent: gomod1, - config: { - ...config, - binarySource: BinarySource.Docker, - }, + config, }) ).not.toBeNull(); expect(execSnapshots).toMatchSnapshot(); }); it('supports docker mode with goModTidy', async () => { - jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); - await setExecConfig({ ...adminConfig, binarySource: BinarySource.Docker }); + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); hostRules.find.mockReturnValueOnce({}); fs.readFile.mockResolvedValueOnce('Current go.sum' as any); fs.readFile.mockResolvedValueOnce(null as any); // vendor modules filename @@ -244,7 +230,6 @@ describe('.updateArtifacts()', () => { newPackageFileContent: gomod1, config: { ...config, - binarySource: BinarySource.Docker, postUpdateOptions: ['gomodTidy'], }, }) diff --git a/lib/manager/gomod/artifacts.ts b/lib/manager/gomod/artifacts.ts index 435d6a7b8ed1ebb153d3fce73c1f14c7d0937367..d76968ddf60293c501e9c3d544c5aead6d96a14e 100644 --- a/lib/manager/gomod/artifacts.ts +++ b/lib/manager/gomod/artifacts.ts @@ -1,11 +1,11 @@ import is from '@sindresorhus/is'; import { quote } from 'shlex'; import { dirname, join } from 'upath'; +import { getAdminConfig } from '../../config/admin'; import { TEMPORARY_ERROR } from '../../constants/error-messages'; import { PLATFORM_TYPE_GITHUB } from '../../constants/platforms'; import { logger } from '../../logger'; import { ExecOptions, exec } from '../../util/exec'; -import { BinarySource } from '../../util/exec/common'; import { ensureCacheDir, readLocalFile, writeLocalFile } from '../../util/fs'; import { getRepoStatus } from '../../util/git'; import { find } from '../../util/host-rules'; @@ -126,7 +126,7 @@ export async function updateArtifacts({ GONOPROXY: process.env.GONOPROXY, GONOSUMDB: process.env.GONOSUMDB, GOFLAGS: useModcacherw(config.constraints?.go) ? '-modcacherw' : null, - CGO_ENABLED: config.binarySource === BinarySource.Docker ? '0' : null, + CGO_ENABLED: getAdminConfig().binarySource === 'docker' ? '0' : null, }, docker: { image: 'go', diff --git a/lib/manager/gradle-wrapper/artifacts-real.spec.ts b/lib/manager/gradle-wrapper/artifacts-real.spec.ts index 181a33286987ef9f5357906d97c9e47cbdcfb0fc..0a4d365a8c2909973742a97aebc5a80c95d75e75 100644 --- a/lib/manager/gradle-wrapper/artifacts-real.spec.ts +++ b/lib/manager/gradle-wrapper/artifacts-real.spec.ts @@ -5,7 +5,6 @@ import * as httpMock from '../../../test/http-mock'; import { getName, git, partial } from '../../../test/util'; import { setAdminConfig } from '../../config/admin'; import type { RepoAdminConfig } from '../../config/types'; -import { setExecConfig } from '../../util/exec'; import type { StatusResult } from '../../util/git'; import { ifSystemSupportsGradle } from '../gradle/__testutil__/gradle'; import type { UpdateArtifactsConfig } from '../types'; @@ -41,9 +40,8 @@ describe(getName(), () => { ifSystemSupportsGradle(6).describe('real tests', () => { jest.setTimeout(60 * 1000); - beforeEach(async () => { + beforeEach(() => { jest.resetAllMocks(); - await setExecConfig(adminConfig as never); setAdminConfig(adminConfig); }); @@ -170,7 +168,6 @@ describe(getName(), () => { localDir: resolve(fixtures, './wrongCmd'), }; - await setExecConfig(wrongCmdConfig); setAdminConfig(wrongCmdConfig); const res = await dcUpdate.updateArtifacts({ packageFileName: 'gradle/wrapper/gradle-wrapper.properties', diff --git a/lib/manager/gradle-wrapper/artifacts.spec.ts b/lib/manager/gradle-wrapper/artifacts.spec.ts index ba06ec203e424dd127865c70b2f40a1b669cd3f2..83a82e654706d32d8520b92038000ce09bb5eee4 100644 --- a/lib/manager/gradle-wrapper/artifacts.spec.ts +++ b/lib/manager/gradle-wrapper/artifacts.spec.ts @@ -14,8 +14,6 @@ import { } from '../../../test/util'; import { setAdminConfig } from '../../config/admin'; import type { RepoAdminConfig } from '../../config/types'; -import { setExecConfig } from '../../util/exec'; -import { BinarySource } from '../../util/exec/common'; import { resetPrefetchedImages } from '../../util/exec/docker'; import type { StatusResult } from '../../util/git'; import type { UpdateArtifactsConfig } from '../types'; @@ -33,7 +31,7 @@ const adminConfig: RepoAdminConfig = { localDir: resolve(fixtures, './testFiles'), }; -const dockerAdminConfig = { ...adminConfig, binarySource: BinarySource.Docker }; +const dockerAdminConfig = { ...adminConfig, binarySource: 'docker' }; const config: UpdateArtifactsConfig = { newValue: '5.6.4', @@ -47,7 +45,7 @@ function readString(...paths: string[]): Promise<string> { } describe(getName(), () => { - beforeEach(async () => { + beforeEach(() => { jest.resetAllMocks(); env.getChildProcessEnv.mockReturnValue({ @@ -56,7 +54,6 @@ describe(getName(), () => { LC_ALL: 'en_US', }); - await setExecConfig(adminConfig as never); setAdminConfig(adminConfig); resetPrefetchedImages(); diff --git a/lib/manager/gradle/index.spec.ts b/lib/manager/gradle/index.spec.ts index 7171b2ac817aa2b474bda45f4d1857d32f1deb50..7dbaecfdf7bcdf95f3a477984670b3ab7c6a741c 100644 --- a/lib/manager/gradle/index.spec.ts +++ b/lib/manager/gradle/index.spec.ts @@ -12,8 +12,6 @@ import { } from '../../../test/util'; import { setAdminConfig } from '../../config/admin'; import type { RepoAdminConfig } from '../../config/types'; -import { setExecConfig } from '../../util/exec'; -import { BinarySource } from '../../util/exec/common'; import * as docker from '../../util/exec/docker'; import * as _env from '../../util/exec/env'; import type { ExtractConfig } from '../types'; @@ -34,7 +32,7 @@ const adminConfig: RepoAdminConfig = { const dockerAdminConfig = { ...adminConfig, - binarySource: BinarySource.Docker, + binarySource: 'docker', }; const gradleOutput = { @@ -88,8 +86,7 @@ describe(getName(), () => { return mockExecAll(exec, output); } - beforeAll(async () => { - await setExecConfig(adminConfig as never); + beforeAll(() => { setAdminConfig(adminConfig); }); @@ -215,8 +212,7 @@ describe(getName(), () => { }); it('should use docker if required', async () => { - jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); - await setExecConfig(dockerAdminConfig); + setAdminConfig(dockerAdminConfig); const execSnapshots = setupMocks({ wrapperFilename: null }); const dependencies = await extractAllPackageFiles(config, [ 'build.gradle', @@ -226,8 +222,7 @@ describe(getName(), () => { }); it('should use docker even if gradlew is available', async () => { - jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); - await setExecConfig(dockerAdminConfig); + setAdminConfig(dockerAdminConfig); const execSnapshots = setupMocks(); const dependencies = await extractAllPackageFiles(config, [ 'build.gradle', @@ -237,8 +232,7 @@ describe(getName(), () => { }); it('should use docker even if gradlew.bat is available on Windows', async () => { - jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); - await setExecConfig(dockerAdminConfig); + setAdminConfig(dockerAdminConfig); jest.spyOn(os, 'platform').mockReturnValueOnce('win32'); const execSnapshots = setupMocks({ wrapperFilename: 'gradlew.bat' }); const dependencies = await extractAllPackageFiles(config, [ diff --git a/lib/manager/gradle/utils.ts b/lib/manager/gradle/utils.ts index c648d7a286c70cec5f766bc4a2797f3bba4b5060..7430988ff4aa7d252d9a62d8dbf3cf4f35e745e0 100644 --- a/lib/manager/gradle/utils.ts +++ b/lib/manager/gradle/utils.ts @@ -2,7 +2,7 @@ import { Stats } from 'fs'; import os from 'os'; import { chmod } from 'fs-extra'; import upath from 'upath'; -import { BinarySource } from '../../util/exec/common'; +import { getAdminConfig } from '../../config/admin'; import type { ExtractConfig } from '../types'; export const extraEnv = { @@ -13,7 +13,7 @@ export const extraEnv = { export function gradleWrapperFileName(config: ExtractConfig): string { if ( os.platform() === 'win32' && - config?.binarySource !== BinarySource.Docker + getAdminConfig()?.binarySource !== 'docker' ) { return 'gradlew.bat'; } diff --git a/lib/manager/helmv3/artifacts.spec.ts b/lib/manager/helmv3/artifacts.spec.ts index 0fcb69da2be1ecec0ff21cd8c03db16d3bbda722..5b34ac041207f766030e720c2b9f0088bfaaaf4a 100644 --- a/lib/manager/helmv3/artifacts.spec.ts +++ b/lib/manager/helmv3/artifacts.spec.ts @@ -5,8 +5,6 @@ import { envMock, mockExecAll } from '../../../test/exec-util'; import { git, mocked } from '../../../test/util'; import { setAdminConfig } from '../../config/admin'; import type { RepoAdminConfig } from '../../config/types'; -import { setExecConfig } from '../../util/exec'; -import { BinarySource } from '../../util/exec/common'; import * as docker from '../../util/exec/docker'; import * as _env from '../../util/exec/env'; import type { UpdateArtifactsConfig } from '../types'; @@ -29,12 +27,11 @@ const adminConfig: RepoAdminConfig = { const config: UpdateArtifactsConfig = {}; describe('.updateArtifacts()', () => { - beforeEach(async () => { + beforeEach(() => { jest.resetAllMocks(); jest.resetModules(); env.getChildProcessEnv.mockReturnValue(envMock.basic); - await setExecConfig(adminConfig as never); setAdminConfig(adminConfig); docker.resetPrefetchedImages(); }); @@ -109,8 +106,7 @@ describe('.updateArtifacts()', () => { }); it('returns updated Chart.lock with docker', async () => { - jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); - await setExecConfig({ ...adminConfig, binarySource: BinarySource.Docker }); + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); git.getFile.mockResolvedValueOnce('Old Chart.lock'); const execSnapshots = mockExecAll(exec); fs.readFile.mockResolvedValueOnce('New Chart.lock' as any); diff --git a/lib/manager/mix/artifacts.spec.ts b/lib/manager/mix/artifacts.spec.ts index 16824a564bb1c739d254fdb1555d32c85fe1bed8..376a7f187585dca0b8ea67e38a9fbf8b6444789f 100644 --- a/lib/manager/mix/artifacts.spec.ts +++ b/lib/manager/mix/artifacts.spec.ts @@ -3,8 +3,6 @@ import { envMock, exec, mockExecAll } from '../../../test/exec-util'; import { env, fs, getName } from '../../../test/util'; import { setAdminConfig } from '../../config/admin'; import type { RepoAdminConfig } from '../../config/types'; -import { setExecConfig } from '../../util/exec'; -import { BinarySource } from '../../util/exec/common'; import * as docker from '../../util/exec/docker'; import type { UpdateArtifactsConfig } from '../types'; import { updateArtifacts } from '.'; @@ -21,12 +19,11 @@ const adminConfig: RepoAdminConfig = { const config: UpdateArtifactsConfig = {}; describe(getName(), () => { - beforeEach(async () => { + beforeEach(() => { jest.resetAllMocks(); jest.resetModules(); env.getChildProcessEnv.mockReturnValue(envMock.basic); - await setExecConfig(adminConfig as never); setAdminConfig(adminConfig); }); @@ -84,7 +81,7 @@ describe(getName(), () => { it('returns updated mix.lock', async () => { jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); - await setExecConfig({ ...adminConfig, binarySource: BinarySource.Docker }); + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); fs.readLocalFile.mockResolvedValueOnce('Old mix.lock'); const execSnapshots = mockExecAll(exec); fs.readLocalFile.mockResolvedValueOnce('New mix.lock'); diff --git a/lib/manager/npm/post-update/npm.spec.ts b/lib/manager/npm/post-update/npm.spec.ts index b896545b9bde2ef7cd5dca874a223c8f3c4bc90d..5add5ecd82691a1da9e4daa37b9fcf3ae7d135a4 100644 --- a/lib/manager/npm/post-update/npm.spec.ts +++ b/lib/manager/npm/post-update/npm.spec.ts @@ -3,7 +3,6 @@ import upath from 'upath'; import { envMock, mockExecAll } from '../../../../test/exec-util'; import { mocked } from '../../../../test/util'; -import { BinarySource } from '../../../util/exec/common'; import * as _env from '../../../util/exec/env'; import * as _fs from '../../../util/fs/proxies'; import * as npmHelper from './npm'; @@ -120,7 +119,7 @@ describe('generateLockFile', () => { const execSnapshots = mockExecAll(exec); fs.readFile = jest.fn(() => 'package-lock-contents') as never; const skipInstalls = false; - const binarySource = BinarySource.Global; + const binarySource = 'global'; const res = await npmHelper.generateLockFile( 'some-dir', {}, @@ -135,7 +134,7 @@ describe('generateLockFile', () => { it('runs twice if remediating', async () => { const execSnapshots = mockExecAll(exec); fs.readFile = jest.fn(() => 'package-lock-contents') as never; - const binarySource = BinarySource.Global; + const binarySource = 'global'; const res = await npmHelper.generateLockFile( 'some-dir', {}, @@ -182,7 +181,7 @@ describe('generateLockFile', () => { 'some-dir', {}, 'package-lock.json', - { binarySource: BinarySource.Docker, constraints: { npm: '^6.0.0' } } + { binarySource: 'docker', constraints: { npm: '^6.0.0' } } ); expect(fs.readFile).toHaveBeenCalledTimes(1); expect(res.lockFile).toEqual('package-lock-contents'); diff --git a/lib/manager/nuget/artifacts.spec.ts b/lib/manager/nuget/artifacts.spec.ts index 877d8de308442eb8162d017326e07baee465783b..11066aa8ebfd5244cdabd3174079927bec64e566 100644 --- a/lib/manager/nuget/artifacts.spec.ts +++ b/lib/manager/nuget/artifacts.spec.ts @@ -4,8 +4,6 @@ import { envMock, mockExecAll } from '../../../test/exec-util'; import { fs, mocked } from '../../../test/util'; import { setAdminConfig } from '../../config/admin'; import type { RepoAdminConfig } from '../../config/types'; -import { setExecConfig } from '../../util/exec'; -import { BinarySource } from '../../util/exec/common'; import * as docker from '../../util/exec/docker'; import * as _env from '../../util/exec/env'; import * as _hostRules from '../../util/host-rules'; @@ -42,7 +40,7 @@ const adminConfig: RepoAdminConfig = { const config: UpdateArtifactsConfig = {}; describe('updateArtifacts', () => { - beforeEach(async () => { + beforeEach(() => { jest.resetAllMocks(); jest.resetModules(); getDefaultRegistries.mockReturnValue([] as any); @@ -51,7 +49,6 @@ describe('updateArtifacts', () => { Promise.resolve(dirName) ); getRandomString.mockReturnValue('not-so-random' as any); - await setExecConfig(adminConfig as never); setAdminConfig(adminConfig); docker.resetPrefetchedImages(); }); @@ -153,8 +150,7 @@ describe('updateArtifacts', () => { }); it('supports docker mode', async () => { - jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); - await setExecConfig({ ...adminConfig, binarySource: BinarySource.Docker }); + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); const execSnapshots = mockExecAll(exec); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json' as any); @@ -170,6 +166,7 @@ describe('updateArtifacts', () => { expect(execSnapshots).toMatchSnapshot(); }); it('supports global mode', async () => { + setAdminConfig({ ...adminConfig, binarySource: 'global' }); const execSnapshots = mockExecAll(exec); fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json'); fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json' as any); @@ -179,10 +176,7 @@ describe('updateArtifacts', () => { packageFileName: 'project.csproj', updatedDeps: ['dep'], newPackageFileContent: '{}', - config: { - ...config, - binarySource: BinarySource.Global, - }, + config, }) ).not.toBeNull(); expect(execSnapshots).toMatchSnapshot(); diff --git a/lib/manager/pip_setup/extract.ts b/lib/manager/pip_setup/extract.ts index cda26f734acb0fe09f9f72f46367dea3f4c916b7..762ff892c0cca684b28511c776d61b4ea5b3a155 100644 --- a/lib/manager/pip_setup/extract.ts +++ b/lib/manager/pip_setup/extract.ts @@ -1,8 +1,8 @@ +import { getAdminConfig } from '../../config/admin'; import * as datasourcePypi from '../../datasource/pypi'; import { logger } from '../../logger'; import { SkipReason } from '../../types'; import { exec } from '../../util/exec'; -import { BinarySource } from '../../util/exec/common'; import { isSkipComment } from '../../util/ignore'; import { dependencyPattern } from '../pip_requirements/extract'; import type { ExtractConfig, PackageDependency, PackageFile } from '../types'; @@ -49,7 +49,7 @@ export async function extractSetupFile( let cmd = 'python'; const extractPy = await getExtractFile(); const args = [`"${extractPy}"`, `"${packageFile}"`]; - if (config.binarySource !== BinarySource.Docker) { + if (getAdminConfig().binarySource !== 'docker') { logger.debug('Running python via global command'); cmd = await getPythonAlias(); } diff --git a/lib/manager/pip_setup/index.spec.ts b/lib/manager/pip_setup/index.spec.ts index fffa8ae536a337168a7ca984c4cce3f6618b0936..e013963cf40ed6a427d40cb40e95e2957fb6c819 100644 --- a/lib/manager/pip_setup/index.spec.ts +++ b/lib/manager/pip_setup/index.spec.ts @@ -8,8 +8,6 @@ import { import { env, getName, loadFixture } from '../../../test/util'; import { setAdminConfig } from '../../config/admin'; import type { RepoAdminConfig } from '../../config/types'; -import { setExecConfig } from '../../util/exec'; -import { BinarySource } from '../../util/exec/common'; import * as fs from '../../util/fs'; import type { ExtractConfig } from '../types'; import * as extract from './extract'; @@ -43,12 +41,11 @@ const fixSnapshots = (snapshots: ExecSnapshots): ExecSnapshots => describe(getName(), () => { describe('extractPackageFile()', () => { - beforeEach(async () => { + beforeEach(() => { jest.resetAllMocks(); jest.resetModules(); extract.resetModule(); - await setExecConfig(adminConfig as never); setAdminConfig(adminConfig); env.getChildProcessEnv.mockReturnValue(envMock.basic); @@ -78,18 +75,14 @@ describe(getName(), () => { }); it('returns found deps (docker)', async () => { - const execSnapshots = mockExecSequence(exec, [ - { stdout: '', stderr: '' }, - ]); + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); + const execSnapshots = mockExecAll(exec, { stdout: '', stderr: '' }); jest.spyOn(fs, 'readLocalFile').mockResolvedValueOnce(jsonContent); expect( - await extractPackageFile(content, packageFile, { - ...config, - binarySource: BinarySource.Docker, - }) + await extractPackageFile(content, packageFile, config) ).toMatchSnapshot(); - expect(execSnapshots).toHaveLength(1); // TODO: figure out volume arguments in Windows (#9617) + expect(execSnapshots).toHaveLength(3); // TODO: figure out volume arguments in Windows (#9617) }); it('returns no deps', async () => { diff --git a/lib/manager/pipenv/artifacts.spec.ts b/lib/manager/pipenv/artifacts.spec.ts index 64951dc94edecc8b06363f94b5ddb6f92dd370d9..5cc7b8c0fbb5b268b6e949d4fa7007e8ae97438e 100644 --- a/lib/manager/pipenv/artifacts.spec.ts +++ b/lib/manager/pipenv/artifacts.spec.ts @@ -5,8 +5,6 @@ import { envMock, mockExecAll } from '../../../test/exec-util'; import { git, mocked } from '../../../test/util'; import { setAdminConfig } from '../../config/admin'; import type { RepoAdminConfig } from '../../config/types'; -import { setExecConfig } from '../../util/exec'; -import { BinarySource } from '../../util/exec/common'; import * as docker from '../../util/exec/docker'; import * as _env from '../../util/exec/env'; import type { StatusResult } from '../../util/git'; @@ -29,14 +27,14 @@ const adminConfig: RepoAdminConfig = { localDir: join('/tmp/github/some/repo'), cacheDir: join('/tmp/renovate/cache'), }; -const dockerAdminConfig = { ...adminConfig, binarySource: BinarySource.Docker }; +const dockerAdminConfig = { ...adminConfig, binarySource: 'docker' }; const config: UpdateArtifactsConfig = {}; const lockMaintenanceConfig = { ...config, isLockFileMaintenance: true }; describe('.updateArtifacts()', () => { let pipFileLock; - beforeEach(async () => { + beforeEach(() => { jest.resetAllMocks(); env.getChildProcessEnv.mockReturnValue({ ...envMock.basic, @@ -44,7 +42,6 @@ describe('.updateArtifacts()', () => { LC_ALL: 'en_US', }); - await setExecConfig(adminConfig as never); setAdminConfig(adminConfig); docker.resetPrefetchedImages(); pipFileLock = { @@ -111,8 +108,7 @@ describe('.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('supports docker mode', async () => { - jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); - await setExecConfig(dockerAdminConfig); + setAdminConfig(dockerAdminConfig); pipFileLock._meta.requires.python_version = '3.7'; fs.readFile.mockResolvedValueOnce(JSON.stringify(pipFileLock) as any); const execSnapshots = mockExecAll(exec); @@ -125,7 +121,7 @@ describe('.updateArtifacts()', () => { packageFileName: 'Pipfile', updatedDeps: [], newPackageFileContent: 'some new content', - config: { ...config, ...dockerAdminConfig }, + config, }) ).not.toBeNull(); expect(execSnapshots).toMatchSnapshot(); @@ -162,8 +158,7 @@ describe('.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('uses pipenv version from Pipfile', async () => { - jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); - await setExecConfig(dockerAdminConfig); + setAdminConfig(dockerAdminConfig); pipFileLock.default.pipenv.version = '==2020.8.13'; fs.readFile.mockResolvedValueOnce(JSON.stringify(pipFileLock) as any); const execSnapshots = mockExecAll(exec); @@ -176,14 +171,13 @@ describe('.updateArtifacts()', () => { packageFileName: 'Pipfile', updatedDeps: [], newPackageFileContent: 'some new content', - config: { ...config, ...dockerAdminConfig }, + config, }) ).not.toBeNull(); expect(execSnapshots).toMatchSnapshot(); }); it('uses pipenv version from Pipfile dev packages', async () => { - jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); - await setExecConfig(dockerAdminConfig); + setAdminConfig(dockerAdminConfig); pipFileLock.develop.pipenv.version = '==2020.8.13'; fs.readFile.mockResolvedValueOnce(JSON.stringify(pipFileLock) as any); const execSnapshots = mockExecAll(exec); @@ -196,14 +190,13 @@ describe('.updateArtifacts()', () => { packageFileName: 'Pipfile', updatedDeps: [], newPackageFileContent: 'some new content', - config: { ...config, ...dockerAdminConfig }, + config, }) ).not.toBeNull(); expect(execSnapshots).toMatchSnapshot(); }); it('uses pipenv version from config', async () => { - jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); - await setExecConfig(dockerAdminConfig); + setAdminConfig(dockerAdminConfig); pipFileLock.default.pipenv.version = '==2020.8.13'; fs.readFile.mockResolvedValueOnce(JSON.stringify(pipFileLock) as any); const execSnapshots = mockExecAll(exec); @@ -216,7 +209,7 @@ describe('.updateArtifacts()', () => { packageFileName: 'Pipfile', updatedDeps: [], newPackageFileContent: 'some new content', - config: { ...dockerAdminConfig, constraints: { pipenv: '==2020.1.1' } }, + config: { ...config, constraints: { pipenv: '==2020.1.1' } }, }) ).not.toBeNull(); expect(execSnapshots).toMatchSnapshot(); diff --git a/lib/manager/poetry/artifacts.spec.ts b/lib/manager/poetry/artifacts.spec.ts index 85a77bc6cf639abf5de6e8020f8b3d00262b20a7..08dd6c1288956d1678d8136b4883cbb7d374f9f5 100644 --- a/lib/manager/poetry/artifacts.spec.ts +++ b/lib/manager/poetry/artifacts.spec.ts @@ -6,8 +6,6 @@ import { loadFixture, mocked } from '../../../test/util'; import { setAdminConfig } from '../../config/admin'; import type { RepoAdminConfig } from '../../config/types'; import * as _datasource from '../../datasource'; -import { setExecConfig } from '../../util/exec'; -import { BinarySource } from '../../util/exec/common'; import * as docker from '../../util/exec/docker'; import * as _env from '../../util/exec/env'; import * as _hostRules from '../../util/host-rules'; @@ -35,10 +33,9 @@ const adminConfig: RepoAdminConfig = { const config: UpdateArtifactsConfig = {}; describe('.updateArtifacts()', () => { - beforeEach(async () => { + beforeEach(() => { jest.resetAllMocks(); env.getChildProcessEnv.mockReturnValue(envMock.basic); - await setExecConfig(adminConfig as never); setAdminConfig(adminConfig); docker.resetPrefetchedImages(); }); @@ -133,8 +130,7 @@ describe('.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('returns updated poetry.lock using docker', async () => { - jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); - await setExecConfig({ ...adminConfig, binarySource: BinarySource.Docker }); + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); fs.readFile.mockResolvedValueOnce('[metadata]\n' as any); const execSnapshots = mockExecAll(exec); fs.readFile.mockReturnValueOnce('New poetry.lock' as any); @@ -159,8 +155,7 @@ describe('.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('returns updated poetry.lock using docker (constraints)', async () => { - jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); - await setExecConfig({ ...adminConfig, binarySource: BinarySource.Docker }); + setAdminConfig({ ...adminConfig, binarySource: 'docker' }); fs.readFile.mockResolvedValueOnce( '[metadata]\npython-versions = "~2.7 || ^3.4"' as any ); diff --git a/lib/manager/types.ts b/lib/manager/types.ts index 40b7f21c2b953b3e6cb03112b3621a94645ddf67..fb4236f79412402da1615d0fcd5df86b692db157 100644 --- a/lib/manager/types.ts +++ b/lib/manager/types.ts @@ -10,7 +10,6 @@ import type { File } from '../util/git'; export type Result<T> = T | Promise<T>; export interface ManagerConfig { - binarySource?: string; registryUrls?: string[]; } @@ -19,7 +18,6 @@ export interface ManagerData<T> { } export interface ExtractConfig { - binarySource?: string; registryUrls?: string[]; endpoint?: string; gradle?: { timeout?: number }; diff --git a/lib/util/exec/__snapshots__/exec.spec.ts.snap b/lib/util/exec/__snapshots__/exec.spec.ts.snap index 68d144bc5f8d10e32afd49ae4219582e66772d37..c309df433cfdf3d9e76467d3fc5d79ed865ee211 100644 --- a/lib/util/exec/__snapshots__/exec.spec.ts.snap +++ b/lib/util/exec/__snapshots__/exec.spec.ts.snap @@ -4,7 +4,6 @@ exports[`util/exec/exec Supports image prefetch 1`] = ` Array [ "echo hello", "echo hello", - "docker ps --filter label=renovate_child -aq", "docker pull renovate/image", "docker ps --filter name=renovate_image -aq", "docker run --rm --name=renovate_image --label=renovate_child renovate/image bash -l -c \\"echo hello\\"", @@ -12,7 +11,6 @@ Array [ "docker run --rm --name=renovate_image --label=renovate_child renovate/image bash -l -c \\"echo hello\\"", "echo hello", "echo hello", - "docker ps --filter label=renovate_child -aq", "docker ps --filter name=renovate_image -aq", "docker run --rm --name=renovate_image --label=renovate_child renovate/image bash -l -c \\"echo hello\\"", "docker ps --filter name=renovate_image -aq", diff --git a/lib/util/exec/common.ts b/lib/util/exec/common.ts index 3c09ad1947cccb2f42e276a711b62c5972111be0..f0cb2a9c8536242cb1fb62d2a889df441af4a9b1 100644 --- a/lib/util/exec/common.ts +++ b/lib/util/exec/common.ts @@ -6,15 +6,6 @@ import { promisify } from 'util'; export type Opt<T> = T | null | undefined; -export enum BinarySource { - Docker = 'docker', - Global = 'global', -} - -export interface ExecConfig { - binarySource: Opt<BinarySource>; -} - export type VolumesPair = [string, string]; export type VolumeOption = Opt<string | VolumesPair>; diff --git a/lib/util/exec/docker/index.ts b/lib/util/exec/docker/index.ts index b58a9d82d37c3a600f1c09d8a3a0870c69c65c00..5a619476be9eb6e3ce139a5644205f083ef5073c 100644 --- a/lib/util/exec/docker/index.ts +++ b/lib/util/exec/docker/index.ts @@ -7,7 +7,6 @@ import * as versioning from '../../../versioning'; import { ensureTrailingSlash } from '../../url'; import { DockerOptions, - ExecConfig, Opt, VolumeOption, VolumesPair, @@ -152,9 +151,14 @@ export async function removeDockerContainer( } // istanbul ignore next -export async function removeDanglingContainers(prefix: string): Promise<void> { +export async function removeDanglingContainers(): Promise<void> { + const { binarySource, dockerChildPrefix } = getAdminConfig(); + if (binarySource !== 'docker') { + return; + } + try { - const containerLabel = getContainerLabel(prefix); + const containerLabel = getContainerLabel(dockerChildPrefix); const res = await rawExec( `docker ps --filter label=${containerLabel} -aq`, { @@ -188,8 +192,7 @@ export async function removeDanglingContainers(prefix: string): Promise<void> { export async function generateDockerCommand( commands: string[], - options: DockerOptions, - config: ExecConfig + options: DockerOptions ): Promise<string> { const { envVars, cwd, tagScheme, tagConstraint } = options; let image = options.image; diff --git a/lib/util/exec/exec.spec.ts b/lib/util/exec/exec.spec.ts index b0b1c3cae367cf821ca3fc3afa5408b47af36087..b840a5fa7124a86ef3fe073a06cdc0bc5d8155b9 100644 --- a/lib/util/exec/exec.spec.ts +++ b/lib/util/exec/exec.spec.ts @@ -8,21 +8,15 @@ import { getName } from '../../../test/util'; import { setAdminConfig } from '../../config/admin'; import type { RepoAdminConfig } from '../../config/types'; import { TEMPORARY_ERROR } from '../../constants/error-messages'; -import { - BinarySource, - ExecConfig, - RawExecOptions, - VolumeOption, -} from './common'; +import { RawExecOptions, VolumeOption } from './common'; import * as dockerModule from './docker'; -import { ExecOptions, exec, setExecConfig } from '.'; +import { ExecOptions, exec } from '.'; const cpExec: jest.Mock<typeof _cpExec> = _cpExec as any; jest.mock('child_process'); interface TestInput { - execConfig: Partial<ExecConfig>; processEnv: Record<string, string>; inCmd: string | string[]; inOpts: ExecOptions; @@ -40,8 +34,6 @@ describe(getName(), () => { const defaultCwd = `-w "${cwd}"`; const defaultVolumes = `-v "${cwd}":"${cwd}" -v "${cacheDir}":"${cacheDir}"`; - const execConfig = {}; - beforeEach(() => { dockerModule.resetPrefetchedImages(); jest.resetAllMocks(); @@ -82,7 +74,6 @@ describe(getName(), () => { [ 'Single command', { - execConfig, processEnv, inCmd, inOpts: {}, @@ -102,7 +93,6 @@ describe(getName(), () => { [ 'Multiple commands', { - execConfig, processEnv, inCmd: ['echo "begin"', inCmd, "echo 'end'"], inOpts: {}, @@ -136,7 +126,6 @@ describe(getName(), () => { [ 'Explicit env option', { - execConfig, processEnv, inCmd, inOpts: { env: { FOO: 'BAR' } }, @@ -156,7 +145,6 @@ describe(getName(), () => { [ 'Low trust level', { - execConfig, processEnv, inCmd, inOpts: {}, @@ -176,7 +164,6 @@ describe(getName(), () => { [ 'High trust level', { - execConfig, processEnv: envMock.full, inCmd, inOpts: {}, @@ -197,7 +184,6 @@ describe(getName(), () => { [ 'Docker', { - execConfig: { ...execConfig, binarySource: BinarySource.Docker }, processEnv, inCmd, inOpts: { docker, cwd }, @@ -217,13 +203,13 @@ describe(getName(), () => { maxBuffer: 10485760, }, ], + adminConfig: { binarySource: 'docker' }, }, ], [ 'Extra env vars', { - execConfig, processEnv, inCmd, inOpts: { @@ -244,13 +230,13 @@ describe(getName(), () => { maxBuffer: 10485760, }, ], + adminConfig: { binarySource: 'docker' }, }, ], [ 'Extra env vars (Docker)', { - execConfig: { ...execConfig, binarySource: BinarySource.Docker }, processEnv, inCmd, inOpts: { @@ -279,13 +265,13 @@ describe(getName(), () => { maxBuffer: 10485760, }, ], + adminConfig: { binarySource: 'docker' }, }, ], [ 'Extra env vars defaults', { - execConfig, processEnv: envMock.basic, inCmd, inOpts: { cwd, extraEnv: { SELECTED_ENV_VAR: 'Default value' } }, @@ -299,13 +285,13 @@ describe(getName(), () => { maxBuffer: 10485760, }, ], + adminConfig: { binarySource: 'docker' }, }, ], [ 'Extra env vars defaults (Docker)', { - execConfig: { ...execConfig, binarySource: BinarySource.Docker }, processEnv: envMock.basic, inCmd, inOpts: { @@ -329,13 +315,13 @@ describe(getName(), () => { maxBuffer: 10485760, }, ], + adminConfig: { binarySource: 'docker' }, }, ], [ 'Docker tags', { - execConfig: { ...execConfig, binarySource: BinarySource.Docker }, processEnv, inCmd, inOpts: { docker: { image, tag }, cwd }, @@ -355,13 +341,13 @@ describe(getName(), () => { maxBuffer: 10485760, }, ], + adminConfig: { binarySource: 'docker' }, }, ], [ 'Docker volumes', { - execConfig: { ...execConfig, binarySource: BinarySource.Docker }, processEnv, inCmd, inOpts: { cwd, docker: { image, volumes } }, @@ -381,16 +367,13 @@ describe(getName(), () => { maxBuffer: 10485760, }, ], + adminConfig: { binarySource: 'docker' }, }, ], [ 'Docker user', { - execConfig: { - ...execConfig, - binarySource: BinarySource.Docker, - }, processEnv, inCmd, inOpts: { docker }, @@ -410,17 +393,16 @@ describe(getName(), () => { maxBuffer: 10485760, }, ], - adminConfig: { dockerUser: 'foobar' }, + adminConfig: { + dockerUser: 'foobar', + binarySource: 'docker', + }, }, ], [ 'Docker image prefix', { - execConfig: { - ...execConfig, - binarySource: BinarySource.Docker, - }, processEnv, inCmd, inOpts: { docker }, @@ -440,17 +422,16 @@ describe(getName(), () => { maxBuffer: 10485760, }, ], - adminConfig: { dockerImagePrefix: 'ghcr.io/renovatebot' }, + adminConfig: { + dockerImagePrefix: 'ghcr.io/renovatebot', + binarySource: 'docker', + }, }, ], [ 'Docker child prefix', { - execConfig: { - ...execConfig, - binarySource: BinarySource.Docker, - }, processEnv, inCmd, inOpts: { docker }, @@ -470,17 +451,16 @@ describe(getName(), () => { maxBuffer: 10485760, }, ], - adminConfig: { dockerChildPrefix: 'myprefix_' }, + adminConfig: { + dockerChildPrefix: 'myprefix_', + binarySource: 'docker', + }, }, ], [ 'Docker extra commands', { - execConfig: { - ...execConfig, - binarySource: BinarySource.Docker, - }, processEnv, inCmd, inOpts: { @@ -506,16 +486,13 @@ describe(getName(), () => { maxBuffer: 10485760, }, ], + adminConfig: { binarySource: 'docker' }, }, ], [ 'Docker commands are nullable', { - execConfig: { - ...execConfig, - binarySource: BinarySource.Docker, - }, processEnv, inCmd, inOpts: { @@ -541,13 +518,13 @@ describe(getName(), () => { maxBuffer: 10485760, }, ], + adminConfig: { binarySource: 'docker' }, }, ], [ 'Explicit maxBuffer', { - execConfig, processEnv, inCmd, inOpts: { @@ -563,15 +540,13 @@ describe(getName(), () => { maxBuffer: 1024, }, ], + adminConfig: { binarySource: 'docker' }, }, ], [ 'Custom environment variables for child', { - execConfig: { - ...execConfig, - }, processEnv: envMock.basic, inCmd, inOpts: {}, @@ -589,6 +564,7 @@ describe(getName(), () => { customEnvVariables: { CUSTOM_KEY: 'CUSTOM_VALUE', }, + binarySource: 'docker', }, }, ], @@ -596,9 +572,6 @@ describe(getName(), () => { [ 'Custom environment variables for child should override', { - execConfig: { - ...execConfig, - }, processEnv: { ...envMock.basic, CUSTOM_KEY: 'CUSTOM_VALUE' }, inCmd, inOpts: {}, @@ -616,6 +589,7 @@ describe(getName(), () => { customEnvVariables: { CUSTOM_KEY: 'CUSTOM_OVERRIDEN_VALUE', }, + binarySource: 'docker', }, }, ], @@ -623,10 +597,6 @@ describe(getName(), () => { [ 'Custom environment variables for child (Docker)', { - execConfig: { - ...execConfig, - binarySource: BinarySource.Docker, - }, processEnv, inCmd, inOpts: { docker, cwd }, @@ -650,6 +620,7 @@ describe(getName(), () => { customEnvVariables: { CUSTOM_KEY: 'CUSTOM_VALUE', }, + binarySource: 'docker', }, }, ], @@ -657,10 +628,6 @@ describe(getName(), () => { [ 'Custom environment variables for child should override (Docker)', { - execConfig: { - ...execConfig, - binarySource: BinarySource.Docker, - }, processEnv: { ...envMock.basic, CUSTOM_KEY: 'CUSTOM_VALUE' }, inCmd, inOpts: { docker, cwd }, @@ -684,6 +651,7 @@ describe(getName(), () => { customEnvVariables: { CUSTOM_KEY: 'CUSTOM_OVERRIDEN_VALUE', }, + binarySource: 'docker', }, }, ], @@ -691,7 +659,6 @@ describe(getName(), () => { test.each(testInputs)('%s', async (_msg, testOpts) => { const { - execConfig: config, processEnv: procEnv, inCmd: cmd, inOpts, @@ -702,13 +669,6 @@ describe(getName(), () => { process.env = procEnv; - if (config) { - jest - .spyOn(dockerModule, 'removeDanglingContainers') - .mockResolvedValueOnce(); - await setExecConfig(config); - } - const actualCmd: string[] = []; const actualOpts: ChildProcessExecOptions[] = []; cpExec.mockImplementation((execCmd, execOpts, callback) => { @@ -734,19 +694,19 @@ describe(getName(), () => { return undefined; }); - await setExecConfig({ binarySource: BinarySource.Global }); + setAdminConfig({ binarySource: 'global' }); await exec(inCmd, { docker }); await exec(inCmd, { docker }); - await setExecConfig({ binarySource: BinarySource.Docker }); + setAdminConfig({ binarySource: 'docker' }); await exec(inCmd, { docker }); await exec(inCmd, { docker }); - await setExecConfig({ binarySource: BinarySource.Global }); + setAdminConfig({ binarySource: 'global' }); await exec(inCmd, { docker }); await exec(inCmd, { docker }); - await setExecConfig({ binarySource: BinarySource.Docker }); + setAdminConfig({ binarySource: 'docker' }); await exec(inCmd, { docker }); await exec(inCmd, { docker }); @@ -769,10 +729,7 @@ describe(getName(), () => { }); it('wraps error if removeDockerContainer throws an error', async () => { - cpExec.mockImplementationOnce((_execCmd, _execOpts, callback) => - callback(null, { stdout: '', stderr: '' }) - ); - await setExecConfig({ binarySource: BinarySource.Docker }); + setAdminConfig({ binarySource: 'docker' }); cpExec.mockImplementation(() => { throw new Error('some error occurred'); }); diff --git a/lib/util/exec/index.ts b/lib/util/exec/index.ts index a01b886e5e0d83c39b0874fff385858e4b58fc25..cb31d6032693feec5936247dfa8301d37aff22e0 100644 --- a/lib/util/exec/index.ts +++ b/lib/util/exec/index.ts @@ -1,41 +1,18 @@ import type { ExecOptions as ChildProcessExecOptions } from 'child_process'; import { dirname, join } from 'upath'; import { getAdminConfig } from '../../config/admin'; -import type { RenovateConfig } from '../../config/types'; import { TEMPORARY_ERROR } from '../../constants/error-messages'; import { logger } from '../../logger'; import { - BinarySource, DockerOptions, - ExecConfig, ExecResult, Opt, RawExecOptions, rawExec, } from './common'; -import { - generateDockerCommand, - removeDanglingContainers, - removeDockerContainer, -} from './docker'; +import { generateDockerCommand, removeDockerContainer } from './docker'; import { getChildProcessEnv } from './env'; -const execConfig: ExecConfig = { - binarySource: null, -}; - -export async function setExecConfig( - config: Partial<RenovateConfig> -): Promise<void> { - for (const key of Object.keys(execConfig)) { - const value = config[key]; - execConfig[key] = value || null; - } - if (execConfig.binarySource === 'docker') { - await removeDanglingContainers(getAdminConfig().dockerChildPrefix); - } -} - type ExtraEnv<T = unknown> = Record<string, T>; export interface ExecOptions extends ChildProcessExecOptions { @@ -93,11 +70,11 @@ export async function exec( opts: ExecOptions = {} ): Promise<ExecResult> { const { env, docker, cwdFile } = opts; - const { dockerChildPrefix, customEnvVariables } = getAdminConfig(); + const { binarySource, dockerChildPrefix, customEnvVariables, localDir } = + getAdminConfig(); const extraEnv = { ...opts.extraEnv, ...customEnvVariables }; let cwd; // istanbul ignore if - const { localDir } = getAdminConfig(); if (cwdFile) { cwd = join(localDir, dirname(cwdFile)); } @@ -121,7 +98,7 @@ export async function exec( rawExecOptions.maxBuffer = rawExecOptions.maxBuffer || 10 * 1024 * 1024; let commands = typeof cmd === 'string' ? [cmd] : cmd; - const useDocker = execConfig.binarySource === BinarySource.Docker && docker; + const useDocker = binarySource === 'docker' && docker; if (useDocker) { logger.debug('Using docker to execute'); const dockerOptions = { @@ -130,11 +107,7 @@ export async function exec( envVars: dockerEnvVars(extraEnv, childEnv), }; - const dockerCommand = await generateDockerCommand( - commands, - dockerOptions, - execConfig - ); + const dockerCommand = await generateDockerCommand(commands, dockerOptions); commands = [dockerCommand]; } diff --git a/lib/workers/global/index.ts b/lib/workers/global/index.ts index 6d096d4f8c4ce39b93e573c34fda55cc5f98c881..6f88991f9bd27d7329fa2a45d3e314a837b451f4 100644 --- a/lib/workers/global/index.ts +++ b/lib/workers/global/index.ts @@ -14,7 +14,6 @@ import type { } from '../../config/types'; import { CONFIG_PRESETS_INVALID } from '../../constants/error-messages'; import { getProblems, logger, setMeta } from '../../logger'; -import { setExecConfig } from '../../util/exec'; import * as hostRules from '../../util/host-rules'; import * as repositoryWorker from '../repository'; import { autodiscoverRepositories } from './autodiscover'; @@ -103,7 +102,6 @@ export async function start(): Promise<number> { break; } const repoConfig = await getRepositoryConfig(config, repository); - await setExecConfig(repoConfig); if (repoConfig.hostRules) { hostRules.clear(); repoConfig.hostRules.forEach((rule) => hostRules.add(rule)); diff --git a/lib/workers/repository/index.ts b/lib/workers/repository/index.ts index 8e53c451002c90eba6b28e10d0960664b0c46e4e..22a7bd13ac04e7a73d06630e03f9f1c646b56d6d 100644 --- a/lib/workers/repository/index.ts +++ b/lib/workers/repository/index.ts @@ -2,6 +2,7 @@ import fs from 'fs-extra'; import { getAdminConfig, setAdminConfig } from '../../config/admin'; import type { RenovateConfig } from '../../config/types'; import { logger, setMeta } from '../../logger'; +import { removeDanglingContainers } from '../../util/exec/docker'; import { deleteLocalFile, privateCacheDir } from '../../util/fs'; import * as queue from '../../util/http/queue'; import { addSplit, getSplits, splitInit } from '../../util/split'; @@ -30,6 +31,7 @@ export async function renovateRepository( ): Promise<ProcessResult> { splitInit(); let config = setAdminConfig(repoConfig); + await removeDanglingContainers(); setMeta({ repository: config.repository }); logger.info({ renovateVersion }, 'Repository started'); logger.trace({ config });