UNPKG

1.75 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const shell_1 = require("./shell");
4function generateRunArgs(ctx, image, env = {}) {
5 const environment = ctx.env.require('ENVIRONMENT');
6 let runArgs = [
7 'run',
8 '--rm',
9 '--memory', '4g',
10 '--memory-reservation', '2g',
11 '-v', `${ctx.codedir}:/usr/src/app`,
12 '-v', `${ctx.codedir}/.home:/home/gitlab-runner`,
13 ];
14 if (environment !== 'DEVELOPMENT') {
15 const sharedUserOpts = [
16 '-u', `${process.getuid()}:${process.getgid()}`,
17 '-v', '/etc/group:/etc/group:ro',
18 '-v', '/etc/passwd:/etc/passwd:ro',
19 ];
20 runArgs = runArgs.concat(sharedUserOpts);
21 }
22 for (let [k, v] of Object.entries(env)) {
23 runArgs.push('-e');
24 runArgs.push(`${k}=${v}`);
25 }
26 runArgs.push(image);
27 return runArgs;
28}
29exports.generateRunArgs = generateRunArgs;
30async function prettyUserCommand(ctx, image, args, env = {}) {
31 const actualArgs = args.map(arg => typeof arg === 'string' ? arg : arg[0]);
32 const visualArgs = args.map(arg => {
33 if (typeof arg === 'string') {
34 return arg;
35 }
36 const [, visual] = arg;
37 return visual;
38 });
39 const argv = shell_1.prettyArgv(visualArgs);
40 ctx.userlog.info(ctx.c.magenta(`$ ${argv}`));
41 const runArgs = generateRunArgs(ctx, image, env);
42 try {
43 await shell_1.runcmd({ outlog: ctx.userlog }, 'docker', [...runArgs, ...actualArgs], { cwd: ctx.codedir });
44 ctx.userlog.info(ctx.c.green(`$ ${argv} success`));
45 }
46 catch (e) {
47 ctx.userlog.error(ctx.c.red(`${argv} failed`));
48 throw e;
49 }
50}
51exports.prettyUserCommand = prettyUserCommand;