From d8c038be4442a09830b55139971898e28234e2fa Mon Sep 17 00:00:00 2001 From: Eric Siebeneich Date: Tue, 31 Oct 2023 23:23:39 -0500 Subject: [PATCH] fix(docker): passthrough service not calling docker with current user and group --- .../src/app/services/pass-through.service.spec.ts | 2 +- apps/generator-cli/src/app/services/pass-through.service.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/generator-cli/src/app/services/pass-through.service.spec.ts b/apps/generator-cli/src/app/services/pass-through.service.spec.ts index 21057ccb1..701e9e6c8 100644 --- a/apps/generator-cli/src/app/services/pass-through.service.spec.ts +++ b/apps/generator-cli/src/app/services/pass-through.service.spec.ts @@ -162,7 +162,7 @@ describe('PassThroughService', () => { await program.parseAsync([name, ...argv], {from: 'user'}) expect(childProcess.spawn).toHaveBeenNthCalledWith( 1, - 'docker run --rm -v "/foo/bar:/local" openapitools/openapi-generator-cli:v4.2.1', + expect.stringMatching(/docker run --rm -v "\/foo\/bar:\/local" --user \d+:\d+ openapitools\/openapi-generator-cli:v4.2.1/), [name, ...argv], { stdio: 'inherit', diff --git a/apps/generator-cli/src/app/services/pass-through.service.ts b/apps/generator-cli/src/app/services/pass-through.service.ts index ac1264c5d..8c2673d45 100644 --- a/apps/generator-cli/src/app/services/pass-through.service.ts +++ b/apps/generator-cli/src/app/services/pass-through.service.ts @@ -3,6 +3,7 @@ import * as chalk from 'chalk' import {exec, spawn} from 'child_process' import {Command} from 'commander' import {isString, startsWith, trim} from 'lodash' +import * as os from 'os'; import {COMMANDER_PROGRAM, LOGGER} from '../constants' import {GeneratorService} from './generator.service' import {VersionManagerService} from './version-manager.service' @@ -117,8 +118,12 @@ export class PassThroughService { private cmd() { if (this.configService.useDocker) { + const userInfo = os.userInfo(); + const userArg = userInfo.uid !== -1 ? `--user ${userInfo.uid}:${userInfo.gid}` : ``; + return [ `docker run --rm -v "${this.configService.cwd}:/local"`, + userArg, this.versionManager.getDockerImageName(), ].join(' '); }