fix: mount volume with config file to Docker container

This commit is contained in:
Jeroen de Bruijn 2020-05-03 19:14:08 +02:00
parent cd791cb5c3
commit 4fa9cad2cc
No known key found for this signature in database
GPG key ID: 3A2677A1DF38FF9F

View file

@ -1,27 +1,53 @@
import Docker from './docker';
import child from 'child_process';
import fs from 'fs';
import path from 'path';
class Renovate {
private configurationFileEnv = 'RENOVATE_CONFIG_FILE';
private configFileEnv = 'RENOVATE_CONFIG_FILE';
private tokenEnv = 'RENOVATE_TOKEN';
private configFileMountDir = '/github-action';
private configFile: string;
private docker: Docker;
constructor(private configurationFile: string, private token: string) {
constructor(configFile: string, private token: string) {
this.configFile = path.resolve(configFile);
this.validateArguments();
this.docker = new Docker();
}
runDockerContainer(): void {
const commandArguments = [
'--rm',
`--env ${this.configurationFileEnv}='${this.configurationFile}'`,
`--env ${this.configFileEnv}='${this.configFileMountPath()}'`,
`--env ${this.tokenEnv}='${this.token}'`,
`--volume ${this.configFile}:${this.configFileMountPath()}`,
this.docker.image(),
];
const command = `docker run ${commandArguments.join(' ')}`;
// console.log(commandArguments, command);
child.execSync(command, { stdio: 'inherit' });
}
private validateArguments(): void {
if (!fs.existsSync(this.configFile)) {
throw new Error(
`Could not locate configuration file '${this.configFile}'.`,
);
}
}
private configFileName(): string {
return path.basename(this.configFile);
}
private configFileMountPath(): string {
return path.join(this.configFileMountDir, this.configFileName());
}
}
export default Renovate;