Update techdocs/scaffolder with new function parameters of runDockerContainer

Signed-off-by: Himanshu Mishra <himanshu@orkohunter.net>
This commit is contained in:
Himanshu Mishra
2021-03-06 13:11:36 +01:00
parent 63b8914b82
commit 68575f3689
3 changed files with 44 additions and 8 deletions
@@ -16,6 +16,7 @@
import { runDockerContainer } from '@backstage/backend-common';
import { Config } from '@backstage/config';
import fs from 'fs-extra';
import path from 'path';
import { PassThrough } from 'stream';
import { Logger } from 'winston';
@@ -78,6 +79,14 @@ export class TechdocsGenerator implements GeneratorBase {
);
}
// Directories to bind on container
const mountDirs = new Map([
// Need to use realpath here as Docker mounting does not like
// symlinks for binding volumes
[await fs.realpath(inputDir), '/input'],
[await fs.realpath(outputDir), '/output'],
]);
try {
switch (this.options.runGeneratorIn) {
case 'local':
@@ -98,8 +107,11 @@ export class TechdocsGenerator implements GeneratorBase {
imageName: 'spotify/techdocs',
args: ['build', '-d', '/output'],
logStream,
inputDir,
outputDir,
mountDirs,
workingDir: '/input',
// Set the home directory inside the container as something that applications can
// write to, otherwise they will just fail trying to write to /
envVars: ['HOME=/tmp'],
dockerClient,
});
this.logger.info(
@@ -136,6 +136,11 @@ describe('CookieCutter Templater', () => {
};
jest.spyOn(fs, 'readdir').mockResolvedValueOnce(['newthing']);
jest
.spyOn(fs, 'realpath')
.mockImplementation((filePath: string | Buffer) =>
Promise.resolve(filePath as string),
);
const templater = new CookieCutter();
await templater.run({
@@ -154,8 +159,12 @@ describe('CookieCutter Templater', () => {
'/input',
'--verbose',
],
inputDir: path.join('tempdir', 'template'),
outputDir: path.join('tempdir', 'intermediate'),
envVars: ['HOME=/tmp'],
mountDirs: new Map([
[path.join('tempdir', 'template'), '/input'],
[path.join('tempdir', 'intermediate'), '/output'],
]),
workingDir: '/input',
logStream: undefined,
dockerClient: mockDocker,
});
@@ -193,8 +202,12 @@ describe('CookieCutter Templater', () => {
'/input',
'--verbose',
],
inputDir: path.join('tempdir', 'template'),
outputDir: path.join('tempdir', 'intermediate'),
envVars: ['HOME=/tmp'],
mountDirs: new Map([
[path.join('tempdir', 'template'), '/input'],
[path.join('tempdir', 'intermediate'), '/output'],
]),
workingDir: '/input',
logStream: stream,
dockerClient: mockDocker,
});
@@ -58,6 +58,14 @@ export class CookieCutter implements TemplaterBase {
await fs.writeJSON(path.join(templateDir, 'cookiecutter.json'), cookieInfo);
// Directories to bind on container
const mountDirs = new Map([
// Need to use realpath here as Docker mounting does not like
// symlinks for binding volumes
[await fs.realpath(templateDir), '/input'],
[await fs.realpath(intermediateDir), '/output'],
]);
const cookieCutterInstalled = await commandExists('cookiecutter');
if (cookieCutterInstalled) {
await runCommand({
@@ -76,8 +84,11 @@ export class CookieCutter implements TemplaterBase {
'/input',
'--verbose',
],
inputDir: templateDir,
outputDir: intermediateDir,
mountDirs,
workingDir: '/input',
// Set the home directory inside the container as something that applications can
// write to, otherwise they will just fail trying to write to /
envVars: ['HOME=/tmp'],
logStream,
dockerClient,
});