From c0afe86658f7f78d9146f27bf1ef7f8993a48036 Mon Sep 17 00:00:00 2001 From: Mike Ryan Date: Mon, 30 Sep 2024 06:24:25 -0400 Subject: [PATCH] feat: add `docker-socket-host-path` input (#862) Co-authored-by: Michael Kriese --- README.md | 7 +++++++ action.yml | 7 +++++++ src/input.ts | 4 ++++ src/renovate.ts | 10 +++++++++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f0f69dbd..f4d282d2 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ GitHub Action to run Renovate self-hosted. - [`configurationFile`](#configurationfile) - [`docker-cmd-file`](#docker-cmd-file) - [`docker-network`](#docker-network) + - [`docker-socket-host-path`](#docker-socket-host-path) - [`docker-user`](#docker-user) - [`docker-volumes`](#docker-volumes) - [`env-regex`](#env-regex) @@ -113,6 +114,12 @@ Specify a network to run container in. You can use `${{ job.container.network }}` to run renovate container [in the same network as other containers for this job](https://docs.github.com/en/actions/learn-github-actions/contexts#job-context), or set it to `host` to run in the same network as github runner, or specify any custom network. +### `docker-socket-host-path` + +Allows the overriding of the host path for the Docker socket that is mounted into the container. +Useful on systems where the host Docker socket is located somewhere other than `/var/run/docker.sock` (the default). +Only applicable when `mount-docker-socket` is true. + ### `docker-user` Specify a user (or user-id) to run docker command. diff --git a/action.yml b/action.yml index b565834b..d2e274ec 100644 --- a/action.yml +++ b/action.yml @@ -36,6 +36,13 @@ inputs: can use Docker. Also add the user inside the renovate container to the docker group for socket permissions. required: false + docker-socket-host-path: + description: | + Allows the overriding of the host path for the Docker socket that is mounted into the container. + Useful on systems where the host Docker socket is located somewhere other than '/var/run/docker.sock' (the default). + Only applicable when 'mount-docker-socket' is true. + required: false + default: /var/run/docker.sock docker-cmd-file: description: | Override docker command. Default command is `renovate` diff --git a/src/input.ts b/src/input.ts index 693b1528..3b8c8791 100644 --- a/src/input.ts +++ b/src/input.ts @@ -73,6 +73,10 @@ class Input { return core.getInput('mount-docker-socket') === 'true'; } + dockerSocketHostPath(): string { + return core.getInput('docker-socket-host-path') || '/var/run/docker.sock'; + } + getDockerCmdFile(): string | null { const cmdFile = core.getInput('docker-cmd-file'); return !!cmdFile && cmdFile !== '' ? path.resolve(cmdFile) : null; diff --git a/src/renovate.ts b/src/renovate.ts index fb2d35b8..2edb32cc 100644 --- a/src/renovate.ts +++ b/src/renovate.ts @@ -33,8 +33,16 @@ class Renovate { } if (this.input.mountDockerSocket()) { + const sockPath = this.input.dockerSocketHostPath(); + const stat = await fs.stat(sockPath); + if (!stat.isSocket()) { + throw new Error( + `docker socket host path '${sockPath}' MUST exist and be a socket`, + ); + } + dockerArguments.push( - '--volume /var/run/docker.sock:/var/run/docker.sock', + `--volume ${sockPath}:/var/run/docker.sock`, `--group-add ${await this.getDockerGroupId()}`, ); }