@travetto/pack 8.0.0-alpha.9 → 8.0.1
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/README.md +44 -20
- package/__index__.ts +2 -2
- package/package.json +19 -19
- package/src/config-util.ts +26 -25
- package/src/types.ts +4 -4
- package/support/bin/docker-operation.ts +39 -19
- package/support/bin/operation.ts +48 -55
- package/support/bin/preamble.ts +12 -5
- package/support/bin/shell.ts +38 -41
- package/support/bin/util.ts +21 -13
- package/support/cli.pack.ts +6 -3
- package/support/cli.pack_docker.ts +13 -12
- package/support/cli.pack_zip.ts +7 -8
- package/support/pack.base.ts +15 -18
- package/support/pack.dockerfile.ts +2 -2
- package/support/rollup/build.ts +3 -3
- package/support/rollup/config.ts +15 -14
- package/support/rollup/rollup-travetto-entry.ts +3 -2
- package/support/rollup/rollup-travetto-import.ts +4 -4
- package/support/rollup/rollup-travetto-sourcemaps.ts +9 -11
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ npm install @travetto/pack
|
|
|
13
13
|
yarn add @travetto/pack
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
This module provides the necessary tools to produce deliverable output for [Travetto](https://travetto.dev) based projects.
|
|
16
|
+
This module provides the necessary tools to produce deliverable output for [Travetto](https://travetto.dev) based projects. The main interaction with this module is through the command line interface, and the operations it provides. Under the covers, the code bundling is performed by [Rollup](https://rollupjs.org/), with specific configuration to support the frameworks runtime expectations.
|
|
17
17
|
|
|
18
18
|
There are three primary cli commands for packing your code:
|
|
19
19
|
* pack
|
|
@@ -22,12 +22,18 @@ There are three primary cli commands for packing your code:
|
|
|
22
22
|
|
|
23
23
|
## CLI - pack
|
|
24
24
|
|
|
25
|
-
**Terminal:
|
|
25
|
+
**Terminal: Help for pack**
|
|
26
26
|
```bash
|
|
27
27
|
$ trv pack --help
|
|
28
28
|
|
|
29
29
|
Usage: pack [options] [args...:string]
|
|
30
30
|
|
|
31
|
+
Description:
|
|
32
|
+
Build a standard module package artifact.
|
|
33
|
+
|
|
34
|
+
This base command produces the default packaged output and serves as the
|
|
35
|
+
common entry point for module packaging workflows.
|
|
36
|
+
|
|
31
37
|
Options:
|
|
32
38
|
-b, --buildDir <string> Workspace for building (default: "/tmp/<temp-folder>")
|
|
33
39
|
--clean, --no-clean Clean workspace (default: true)
|
|
@@ -46,6 +52,8 @@ Options:
|
|
|
46
52
|
-np, --npm-package <string> External NPM Packages (default: [])
|
|
47
53
|
-m, --module <module> Module to run for
|
|
48
54
|
--help display help for command
|
|
55
|
+
|
|
56
|
+
Examples:
|
|
49
57
|
```
|
|
50
58
|
|
|
51
59
|
This command line operation will compile your project, and produce a ready to use workspace as a deliverable. Additionally, you can pass in a file to the `eject-file` flag that will allow for a script to be produced (base on the host operating system).
|
|
@@ -53,7 +61,7 @@ This command line operation will compile your project, and produce a ready to us
|
|
|
53
61
|
Specific to this CLI command, the `output` field determines where the final folder is written that contains all the compiled source.
|
|
54
62
|
|
|
55
63
|
### Entry Point Configuration
|
|
56
|
-
Every application requires an entry point to determine execution flow (and in [Rollup](https://rollupjs.org/)'s case, tree-shaking as well.).
|
|
64
|
+
Every application requires an entry point to determine execution flow (and in [Rollup](https://rollupjs.org/)'s case, tree-shaking as well.). By default the [Command Line Interface](https://github.com/travetto/travetto/tree/main/module/cli#readme "CLI infrastructure for Travetto framework") acts as the entry point. This bypasses the [Compiler](https://github.com/travetto/travetto/tree/main/module/compiler#readme "The compiler infrastructure for the Travetto framework") intentionally, as the compiler is not available at runtime.
|
|
57
65
|
|
|
58
66
|
Within the command line, the `args` are positional arguments that will be passed to the entry point on application run.
|
|
59
67
|
|
|
@@ -77,23 +85,29 @@ And this entry point would be what is executed by [docker](https://www.docker.co
|
|
|
77
85
|
### General Packing Operations
|
|
78
86
|
Every [Pack](https://github.com/travetto/travetto/tree/main/module/pack#readme "Code packing utilities") operation extends from the base command, and that provides some consistent operations that run on every packing command.
|
|
79
87
|
* `clean` - Empties workspace before beginning, controlled by the `--clean` flag, defaults to on
|
|
80
|
-
* `writeEnv` - Writes the .env.js files that includes the necessary details to start the application.
|
|
88
|
+
* `writeEnv` - Writes the .env.js files that includes the necessary details to start the application. This is primarily to identify the location of the manifest file needed to run.
|
|
81
89
|
* `writePackageJson` - Generates the [Package JSON](https://docs.npmjs.com/cli/v9/configuring-npm/package-json) with the appropriate module type ([CommonJS](https://nodejs.org/api/modules.html) or [Ecmascript Module](https://nodejs.org/api/esm.html)) for interpreting plain `.js` files
|
|
82
90
|
* `writeEntryScript` - Create the entry script based on the `--entry-command`, `args`
|
|
83
91
|
* `copyResources` - Will pull in local `resources/**` files into the final output
|
|
84
|
-
* `primeAppCache` - Runs `trv run` to ensure the appropriate files are generated to allow for running the application.
|
|
85
|
-
* `writeManifest` - Produces the `production`-ready manifest that is used at runtime.
|
|
86
|
-
* `bundle` - Invokes [Rollup](https://rollupjs.org/) with the appropriate file set to produce a single output .js file.
|
|
92
|
+
* `primeAppCache` - Runs `trv run` to ensure the appropriate files are generated to allow for running the application. This only applies if the entry point is equivalent to `trv run`
|
|
93
|
+
* `writeManifest` - Produces the `production`-ready manifest that is used at runtime. Removes all devDependencies from the manifest.json
|
|
94
|
+
* `bundle` - Invokes [Rollup](https://rollupjs.org/) with the appropriate file set to produce a single output .js file. Depending on the module type ([CommonJS](https://nodejs.org/api/modules.html) or [Ecmascript Module](https://nodejs.org/api/esm.html)) the build process differs to handle the dynamic loading that application does at runtime.
|
|
87
95
|
|
|
88
96
|
## CLI - pack:zip
|
|
89
|
-
This command is nearly identical to the standard `pack` operation, except for the `output` flag.
|
|
97
|
+
This command is nearly identical to the standard `pack` operation, except for the `output` flag. In this scenario, the `output` flag determines the location and name of the final zip file.
|
|
90
98
|
|
|
91
|
-
**Terminal:
|
|
99
|
+
**Terminal: Help for pack:zip**
|
|
92
100
|
```bash
|
|
93
101
|
$ trv pack:zip --help
|
|
94
102
|
|
|
95
103
|
Usage: pack:zip [options] [args...:string]
|
|
96
104
|
|
|
105
|
+
Description:
|
|
106
|
+
Build a deployable zip artifact using the standard pack pipeline.
|
|
107
|
+
|
|
108
|
+
This command runs base packing operations and then compresses the generated
|
|
109
|
+
output into a single archive file.
|
|
110
|
+
|
|
97
111
|
Options:
|
|
98
112
|
-b, --buildDir <string> Workspace for building (default: "/tmp/<temp-folder>")
|
|
99
113
|
--clean, --no-clean Clean workspace (default: true)
|
|
@@ -112,17 +126,25 @@ Options:
|
|
|
112
126
|
-np, --npm-package <string> External NPM Packages (default: [])
|
|
113
127
|
-m, --module <module> Module to run for
|
|
114
128
|
--help display help for command
|
|
129
|
+
|
|
130
|
+
Examples:
|
|
115
131
|
```
|
|
116
132
|
|
|
117
133
|
## CLI - pack:docker
|
|
118
134
|
This command starts off identical to the standard `pack` operation, but it contains a few additional flags, and ultimately a few additional operations to support creating of the final [docker](https://www.docker.com/community-edition) image.
|
|
119
135
|
|
|
120
|
-
**Terminal:
|
|
136
|
+
**Terminal: Help for pack:docker**
|
|
121
137
|
```bash
|
|
122
138
|
$ trv pack:docker --help
|
|
123
139
|
|
|
124
140
|
Usage: pack:docker [options] [args...:string]
|
|
125
141
|
|
|
142
|
+
Description:
|
|
143
|
+
Build container-ready artifacts and optionally publish Docker images.
|
|
144
|
+
|
|
145
|
+
Extends the core pack pipeline with Dockerfile generation and image build/
|
|
146
|
+
push operations, including runtime user and registry customization.
|
|
147
|
+
|
|
126
148
|
Options:
|
|
127
149
|
-b, --buildDir <string> Workspace for building (default: "/tmp/<temp-folder>")
|
|
128
150
|
--clean, --no-clean Clean workspace (default: true)
|
|
@@ -141,7 +163,7 @@ Options:
|
|
|
141
163
|
-np, --npm-package <string> External NPM Packages (default: [])
|
|
142
164
|
-m, --module <module> Module to run for
|
|
143
165
|
-df, --docker-factory <string> Docker Factory source (default: "@travetto/pack/support/pack.dockerfile.ts")
|
|
144
|
-
-di, --docker-image <string> Docker Image to extend (default: "node:
|
|
166
|
+
-di, --docker-image <string> Docker Image to extend (default: "node:26-alpine")
|
|
145
167
|
-dn, --docker-name <string> Docker Image Name (default: "<module>")
|
|
146
168
|
-ru, --runtime-user <string> Docker Runtime user
|
|
147
169
|
-rp, --runtime-package <string> Docker Runtime Packages (default: [])
|
|
@@ -152,18 +174,20 @@ Options:
|
|
|
152
174
|
-db, --docker-build-platform <string> Docker Build Platform
|
|
153
175
|
-dr, --docker-registry <string> Docker Registry
|
|
154
176
|
--help display help for command
|
|
177
|
+
|
|
178
|
+
Examples:
|
|
155
179
|
```
|
|
156
180
|
|
|
157
|
-
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
|
|
181
|
+
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.
|
|
158
182
|
|
|
159
183
|
In addition to the standard operations, this command adds the following steps:
|
|
160
184
|
* `writeDockerFile` - Generate the docker file contents
|
|
161
185
|
* `pullDockerBaseImage` - Pull base image, to ensure its available and primed
|
|
162
186
|
* `buildDockerContainer` - Build final container
|
|
163
|
-
* `pushDockerContainer` - Push container with appropriate tags.
|
|
187
|
+
* `pushDockerContainer` - Push container with appropriate tags. Only applies if `--docker-push` is specified
|
|
164
188
|
|
|
165
189
|
## Ejected File
|
|
166
|
-
As indicated, any of the pack operations can be ejected, and produce an output that can be run independent of the pack command.
|
|
190
|
+
As indicated, any of the pack operations can be ejected, and produce an output that can be run independent of the pack command. This is helpful when integrating with more complicated build processes.
|
|
167
191
|
|
|
168
192
|
**Terminal: Sample Ejected File**
|
|
169
193
|
```bash
|
|
@@ -244,21 +268,21 @@ cd $TRV_OUT
|
|
|
244
268
|
node $REPO_ROOT/node_modules/.bin/rollup -c $TRV_OUT/node_modules/@travetto/pack/support/rollup/build.js
|
|
245
269
|
cd $ROOT
|
|
246
270
|
|
|
247
|
-
# Pulling Docker Base Image node:
|
|
271
|
+
# Pulling Docker Base Image node:26-alpine
|
|
248
272
|
|
|
249
|
-
echo "Pulling Docker Base Image node:
|
|
273
|
+
echo "Pulling Docker Base Image node:26-alpine"
|
|
250
274
|
|
|
251
|
-
docker pull node:
|
|
275
|
+
docker pull node:26-alpine
|
|
252
276
|
|
|
253
|
-
# Detected Image OS node:
|
|
277
|
+
# Detected Image OS node:26-alpine as alpine
|
|
254
278
|
|
|
255
|
-
echo "Detected Image OS node:
|
|
279
|
+
echo "Detected Image OS node:26-alpine as alpine"
|
|
256
280
|
|
|
257
281
|
# Generating Docker File $DIST/Dockerfile @travetto/pack/support/pack.dockerfile.ts
|
|
258
282
|
|
|
259
283
|
echo "Generating Docker File $DIST/Dockerfile @travetto/pack/support/pack.dockerfile.ts"
|
|
260
284
|
|
|
261
|
-
echo "FROM node:
|
|
285
|
+
echo "FROM node:26-alpine" > $DIST/Dockerfile
|
|
262
286
|
echo "RUN addgroup -g 2000 app && adduser -D -G app -u 2000 app" >> $DIST/Dockerfile
|
|
263
287
|
echo "RUN mkdir /app && chown app:app /app" >> $DIST/Dockerfile
|
|
264
288
|
echo "COPY --chown=\"app:app\" . /app" >> $DIST/Dockerfile
|
package/__index__.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export {
|
|
1
|
+
export { PackConfigUtil } from './src/config-util.ts';
|
|
2
|
+
export type { CommonPackConfig, DockerPackConfig, DockerPackFactory } from './src/types.ts';
|
package/package.json
CHANGED
|
@@ -1,41 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/pack",
|
|
3
|
-
"version": "8.0.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "8.0.1",
|
|
5
4
|
"description": "Code packing utilities",
|
|
6
5
|
"keywords": [
|
|
7
|
-
"
|
|
8
|
-
"typescript",
|
|
6
|
+
"docker",
|
|
9
7
|
"packing",
|
|
10
|
-
"
|
|
8
|
+
"travetto",
|
|
9
|
+
"typescript"
|
|
11
10
|
],
|
|
12
11
|
"homepage": "https://travetto.io",
|
|
13
12
|
"license": "MIT",
|
|
14
13
|
"author": {
|
|
15
|
-
"
|
|
16
|
-
"
|
|
14
|
+
"name": "Travetto Framework",
|
|
15
|
+
"email": "travetto.framework@gmail.com"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"url": "git+https://github.com/travetto/travetto.git",
|
|
19
|
+
"directory": "module/pack"
|
|
17
20
|
},
|
|
18
|
-
"main": "__index__.ts",
|
|
19
21
|
"files": [
|
|
20
22
|
"__index__.ts",
|
|
21
23
|
"src",
|
|
22
24
|
"support"
|
|
23
25
|
],
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "__index__.ts",
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
27
30
|
},
|
|
28
31
|
"dependencies": {
|
|
29
|
-
"@rollup/plugin-commonjs": "^29.0.
|
|
32
|
+
"@rollup/plugin-commonjs": "^29.0.3",
|
|
30
33
|
"@rollup/plugin-json": "^6.1.0",
|
|
31
34
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
32
35
|
"@rollup/plugin-terser": "^1.0.0",
|
|
33
|
-
"@travetto/runtime": "^8.0.
|
|
34
|
-
"@travetto/terminal": "^8.0.
|
|
35
|
-
"rollup": "^4.
|
|
36
|
+
"@travetto/runtime": "^8.0.1",
|
|
37
|
+
"@travetto/terminal": "^8.0.1",
|
|
38
|
+
"rollup": "^4.63.1"
|
|
36
39
|
},
|
|
37
40
|
"peerDependencies": {
|
|
38
|
-
"@travetto/cli": "^8.0.
|
|
41
|
+
"@travetto/cli": "^8.0.1"
|
|
39
42
|
},
|
|
40
43
|
"peerDependenciesMeta": {
|
|
41
44
|
"@travetto/cli": {
|
|
@@ -47,8 +50,5 @@
|
|
|
47
50
|
"roles": [
|
|
48
51
|
"build"
|
|
49
52
|
]
|
|
50
|
-
},
|
|
51
|
-
"publishConfig": {
|
|
52
|
-
"access": "public"
|
|
53
53
|
}
|
|
54
54
|
}
|
package/src/config-util.ts
CHANGED
|
@@ -18,11 +18,14 @@ export class PackConfigUtil {
|
|
|
18
18
|
const { os, packages } = config.dockerRuntime;
|
|
19
19
|
if (packages?.length) {
|
|
20
20
|
switch (os) {
|
|
21
|
-
case 'alpine':
|
|
22
|
-
|
|
23
|
-
case '
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
case 'alpine':
|
|
22
|
+
return `RUN apk --update add ${packages.join(' ')} && rm -rf /var/cache/apk/*`;
|
|
23
|
+
case 'debian':
|
|
24
|
+
return `RUN apt update && apt install -y ${packages.join(' ')} && rm -rf /var/lib/{apt,dpkg,cache,log}/`;
|
|
25
|
+
case 'centos':
|
|
26
|
+
return `RUN yum -y install ${packages.join(' ')} && yum -y clean all && rm -fr /var/cache`;
|
|
27
|
+
default:
|
|
28
|
+
throw new Error('Unable to install packages in an unknown os');
|
|
26
29
|
}
|
|
27
30
|
} else {
|
|
28
31
|
return '';
|
|
@@ -38,9 +41,11 @@ export class PackConfigUtil {
|
|
|
38
41
|
const [name, directive] = item.split(':');
|
|
39
42
|
switch (directive) {
|
|
40
43
|
case 'from-source':
|
|
41
|
-
out.push(`RUN npm_config_build_from_source=true npm install ${name} --build-from-source`);
|
|
44
|
+
out.push(`RUN npm_config_build_from_source=true npm install ${name} --build-from-source`);
|
|
45
|
+
break;
|
|
42
46
|
default:
|
|
43
|
-
out.push(`RUN npm install ${name}`);
|
|
47
|
+
out.push(`RUN npm install ${name}`);
|
|
48
|
+
break;
|
|
44
49
|
}
|
|
45
50
|
}
|
|
46
51
|
if (out.length) {
|
|
@@ -65,11 +70,13 @@ export class PackConfigUtil {
|
|
|
65
70
|
return '';
|
|
66
71
|
} else {
|
|
67
72
|
switch (os) {
|
|
68
|
-
case 'alpine':
|
|
73
|
+
case 'alpine':
|
|
74
|
+
return `RUN addgroup -g ${groupId} ${group} && adduser -D -G ${group} -u ${userId} ${user}`;
|
|
69
75
|
case 'debian':
|
|
70
|
-
case 'centos':
|
|
71
|
-
|
|
72
|
-
default:
|
|
76
|
+
case 'centos':
|
|
77
|
+
return `RUN groupadd --gid ${groupId} ${group} && useradd -u ${userId} -g ${group} ${user}`;
|
|
78
|
+
default:
|
|
79
|
+
throw new Error('Unable to add user/group for an unknown os');
|
|
73
80
|
}
|
|
74
81
|
}
|
|
75
82
|
}
|
|
@@ -78,9 +85,7 @@ export class PackConfigUtil {
|
|
|
78
85
|
* Setup Env Vars for NODE_OPTIONS and other standard environment variables
|
|
79
86
|
*/
|
|
80
87
|
static dockerEnvVars(config: DockerPackConfig): string {
|
|
81
|
-
return [
|
|
82
|
-
`ENV NODE_OPTIONS="${[...(config.sourcemap ? ['--enable-source-maps'] : [])].join(' ')}"`,
|
|
83
|
-
].join('\n');
|
|
88
|
+
return [`ENV NODE_OPTIONS="${[...(config.sourcemap ? ['--enable-source-maps'] : [])].join(' ')}"`].join('\n');
|
|
84
89
|
}
|
|
85
90
|
|
|
86
91
|
/**
|
|
@@ -88,9 +93,7 @@ export class PackConfigUtil {
|
|
|
88
93
|
*/
|
|
89
94
|
static dockerAppFolder(config: DockerPackConfig): string {
|
|
90
95
|
const { folder, user, group } = config.dockerRuntime;
|
|
91
|
-
return [
|
|
92
|
-
`RUN mkdir ${folder} && chown ${user}:${group} ${folder}`,
|
|
93
|
-
].join('\n');
|
|
96
|
+
return [`RUN mkdir ${folder} && chown ${user}:${group} ${folder}`].join('\n');
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
/**
|
|
@@ -106,11 +109,7 @@ export class PackConfigUtil {
|
|
|
106
109
|
*/
|
|
107
110
|
static dockerEntrypoint(config: DockerPackConfig): string {
|
|
108
111
|
const { user, folder } = config.dockerRuntime;
|
|
109
|
-
return [
|
|
110
|
-
`USER ${user}`,
|
|
111
|
-
`WORKDIR ${folder}`,
|
|
112
|
-
`ENTRYPOINT ["${folder}/${config.mainName}.sh"]`,
|
|
113
|
-
].join('\n');
|
|
112
|
+
return [`USER ${user}`, `WORKDIR ${folder}`, `ENTRYPOINT ["${folder}/${config.mainName}.sh"]`].join('\n');
|
|
114
113
|
}
|
|
115
114
|
/**
|
|
116
115
|
* Common docker environment setup
|
|
@@ -122,8 +121,10 @@ export class PackConfigUtil {
|
|
|
122
121
|
this.dockerPackageInstall(config),
|
|
123
122
|
this.dockerAppFolder(config),
|
|
124
123
|
this.dockerAppFiles(config),
|
|
125
|
-
this.dockerEnvVars(config)
|
|
126
|
-
]
|
|
124
|
+
this.dockerEnvVars(config)
|
|
125
|
+
]
|
|
126
|
+
.filter(line => !!line)
|
|
127
|
+
.join('\n');
|
|
127
128
|
}
|
|
128
129
|
|
|
129
130
|
/**
|
|
@@ -137,4 +138,4 @@ export class PackConfigUtil {
|
|
|
137
138
|
this.dockerEntrypoint(config)
|
|
138
139
|
].join('\n');
|
|
139
140
|
}
|
|
140
|
-
}
|
|
141
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type OutputOptions } from 'rollup';
|
|
2
1
|
import type terser from '@rollup/plugin-terser';
|
|
2
|
+
import type { OutputOptions } from 'rollup';
|
|
3
3
|
|
|
4
4
|
export type CommonPackConfig = {
|
|
5
5
|
buildDirectory: string;
|
|
@@ -59,10 +59,10 @@ export type ShellCommandProvider = {
|
|
|
59
59
|
comment(message: string): string[];
|
|
60
60
|
echo(text: string): string[];
|
|
61
61
|
zip(output: string): string[];
|
|
62
|
-
script(lines: string[], chdir?: boolean): { ext: string
|
|
62
|
+
script(lines: string[], chdir?: boolean): { ext: string; contents: string[] };
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
-
export type DockerPackFactory = (config: DockerPackConfig) =>
|
|
65
|
+
export type DockerPackFactory = (config: DockerPackConfig) => string | Promise<string>;
|
|
66
66
|
export type DockerPackFactoryModule = { factory: DockerPackFactory };
|
|
67
67
|
|
|
68
68
|
export type CoreRollupConfig = {
|
|
@@ -73,4 +73,4 @@ export type CoreRollupConfig = {
|
|
|
73
73
|
ignore: Set<string>;
|
|
74
74
|
external: string[];
|
|
75
75
|
minify: Parameters<typeof terser>[0];
|
|
76
|
-
};
|
|
76
|
+
};
|
|
@@ -1,46 +1,64 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
|
-
import { JSONUtil, Runtime } from '@travetto/runtime';
|
|
5
4
|
import { cliTpl } from '@travetto/cli';
|
|
5
|
+
import { JSONUtil, Runtime } from '@travetto/runtime';
|
|
6
6
|
|
|
7
|
-
import { ActiveShellCommand } from './shell.ts';
|
|
8
7
|
import type { DockerPackConfig, DockerPackFactoryModule } from '../../src/types.ts';
|
|
9
8
|
import { PackOperation } from './operation.ts';
|
|
9
|
+
import { ActiveShellCommand } from './shell.ts';
|
|
10
10
|
import { PackUtil } from './util.ts';
|
|
11
11
|
|
|
12
12
|
export class DockerPackOperation {
|
|
13
|
-
|
|
14
13
|
static getDockerTags(config: DockerPackConfig): string[] {
|
|
15
|
-
return (config.dockerTag ?? []).map(tag =>
|
|
14
|
+
return (config.dockerTag ?? []).map(tag =>
|
|
15
|
+
config.dockerRegistry ? `${config.dockerRegistry}/${config.dockerName}:${tag}` : `${config.dockerName}:${tag}`
|
|
16
|
+
);
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Detect image os
|
|
20
21
|
*/
|
|
21
|
-
static async*
|
|
22
|
+
static async *detectDockerImageOs(config: DockerPackConfig): AsyncIterable<string[]> {
|
|
22
23
|
// Read os before writing
|
|
23
|
-
config.dockerRuntime.os = await PackUtil.runCommand(
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
config.dockerRuntime.os = await PackUtil.runCommand([
|
|
25
|
+
'docker',
|
|
26
|
+
'run',
|
|
27
|
+
'--rm',
|
|
28
|
+
'--entrypoint',
|
|
29
|
+
'/bin/sh',
|
|
30
|
+
config.dockerImage,
|
|
31
|
+
'-c',
|
|
32
|
+
'cat /etc/*release*'
|
|
33
|
+
]).then(out => {
|
|
26
34
|
const found = out.toLowerCase().match(/\b(?:debian|alpine|centos)\b/)?.[0];
|
|
27
35
|
switch (found) {
|
|
28
|
-
case 'debian':
|
|
29
|
-
|
|
36
|
+
case 'debian':
|
|
37
|
+
case 'alpine':
|
|
38
|
+
case 'centos':
|
|
39
|
+
return found;
|
|
40
|
+
default:
|
|
41
|
+
return 'unknown';
|
|
30
42
|
}
|
|
31
43
|
});
|
|
32
|
-
yield* PackOperation.title(
|
|
44
|
+
yield* PackOperation.title(
|
|
45
|
+
config,
|
|
46
|
+
cliTpl`${{ title: 'Detected Image OS' }} ${{ param: config.dockerImage }} as ${{ param: config.dockerRuntime.os }}`
|
|
47
|
+
);
|
|
33
48
|
}
|
|
34
49
|
|
|
35
50
|
/**
|
|
36
51
|
* Write Docker File
|
|
37
52
|
*/
|
|
38
|
-
static async*
|
|
53
|
+
static async *writeDockerFile(config: DockerPackConfig): AsyncIterable<string[]> {
|
|
39
54
|
const dockerFile = path.resolve(config.buildDirectory, 'Dockerfile');
|
|
40
55
|
const { factory } = await Runtime.importFrom<DockerPackFactoryModule>(config.dockerFactory);
|
|
41
56
|
const content = (await factory(config)).trim();
|
|
42
57
|
|
|
43
|
-
yield* PackOperation.title(
|
|
58
|
+
yield* PackOperation.title(
|
|
59
|
+
config,
|
|
60
|
+
cliTpl`${{ title: 'Generating Docker File' }} ${{ path: dockerFile }} ${{ param: config.dockerFactory }}`
|
|
61
|
+
);
|
|
44
62
|
|
|
45
63
|
if (config.ejectFile) {
|
|
46
64
|
yield* ActiveShellCommand.createFile(dockerFile, content.split(/\n/));
|
|
@@ -52,7 +70,7 @@ export class DockerPackOperation {
|
|
|
52
70
|
/**
|
|
53
71
|
* Pull Docker Base Image
|
|
54
72
|
*/
|
|
55
|
-
static async*
|
|
73
|
+
static async *pullDockerBaseImage(config: DockerPackConfig): AsyncIterable<string[]> {
|
|
56
74
|
const command = ['docker', 'pull', config.dockerImage];
|
|
57
75
|
|
|
58
76
|
yield* PackOperation.title(config, cliTpl`${{ title: 'Pulling Docker Base Image' }} ${{ param: config.dockerImage }}`);
|
|
@@ -67,11 +85,13 @@ export class DockerPackOperation {
|
|
|
67
85
|
/**
|
|
68
86
|
* Building Docker Container
|
|
69
87
|
*/
|
|
70
|
-
static async*
|
|
88
|
+
static async *buildDockerContainer(config: DockerPackConfig): AsyncIterable<string[]> {
|
|
71
89
|
const cmd = [
|
|
72
|
-
'docker',
|
|
90
|
+
'docker',
|
|
91
|
+
'build',
|
|
73
92
|
...(config.dockerBuildPlatform ? ['--platform', config.dockerBuildPlatform] : []),
|
|
74
|
-
...DockerPackOperation.getDockerTags(config).flatMap(tag => ['-t', tag]),
|
|
93
|
+
...DockerPackOperation.getDockerTags(config).flatMap(tag => ['-t', tag]),
|
|
94
|
+
'.'
|
|
75
95
|
];
|
|
76
96
|
|
|
77
97
|
yield* PackOperation.title(config, cliTpl`${{ title: 'Building Docker Container' }} ${{ param: config.dockerTag?.join(',') }}`);
|
|
@@ -90,7 +110,7 @@ export class DockerPackOperation {
|
|
|
90
110
|
/**
|
|
91
111
|
* Push Docker Container
|
|
92
112
|
*/
|
|
93
|
-
static async*
|
|
113
|
+
static async *pushDockerContainer(config: DockerPackConfig): AsyncIterable<string[]> {
|
|
94
114
|
if (!config.dockerPush) {
|
|
95
115
|
return;
|
|
96
116
|
}
|
|
@@ -109,4 +129,4 @@ export class DockerPackOperation {
|
|
|
109
129
|
}
|
|
110
130
|
}
|
|
111
131
|
}
|
|
112
|
-
}
|
|
132
|
+
}
|