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

refactor: move preCommands out of docker options #12938

Merged
merged 4 commits into from
Dec 3, 2021
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
2 changes: 1 addition & 1 deletion lib/manager/bundler/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ export async function updateArtifacts(
image: 'ruby',
tagScheme: 'ruby',
tagConstraint: await getRubyConstraint(updateArtifact),
preCommands,
},
preCommands,
};
await exec(cmd, execOptions);

Expand Down
2 changes: 1 addition & 1 deletion lib/manager/gradle/deep/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ export async function executeGradle(
tagConstraint:
config.constraints?.java ?? (await getDockerConstraint(gradleRoot)),
tagScheme: getJavaVersioning(),
preCommands: await getDockerPreCommands(gradleRoot),
},
preCommands: await getDockerPreCommands(gradleRoot),
extraEnv,
};
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/mix/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export async function updateArtifacts({
cwdFile: packageFileName,
docker: {
image: 'elixir',
preCommands,
},
preCommands,
};
const command = [
'mix',
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/npm/post-update/lerna.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export async function generateLockFiles(
image: 'node',
tagScheme: 'node',
tagConstraint,
preCommands,
},
preCommands,
};
// istanbul ignore if
if (GlobalConfig.get('exposeAllEnv')) {
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/npm/post-update/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export async function generateLockFile(
image: 'node',
tagScheme: 'node',
tagConstraint,
preCommands,
},
preCommands,
};
// istanbul ignore if
if (GlobalConfig.get('exposeAllEnv')) {
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/npm/post-update/pnpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export async function generateLockFile(
image: 'node',
tagScheme: 'node',
tagConstraint,
preCommands,
},
preCommands,
};
// istanbul ignore if
if (GlobalConfig.get('exposeAllEnv')) {
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/npm/post-update/yarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ export async function generateLockFile(
image: 'node',
tagScheme: 'node',
tagConstraint,
preCommands,
},
preCommands,
};
// istanbul ignore if
if (GlobalConfig.get('exposeAllEnv')) {
Expand Down
6 changes: 3 additions & 3 deletions lib/manager/pip-compile/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ export async function updateArtifacts({
image: 'python',
tagConstraint,
tagScheme: 'pep440',
preCommands: [
`pip install --user ${quote(`pip-tools${pipToolsConstraint}`)}`,
],
},
preCommands: [
`pip install --user ${quote(`pip-tools${pipToolsConstraint}`)}`,
],
};
logger.debug({ cmd }, 'pip-compile command');
await exec(cmd, execOptions);
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/pip_requirements/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export async function updateArtifacts({
docker: {
image: 'python',
tagScheme: 'pip_requirements',
preCommands: ['pip install hashin'],
},
preCommands: ['pip install hashin'],
};
await exec(cmd, execOptions);
const newContent = await readLocalFile(packageFileName, 'utf8');
Expand Down
4 changes: 1 addition & 3 deletions lib/manager/pipenv/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@ export async function updateArtifacts({
image: 'python',
tagConstraint,
tagScheme: 'pep440',
preCommands: [
`pip install --user ${quote(`pipenv${pipenvConstraint}`)}`,
],
},
preCommands: [`pip install --user ${quote(`pipenv${pipenvConstraint}`)}`],
};
logger.debug({ cmd }, 'pipenv lock command');
await exec(cmd, execOptions);
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/poetry/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ export async function updateArtifacts({
image: 'python',
tagConstraint,
tagScheme: 'poetry',
preCommands: [poetryInstall],
},
preCommands: [poetryInstall],
};
await exec(cmd, execOptions);
const newPoetryLockContent = await readLocalFile(lockFileName, 'utf8');
Expand Down
1 change: 0 additions & 1 deletion lib/util/exec/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export interface DockerOptions {
volumes?: Opt<VolumeOption[]>;
envVars?: Opt<Opt<string>[]>;
cwd?: Opt<string>;
preCommands?: DockerExtraCommands;
}

export interface RawExecOptions extends ChildProcessExecOptions {
Expand Down
13 changes: 8 additions & 5 deletions lib/util/exec/docker/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ describe('util/exec/docker/index', () => {
const envVars = ['FOO', 'BAR'];
const image = 'sample_image';
const dockerOptions = {
preCommands,
image,
cwd: '/tmp/foobar',
envVars,
Expand All @@ -234,7 +233,11 @@ describe('util/exec/docker/index', () => {

it('returns executable command', async () => {
mockExecAll(exec);
const res = await generateDockerCommand(commands, dockerOptions);
const res = await generateDockerCommand(
commands,
preCommands,
dockerOptions
);
expect(res).toBe(command(image));
});

Expand All @@ -245,7 +248,7 @@ describe('util/exec/docker/index', () => {
['/tmp/bar', `/tmp/bar`],
['/tmp/baz', `/home/baz`],
];
const res = await generateDockerCommand(commands, {
const res = await generateDockerCommand(commands, preCommands, {
...dockerOptions,
volumes: [...volumes, ...volumes],
});
Expand All @@ -259,7 +262,7 @@ describe('util/exec/docker/index', () => {

it('handles tag parameter', async () => {
mockExecAll(exec);
const res = await generateDockerCommand(commands, {
const res = await generateDockerCommand(commands, preCommands, {
...dockerOptions,
tag: '1.2.3',
});
Expand All @@ -275,7 +278,7 @@ describe('util/exec/docker/index', () => {
{ version: '2.0.0' },
],
} as never);
const res = await generateDockerCommand(commands, {
const res = await generateDockerCommand(commands, preCommands, {
...dockerOptions,
tagScheme: 'npm',
tagConstraint: '^1.2.3',
Expand Down
2 changes: 1 addition & 1 deletion lib/util/exec/docker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ export async function removeDanglingContainers(): Promise<void> {

export async function generateDockerCommand(
commands: string[],
preCommands: string[],
options: DockerOptions
): Promise<string> {
const { envVars, cwd, tagScheme, tagConstraint } = options;
let image = options.image;
const volumes = options.volumes || [];
const preCommands = options.preCommands || [];
const {
localDir,
cacheDir,
Expand Down
3 changes: 1 addition & 2 deletions lib/util/exec/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,8 @@ describe('util/exec/index', () => {
inOpts: {
docker: {
image,
preCommands: ['preCommand1', 'preCommand2', null],
},
preCommands: ['preCommand1', 'preCommand2', null],
},
outCmd: [
dockerPullCmd,
Expand Down Expand Up @@ -495,7 +495,6 @@ describe('util/exec/index', () => {
inOpts: {
docker: {
image,
preCommands: null,
},
},
outCmd: [
Expand Down
8 changes: 6 additions & 2 deletions lib/util/exec/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TEMPORARY_ERROR } from '../../constants/error-messages';
import { logger } from '../../logger';
import { generateInstallCommands } from './buildpack';
import {
DockerExtraCommands,
DockerOptions,
ExecResult,
Opt,
Expand All @@ -22,6 +23,7 @@ export interface ExecOptions extends ChildProcessExecOptions {
extraEnv?: Opt<ExtraEnv>;
docker?: Opt<DockerOptions>;
toolConstraints?: Opt<ToolConstraint[]>;
preCommands?: DockerExtraCommands;
rarkins marked this conversation as resolved.
Show resolved Hide resolved
}

function getChildEnv({
Expand Down Expand Up @@ -74,6 +76,7 @@ function getRawExecOptions(opts: ExecOptions): RawExecOptions {
delete execOptions.docker;
delete execOptions.cwdFile;
delete execOptions.toolConstraints;
delete execOptions.preCommands;

const childEnv = getChildEnv(opts);
const cwd = getCwd(opts);
Expand Down Expand Up @@ -125,12 +128,13 @@ async function prepareRawExec(
const envVars = dockerEnvVars(extraEnv, childEnv);
const cwd = getCwd(opts);
const dockerOptions: DockerOptions = { ...docker, cwd, envVars };
dockerOptions.preCommands = [
const preCommands = [
...(await generateInstallCommands(opts.toolConstraints)),
...(dockerOptions.preCommands || []),
...(opts.preCommands || []),
];
const dockerCommand = await generateDockerCommand(
rawCommands,
preCommands,
dockerOptions
);
rawCommands = [dockerCommand];
Expand Down