@travetto/pack 3.2.5 → 3.2.7

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/__index__.ts CHANGED
@@ -1 +1,2 @@
1
- export type { CommonPackConfig, DockerPackFactory, DockerPackConfig } from './support/bin/types';
1
+ export type { CommonPackConfig, DockerPackFactory, DockerPackConfig } from './support/bin/types';
2
+ export { PackConfigUtil } from './support/bin/config-util';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/pack",
3
- "version": "3.2.5",
3
+ "version": "3.2.7",
4
4
  "description": "Code packing utilities",
5
5
  "keywords": [
6
6
  "travetto",
@@ -0,0 +1,24 @@
1
+ import { DockerPackConfig } from './types';
2
+
3
+ /**
4
+ * Common utils for setting up pack config
5
+ */
6
+ export class PackConfigUtil {
7
+ /**
8
+ * Generate a docker user creation command
9
+ */
10
+ static dockerUserCommand(cfg: DockerPackConfig): string {
11
+ const { user, group, uid, gid } = cfg.dockerRuntimeUser;
12
+ if (user !== 'root') {
13
+ return [
14
+ '',
15
+ `RUN which addgroup && \
16
+ ( addgroup -g ${gid} ${group} && adduser -S -u ${uid} ${user} ${group} ) || \
17
+ ( groupadd -g ${gid} ${group} && useradd -r -u ${uid} -g ${group} ${user} )`,
18
+ `USER ${user}`
19
+ ].join('\n');
20
+ } else {
21
+ return '';
22
+ }
23
+ }
24
+ }
@@ -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 { PackConfigUtil } from './bin/config-util';
15
3
 
16
4
  export const factory: DockerPackFactory = cfg => `
17
5
  FROM ${cfg.dockerImage}
18
- ${buildRuntimeUser(cfg)}
6
+ ${PackConfigUtil.dockerUserCommand(cfg)}
19
7
  WORKDIR /app
20
8
  COPY . .
21
9
  ${cfg.dockerPort?.map(port => `EXPOSE ${port}`).join('\n') ?? ''}