fix: throw error if docker group cannot be found (#78)

This commit is contained in:
Jeroen de Bruijn 2020-05-11 21:39:15 +02:00 committed by GitHub
parent 17a2d55cdd
commit 3aa72249b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,7 @@ import path from 'path';
class Renovate { class Renovate {
private configFileEnv = 'RENOVATE_CONFIG_FILE'; private configFileEnv = 'RENOVATE_CONFIG_FILE';
private tokenEnv = 'RENOVATE_TOKEN'; private tokenEnv = 'RENOVATE_TOKEN';
private dockerGroupName = 'docker';
private configFileMountDir = '/github-action'; private configFileMountDir = '/github-action';
private configFile: string; private configFile: string;
@ -47,7 +48,8 @@ class Renovate {
* required permissions on the Docker socket. * required permissions on the Docker socket.
*/ */
private getDockerGroupId(): string { private getDockerGroupId(): string {
const groups = fs.readFileSync('/etc/group', { const groupFile = '/etc/group';
const groups = fs.readFileSync(groupFile, {
encoding: 'utf-8', encoding: 'utf-8',
}); });
@ -57,8 +59,15 @@ class Renovate {
* *
* Source: https://www.thegeekdiary.com/etcgroup-file-explained/ * Source: https://www.thegeekdiary.com/etcgroup-file-explained/
*/ */
const [, group] = /^docker:x:([1-9][0-9]*):$/m.exec(groups); const re = new RegExp(`^${this.dockerGroupName}:x:([1-9][0-9]*):`, 'm');
return group; const match = re.exec(groups);
if (!match || match.length < 2) {
throw new Error(
`Could not find group '${this.dockerGroupName}' in ${groupFile}`
);
}
return match[1];
} }
private validateArguments(): void { private validateArguments(): void {