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: allow to override docker command and user #783

Merged
merged 11 commits into from
Oct 16, 2023
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ jobs:
with:
configurationFile: ${{ matrix.configurationFile }}
renovate-version: ${{ env.RENOVATE_VERSION }}
docker-cmd-file: example/entrypoint.sh
docker-user: root
viceice marked this conversation as resolved.
Show resolved Hide resolved

release:
needs: [lint, commitlint, e2e]
Expand Down
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ GitHub Action to run Renovate self-hosted.
- [`token`](#token)
- [`renovate-image`](#renovate-image)
- [`renovate-version`](#renovate-version)
- [`docker-cmd-file`](#docker-cmd-file)
- [`docker-user`](#docker-user)
Copy link
Member

Choose a reason for hiding this comment

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

We should sort aphabetically

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

- [Example](#example)
- [Environment Variables](#environment-variables)
- [Passing other environment variables](#passing-other-environment-variables)
Expand Down Expand Up @@ -172,6 +174,51 @@ jobs:
We recommend you pin the version of Renovate to a full version or a full checksum, and use Renovate's regex manager to create PRs to update the pinned version.
See `.github/workflows/build.yml` for an example of how to do this.

### `docker-cmd-file`

Specify a command to run when the image start. By default the image run
`renovate`

This option is useful to customize the image before running `renovate`

For example you can create a simple script like this one (let's call it
`renovate-entrypoint.sh`)
CedricCabessa marked this conversation as resolved.
Show resolved Hide resolved

```sh
#!/bin/bash

apt update

apt install -y build-essential libpq-dev

runuser -u ubuntu renovate
```

Now use this action

```yml
....
jobs:
renovate:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3.5.3
- name: Self-hosted Renovate
uses: renovatebot/github-action@v39.0.0
with:
docker-cmd-file: .github/renovate-entrypoint.sh
docker-user: root
token: ${{ secrets.RENOVATE_TOKEN }}
```

### `docker-user`

Specify a user (or user-id) to run docker command.

You can use it with [`docker-cmd-file`](#docker-cmd-file) in order to start the
image as root, do some customization and switch back to a unprivileged user.

## Example

This example uses a Personal Access Token and will run every 15 minutes.
Expand Down
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ inputs:
can use Docker. Also add the user inside the renovate container to the
docker group for socket permissions.
required: false
docker-cmd-file:
description: |
Override docker command. Default command is `renovate`
required: false
docker-user:
description: |
Docker user. Default to an unprivileged user
required: false

runs:
using: node16
main: dist/index.js
7 changes: 7 additions & 0 deletions example/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

set -e

install-apt sl

exec runuser -u ubuntu renovate
9 changes: 9 additions & 0 deletions src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ class Input {
return core.getInput('mount-docker-socket') === 'true';
}

getDockerCmdFile(): string | null {
const cmdFile = core.getInput('docker-cmd-file');
return !!cmdFile && cmdFile !== '' ? path.resolve(cmdFile) : null;
}

getDockerUser(): string | null {
return core.getInput('docker-user') || null;
}

/**
* Convert to environment variables.
*
Expand Down
18 changes: 18 additions & 0 deletions src/renovate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,26 @@ class Renovate {
);
}

const docker_cmd_file = this.input.getDockerCmdFile();
let docker_cmd = null;
viceice marked this conversation as resolved.
Show resolved Hide resolved
if (docker_cmd_file !== null) {
const baseName = path.basename(docker_cmd_file);
const mountPath = path.join('/', baseName);
CedricCabessa marked this conversation as resolved.
Show resolved Hide resolved
dockerArguments.push(`--volume ${docker_cmd_file}:${mountPath}`);
docker_cmd = mountPath;
}

const docker_user = this.input.getDockerUser();
if (docker_user !== null) {
dockerArguments.push(`--user ${docker_user}`);
}

dockerArguments.push('--volume /tmp:/tmp', '--rm', this.docker.image());

if (docker_cmd !== null) {
dockerArguments.push(docker_cmd);
}

const command = `docker run ${dockerArguments.join(' ')}`;

const code = await exec(command);
Expand Down