@travetto/pack 3.4.4 → 3.4.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 ArcSine Technologies
3
+ Copyright (c) 2023 ArcSine Technologies
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -116,27 +116,28 @@ $ trv pack:docker --help
116
116
  Usage: pack:docker [options]
117
117
 
118
118
  Options:
119
- -w, --workspace <string> Workspace for building (default: "/tmp/<temp-folder>")
120
- --clean, --no-clean Clean workspace (default: true)
121
- -o, --output <string> Output location
122
- --main-scripts, --no-main-scripts Create entry scripts (default: true)
123
- -f, --main-name <string> Main name for build artifact
124
- -e, --entry-point <string> Entry point (default: "@travetto/cli/support/entry.trv")
125
- --minify, --no-minify Minify output (default: true)
126
- -sm, --sourcemap Bundle source maps (default: false)
127
- -is, --include-sources Include source with source maps (default: false)
128
- -x, --eject-file <string> Eject commands to file
129
- -r, --rollup-configuration <string> Rollup configuration file (default: "@travetto/pack/support/bin/rollup")
130
- -df, --docker-factory <string> Docker Factory source (default: "@travetto/pack/support/pack.dockerfile")
131
- -di, --docker-image <string> Docker Image to extend (default: "node:20-alpine")
132
- -dn, --docker-name <string> Docker Image Name (default: "travetto_pack")
133
- -dt, --docker-tag <string> Docker Image Tag (default: ["latest"])
134
- -dp, --docker-port <number> Docker Image Port (default: [])
135
- -dx, --docker-push Docker Push Tags (default: false)
136
- -dr, --docker-registry <string> Docker Registry
137
- -du, --docker-runtime-user <string> Docker Runtime user
138
- -m, --module <string> Module to run for
139
- -h, --help display help for command
119
+ -w, --workspace <string> Workspace for building (default: "/tmp/<temp-folder>")
120
+ --clean, --no-clean Clean workspace (default: true)
121
+ -o, --output <string> Output location
122
+ --main-scripts, --no-main-scripts Create entry scripts (default: true)
123
+ -f, --main-name <string> Main name for build artifact
124
+ -e, --entry-point <string> Entry point (default: "@travetto/cli/support/entry.trv")
125
+ --minify, --no-minify Minify output (default: true)
126
+ -sm, --sourcemap Bundle source maps (default: false)
127
+ -is, --include-sources Include source with source maps (default: false)
128
+ -x, --eject-file <string> Eject commands to file
129
+ -r, --rollup-configuration <string> Rollup configuration file (default: "@travetto/pack/support/bin/rollup")
130
+ -df, --docker-factory <string> Docker Factory source (default: "@travetto/pack/support/pack.dockerfile")
131
+ -di, --docker-image <string> Docker Image to extend (default: "node:20-alpine")
132
+ -dn, --docker-name <string> Docker Image Name (default: "travetto_pack")
133
+ -dt, --docker-tag <string> Docker Image Tag (default: ["latest"])
134
+ -dp, --docker-port <number> Docker Image Port (default: [])
135
+ -dx, --docker-push Docker Push Tags (default: false)
136
+ -db, --docker-build-platform <string> Docker Build Platform
137
+ -dr, --docker-registry <string> Docker Registry
138
+ -du, --docker-runtime-user <string> Docker Runtime user
139
+ -m, --module <string> Module to run for
140
+ -h, --help display help for command
140
141
  ```
141
142
 
142
143
  The additional flags provided are allow for specifying the base image, the final docker image name (and tags), and which registry to push to (if any). Additionally, there are flags for exposing which ports the image should expect to open as well. When using the `--eject-file` flag, the output script will produce the entire Dockerfile output inline, so that it can be easily modified as needed.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/pack",
3
- "version": "3.4.4",
3
+ "version": "3.4.6",
4
4
  "description": "Code packing utilities",
5
5
  "keywords": [
6
6
  "travetto",
@@ -28,11 +28,11 @@
28
28
  "@rollup/plugin-json": "^6.0.1",
29
29
  "@rollup/plugin-node-resolve": "^15.2.3",
30
30
  "@rollup/plugin-terser": "^0.4.4",
31
- "@travetto/base": "^3.4.0",
32
- "rollup": "^4.3.0"
31
+ "@travetto/base": "^3.4.1",
32
+ "rollup": "^4.5.0"
33
33
  },
34
34
  "peerDependencies": {
35
- "@travetto/cli": "^3.4.0"
35
+ "@travetto/cli": "^3.4.4"
36
36
  },
37
37
  "peerDependenciesMeta": {
38
38
  "@travetto/cli": {
@@ -14,28 +14,73 @@ export class PackConfigUtil {
14
14
  }
15
15
 
16
16
  /**
17
- * Common docker environment setup
17
+ * Setup docker ports
18
18
  */
19
- static dockerWorkspace(cfg: DockerPackConfig): string {
20
- const { folder, user, group, uid, gid } = cfg.dockerRuntime;
19
+ static dockerPorts(cfg: DockerPackConfig): string {
20
+ return (cfg.dockerPort?.map(x => `EXPOSE ${x}`) ?? []).join('\n');
21
+ }
22
+
23
+ /**
24
+ * Setup docker user
25
+ * @returns
26
+ */
27
+ static dockerUser(cfg: DockerPackConfig): string {
28
+ const { user, group, uid, gid } = cfg.dockerRuntime;
21
29
  return [
22
- ...cfg.dockerPort?.map(x => `EXPOSE ${x}`) ?? [],
23
30
  user !== 'root' ? ifElse(
24
31
  'RUN which useradd',
25
32
  `groupadd --gid ${gid} ${group} && useradd -u ${uid} -g ${group} ${user}`,
26
33
  `addgroup -g ${gid} ${group} && adduser -D -G ${group} -u ${uid} ${user}`
27
34
  ) : '',
28
- `RUN mkdir ${folder} && chown ${user}:${group} ${folder}`,
29
35
  `USER ${user}`,
36
+ ].join('\n');
37
+ }
38
+
39
+ /**
40
+ * Common docker runtime folder
41
+ */
42
+ static dockerAppFolder(cfg: DockerPackConfig): string {
43
+ const { folder, user, group } = cfg.dockerRuntime;
44
+ return [
45
+ `RUN mkdir ${folder} && chown ${user}:${group} ${folder}`,
30
46
  `WORKDIR ${folder}`,
31
- `COPY --chown="${user}:${group}" . .`,
32
47
  ].join('\n');
33
48
  }
34
49
 
50
+ /**
51
+ * Docker app files copied and permissioned
52
+ */
53
+ static dockerAppFiles(cfg: DockerPackConfig): string {
54
+ const { user, group } = cfg.dockerRuntime;
55
+ return `COPY --chown="${user}:${group}" . .`;
56
+ }
57
+
35
58
  /**
36
59
  * Entrypoint creation for a docker configuration
37
60
  */
38
61
  static dockerEntrypoint(cfg: DockerPackConfig): string {
39
62
  return `ENTRYPOINT ["${cfg.dockerRuntime.folder}/${cfg.mainName}.sh"]`;
40
63
  }
64
+ /**
65
+ * Common docker environment setup
66
+ */
67
+ static dockerWorkspace(cfg: DockerPackConfig): string {
68
+ return [
69
+ this.dockerPorts(cfg),
70
+ this.dockerUser(cfg),
71
+ this.dockerAppFolder(cfg),
72
+ this.dockerAppFiles(cfg),
73
+ ].filter(x => !!x).join('\n');
74
+ }
75
+
76
+ /**
77
+ * Common docker file setup
78
+ */
79
+ static dockerStandardFile(cfg: DockerPackConfig): string {
80
+ return [
81
+ this.dockerInit(cfg),
82
+ this.dockerWorkspace(cfg),
83
+ this.dockerEntrypoint(cfg)
84
+ ].join('\n');
85
+ }
41
86
  }
@@ -19,7 +19,7 @@ export type CommonPackConfig = {
19
19
 
20
20
  export type DockerPackConfig = {
21
21
  dockerFactory: string;
22
- dockerBuildPlatform: string;
22
+ dockerBuildPlatform?: string;
23
23
  dockerImage: string;
24
24
  dockerName: string;
25
25
  dockerTag?: string[];
@@ -27,7 +27,7 @@ export class PackDockerCommand extends BasePackCommand {
27
27
  dockerPort: number[] = [];
28
28
  @CliFlag({ desc: 'Docker Push Tags ', short: 'dx', envVars: ['PACK_DOCKER_PUSH'] })
29
29
  dockerPush = false;
30
- @CliFlag({ desc: 'Docker Build Platform ', short: 'dr', envVars: ['PACK_DOCKER_BUILD_PLATFORM'] })
30
+ @CliFlag({ desc: 'Docker Build Platform ', short: 'db', envVars: ['PACK_DOCKER_BUILD_PLATFORM'] })
31
31
  dockerBuildPlatform?: string;
32
32
  @CliFlag({ desc: 'Docker Registry ', short: 'dr', envVars: ['PACK_DOCKER_REGISTRY'] })
33
33
  dockerRegistry?: string;
@@ -1,8 +1,4 @@
1
1
  import { DockerPackFactory } from './bin/types';
2
2
  import { PackConfigUtil } from './bin/config-util';
3
3
 
4
- export const factory: DockerPackFactory = cfg => [
5
- PackConfigUtil.dockerInit(cfg),
6
- PackConfigUtil.dockerWorkspace(cfg),
7
- PackConfigUtil.dockerEntrypoint(cfg),
8
- ].join('\n');
4
+ export const factory: DockerPackFactory = cfg => PackConfigUtil.dockerStandardFile(cfg);