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: add docker image prefix #7164

Merged
merged 11 commits into from
Sep 8, 2020
6 changes: 6 additions & 0 deletions docs/usage/self-hosted-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ Configure this directory if you want to change which directory Renovate uses for

Set to `false` to prevent usage of `--ignore-platform-reqs` in the composer package manager.

## dockerImagePrefix

Override the default renovate sidecar docker containers image prefix from `docker.io/renovate` to a custom value, so renovate will pull images from a custom docker registry.

If this is set to `ghcr.io/renovatebot` the final image for `node` would become `ghcr.io/renovatebot/node` instead of currently used `docker.io/renovate/node`.

## dockerMapDotfiles

This is used if you want to map "dotfiles" from your host computer home directory to containers that Renovate creates, e.g. for updating lock files. Currently applicable to `.npmrc` only.
Expand Down
4 changes: 4 additions & 0 deletions lib/config/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export interface RenovateAdminConfig {
baseDir?: string;
cacheDir?: string;
configWarningReuseIssue?: boolean;

dockerImagePrefix?: string;
dockerUser?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary for the PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but was missing anyway. I don't want to add a pr for just that simple type.

There are a lot more properties missing but becuase of extending Record somewhere it will mostly work. We should make that types more strict.


dryRun?: boolean;

endpoint?: string;
Expand Down
8 changes: 8 additions & 0 deletions lib/config/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@ const options: RenovateOptions[] = [
type: 'boolean',
default: false,
},
{
name: 'dockerImagePrefix',
description:
'Change this value in order to override the default renovate docker sidecar image name prefix.',
type: 'string',
default: 'docker.io/renovate',
admin: true,
},
{
name: 'dockerUser',
description:
Expand Down
18 changes: 9 additions & 9 deletions lib/util/exec/__snapshots__/exec.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ Array [
"echo hello",
"echo hello",
"docker ps --filter label=renovate_child -aq",
"docker pull example/image",
"docker ps --filter name=example_image -aq",
"docker run --rm --name=example_image --label=renovate_child example/image bash -l -c \\"echo hello\\"",
"docker ps --filter name=example_image -aq",
"docker run --rm --name=example_image --label=renovate_child example/image bash -l -c \\"echo hello\\"",
"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\\"",
"docker ps --filter name=renovate_image -aq",
"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=example_image -aq",
"docker run --rm --name=example_image --label=renovate_child example/image bash -l -c \\"echo hello\\"",
"docker ps --filter name=example_image -aq",
"docker run --rm --name=example_image --label=renovate_child example/image bash -l -c \\"echo hello\\"",
"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",
"docker run --rm --name=renovate_image --label=renovate_child renovate/image bash -l -c \\"echo hello\\"",
]
`;
1 change: 1 addition & 0 deletions lib/util/exec/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum BinarySource {

export interface ExecConfig {
binarySource: Opt<BinarySource>;
dockerImagePrefix: Opt<string>;
dockerUser: Opt<string>;
localDir: Opt<string>;
cacheDir: Opt<string>;
Expand Down
11 changes: 10 additions & 1 deletion lib/util/exec/docker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SYSTEM_INSUFFICIENT_MEMORY } from '../../../constants/error-messages';
import { getPkgReleases } from '../../../datasource';
import { logger } from '../../../logger';
import * as versioning from '../../../versioning';
import { ensureTrailingSlash } from '../../url';
import {
DockerOptions,
ExecConfig,
Expand Down Expand Up @@ -180,7 +181,8 @@ export async function generateDockerCommand(
options: DockerOptions,
config: ExecConfig
): Promise<string> {
const { image, envVars, cwd, tagScheme, tagConstraint } = options;
const { envVars, cwd, tagScheme, tagConstraint } = options;
let image = options.image;
const volumes = options.volumes || [];
const preCommands = options.preCommands || [];
const postCommands = options.postCommands || [];
Expand Down Expand Up @@ -208,6 +210,13 @@ export async function generateDockerCommand(
result.push(`-w "${cwd}"`);
}

if (config.dockerImagePrefix) {
image = image.replace(
/^renovate\//,
ensureTrailingSlash(config.dockerImagePrefix)
);
}

let tag: string;
if (options.tag) {
tag = options.tag;
Expand Down
26 changes: 25 additions & 1 deletion lib/util/exec/exec.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe(`Child process execution wrapper`, () => {
global.trustLevel = trustLevelOrig;
});

const image = 'example/image';
const image = 'renovate/image';
const name = image.replace(/\//g, '_');
const tag = '1.2.3';
const inCmd = 'echo hello';
Expand Down Expand Up @@ -331,6 +331,30 @@ describe(`Child process execution wrapper`, () => {
},
],

[
'Docker image prefix',
{
execConfig: {
...execConfig,
binarySource: BinarySource.Docker,
dockerImagePrefix: 'ghcr.io/renovatebot',
},
processEnv,
inCmd,
inOpts: { docker },
outCmd: [
`docker pull ghcr.io/renovatebot/image`,
dockerRemoveCmd,
`docker run --rm --name=${name} --label=renovate_child ${defaultVolumes} -w "${cwd}" ghcr.io/renovatebot/image bash -l -c "${inCmd}"`,
],
outOpts: [
dockerPullOpts,
dockerRemoveOpts,
{ cwd, encoding, env: envMock.basic, timeout: 900000 },
],
},
],

[
'Docker extra commands',
{
Expand Down
1 change: 1 addition & 0 deletions lib/util/exec/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { getChildProcessEnv } from './env';

const execConfig: ExecConfig = {
binarySource: null,
dockerImagePrefix: null,
dockerUser: null,
localDir: null,
cacheDir: null,
Expand Down