@travetto/pack 3.2.5 → 3.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/pack",
3
- "version": "3.2.5",
3
+ "version": "3.2.6",
4
4
  "description": "Code packing utilities",
5
5
  "keywords": [
6
6
  "travetto",
@@ -4,6 +4,7 @@ import { path, RootIndex } from '@travetto/manifest';
4
4
  import { AppError, ExecUtil, ExecutionOptions } from '@travetto/base';
5
5
 
6
6
  import { ActiveShellCommand } from './shell';
7
+ import { DockerPackConfig } from './types';
7
8
 
8
9
  export class PackUtil {
9
10
  /**
@@ -77,4 +78,22 @@ export class PackUtil {
77
78
  throw new AppError(stderr || message || 'An unexpected error has occurred');
78
79
  }
79
80
  }
81
+
82
+ /**
83
+ * Generate a docker user creation command
84
+ */
85
+ static generateDockerUserCommand(cfg: DockerPackConfig): string {
86
+ const { user, group, uid, gid } = cfg.dockerRuntimeUser;
87
+ if (user !== 'root') {
88
+ return [
89
+ '',
90
+ `RUN which addgroup && \
91
+ ( addgroup -g ${gid} ${group} && adduser -S -u ${uid} ${user} ${group} ) || \
92
+ ( groupadd -g ${gid} ${group} && useradd -r -u ${uid} -g ${group} ${user} )`,
93
+ `USER ${user}`
94
+ ].join('\n');
95
+ } else {
96
+ return '';
97
+ }
98
+ }
80
99
  }
@@ -1,21 +1,9 @@
1
- import { DockerPackConfig, DockerPackFactory } from './bin/types';
2
-
3
- function buildRuntimeUser(cfg: DockerPackConfig): string {
4
- const { user, group, uid, gid } = cfg.dockerRuntimeUser;
5
- if (user !== 'root') {
6
- return [
7
- '',
8
- `RUN addgroup -g ${gid} ${group} && adduser -S -u ${uid} ${user} ${group}`,
9
- `USER ${user}`
10
- ].join('\n');
11
- } else {
12
- return '';
13
- }
14
- }
1
+ import { DockerPackFactory } from './bin/types';
2
+ import { PackUtil } from './bin/util';
15
3
 
16
4
  export const factory: DockerPackFactory = cfg => `
17
5
  FROM ${cfg.dockerImage}
18
- ${buildRuntimeUser(cfg)}
6
+ ${PackUtil.generateDockerUserCommand(cfg)}
19
7
  WORKDIR /app
20
8
  COPY . .
21
9
  ${cfg.dockerPort?.map(port => `EXPOSE ${port}`).join('\n') ?? ''}