mirror of
https://github.com/renovatebot/github-action.git
synced 2025-12-18 09:52:35 +00:00
fix: mount volume with config file to Docker container
This commit is contained in:
parent
cd791cb5c3
commit
4fa9cad2cc
1 changed files with 29 additions and 3 deletions
|
|
@ -1,27 +1,53 @@
|
||||||
import Docker from './docker';
|
import Docker from './docker';
|
||||||
import child from 'child_process';
|
import child from 'child_process';
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
class Renovate {
|
class Renovate {
|
||||||
private configurationFileEnv = 'RENOVATE_CONFIG_FILE';
|
private configFileEnv = 'RENOVATE_CONFIG_FILE';
|
||||||
private tokenEnv = 'RENOVATE_TOKEN';
|
private tokenEnv = 'RENOVATE_TOKEN';
|
||||||
|
private configFileMountDir = '/github-action';
|
||||||
|
|
||||||
|
private configFile: string;
|
||||||
private docker: Docker;
|
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();
|
this.docker = new Docker();
|
||||||
}
|
}
|
||||||
|
|
||||||
runDockerContainer(): void {
|
runDockerContainer(): void {
|
||||||
const commandArguments = [
|
const commandArguments = [
|
||||||
'--rm',
|
'--rm',
|
||||||
`--env ${this.configurationFileEnv}='${this.configurationFile}'`,
|
`--env ${this.configFileEnv}='${this.configFileMountPath()}'`,
|
||||||
`--env ${this.tokenEnv}='${this.token}'`,
|
`--env ${this.tokenEnv}='${this.token}'`,
|
||||||
|
`--volume ${this.configFile}:${this.configFileMountPath()}`,
|
||||||
this.docker.image(),
|
this.docker.image(),
|
||||||
];
|
];
|
||||||
const command = `docker run ${commandArguments.join(' ')}`;
|
const command = `docker run ${commandArguments.join(' ')}`;
|
||||||
|
// console.log(commandArguments, command);
|
||||||
|
|
||||||
child.execSync(command, { stdio: 'inherit' });
|
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;
|
export default Renovate;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue