From d24b24a473a5ef0b1d66ecded07a68fecea59c9a Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 10 Aug 2020 19:13:36 +0200 Subject: [PATCH] feat(scaffolder): Default the user and group id to the same as the host process for docker reasons --- .../stages/templater/helpers.test.ts | 19 +++++++++++++++++++ .../scaffolder/stages/templater/helpers.ts | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/templater/helpers.test.ts b/plugins/scaffolder-backend/src/scaffolder/stages/templater/helpers.test.ts index e04ba48324..d5dd1cc561 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/templater/helpers.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/templater/helpers.test.ts @@ -126,6 +126,25 @@ describe('helpers', () => { ); }); + it('should pass through the user and group id from the host machine', async () => { + await runDockerContainer({ + imageName, + args, + templateDir, + resultDir, + dockerClient: mockDocker, + }); + + expect(mockDocker.run).toHaveBeenCalledWith( + imageName, + args, + expect.any(Stream), + expect.objectContaining({ + User: `${process.getuid()}:${process.getgid()}`, + }), + ); + }); + it('should pass through the log stream to the docker client', async () => { const logStream = new PassThrough(); await runDockerContainer({ diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/templater/helpers.ts b/plugins/scaffolder-backend/src/scaffolder/stages/templater/helpers.ts index 8d3e0eab3f..40bc0ac0c9 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/templater/helpers.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/templater/helpers.ts @@ -72,6 +72,10 @@ export const runDockerContainer = async ({ }); }); + // Files that are created inside the Docker container will be owned by + // root on the host system on non Mac systems, because of reasons. Mainly the fact that + // volume sharing is done using NFS on Mac and actual mounts in Linux world. + // So we set the user in the container as the same user and group id as the host. const User = `${process.getuid()}:${process.getgid()}`; const [{ Error: error, StatusCode: statusCode }] = await dockerClient.run(