@travetto/pack 3.2.7 → 3.2.8
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
|
@@ -4,11 +4,21 @@ import { DockerPackConfig } from './types';
|
|
|
4
4
|
* Common utils for setting up pack config
|
|
5
5
|
*/
|
|
6
6
|
export class PackConfigUtil {
|
|
7
|
+
/**
|
|
8
|
+
* Docker setup
|
|
9
|
+
*/
|
|
10
|
+
static dockerSetup(cfg: DockerPackConfig): string {
|
|
11
|
+
return [
|
|
12
|
+
`FROM ${cfg.dockerImage}`,
|
|
13
|
+
`WORKDIR /${cfg.dockerRuntime.folder}`,
|
|
14
|
+
].join('\n');
|
|
15
|
+
}
|
|
16
|
+
|
|
7
17
|
/**
|
|
8
18
|
* Generate a docker user creation command
|
|
9
19
|
*/
|
|
10
20
|
static dockerUserCommand(cfg: DockerPackConfig): string {
|
|
11
|
-
const { user, group, uid, gid } = cfg.
|
|
21
|
+
const { user, group, uid, gid } = cfg.dockerRuntime;
|
|
12
22
|
if (user !== 'root') {
|
|
13
23
|
return [
|
|
14
24
|
'',
|
|
@@ -21,4 +31,25 @@ export class PackConfigUtil {
|
|
|
21
31
|
return '';
|
|
22
32
|
}
|
|
23
33
|
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Expose ports
|
|
37
|
+
*/
|
|
38
|
+
static dockerExposePorts(cfg: DockerPackConfig): string {
|
|
39
|
+
return cfg.dockerPort?.map(x => `EXPOSE ${x}`).join('\n') ?? '';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Copy workspace contents
|
|
44
|
+
*/
|
|
45
|
+
static dockerCopyWorkspace(cfg: DockerPackConfig): string {
|
|
46
|
+
return `COPY --chown="${cfg.dockerRuntime.user}:${cfg.dockerRuntime.group}" . .`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Entrypoint creation for a docker configuration
|
|
51
|
+
*/
|
|
52
|
+
static dockerEntrypoint(cfg: DockerPackConfig): string {
|
|
53
|
+
return `ENTRYPOINT ["/${cfg.dockerRuntime.folder}/${cfg.mainName}.sh"]`;
|
|
54
|
+
}
|
|
24
55
|
}
|
package/support/bin/types.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { path, RootIndex } from '@travetto/manifest';
|
|
2
2
|
import { CliCommand, CliFlag, CliUtil, CliValidationError } from '@travetto/cli';
|
|
3
|
+
import { GlobalEnv } from '@travetto/base';
|
|
4
|
+
import { Ignore } from '@travetto/schema';
|
|
3
5
|
|
|
4
6
|
import { DockerPackOperation } from './bin/docker-operation';
|
|
5
7
|
import { BasePackCommand, PackOperationShape } from './pack.base';
|
|
6
|
-
import {
|
|
7
|
-
import { Ignore } from '@travetto/schema';
|
|
8
|
+
import { DockerPackConfig } from './bin/types';
|
|
8
9
|
|
|
9
10
|
const NODE_MAJOR = GlobalEnv.nodeVersion.replace('v', '').split('.')[0];
|
|
10
11
|
const DEFAULT_USER_ID = 2000;
|
|
@@ -33,12 +34,7 @@ export class PackDockerCommand extends BasePackCommand {
|
|
|
33
34
|
dockerRuntimeUserSrc?: string;
|
|
34
35
|
|
|
35
36
|
@Ignore()
|
|
36
|
-
|
|
37
|
-
user: string;
|
|
38
|
-
uid: number;
|
|
39
|
-
group: string;
|
|
40
|
-
gid: number;
|
|
41
|
-
};
|
|
37
|
+
dockerRuntime: DockerPackConfig['dockerRuntime'];
|
|
42
38
|
|
|
43
39
|
async validate(...unknownArgs: string[]): Promise<CliValidationError[] | undefined> {
|
|
44
40
|
const errs: CliValidationError[] = [];
|
|
@@ -70,7 +66,7 @@ export class PackDockerCommand extends BasePackCommand {
|
|
|
70
66
|
const gid = groupIsNum ? +groupOrGid : DEFAULT_USER_ID;
|
|
71
67
|
const group = (!groupIsNum ? groupOrGid : undefined) || DEFAULT_USER;
|
|
72
68
|
const user = (!userIsNum ? userOrUid : undefined) || DEFAULT_USER;
|
|
73
|
-
this.
|
|
69
|
+
this.dockerRuntime = { user, uid, group, gid, folder: DEFAULT_USER };
|
|
74
70
|
}
|
|
75
71
|
|
|
76
72
|
getOperations(): PackOperationShape<this>[] {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { DockerPackFactory } from './bin/types';
|
|
2
2
|
import { PackConfigUtil } from './bin/config-util';
|
|
3
3
|
|
|
4
|
-
export const factory: DockerPackFactory = cfg =>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
`;
|
|
4
|
+
export const factory: DockerPackFactory = cfg => [
|
|
5
|
+
PackConfigUtil.dockerSetup(cfg),
|
|
6
|
+
PackConfigUtil.dockerUserCommand(cfg),
|
|
7
|
+
PackConfigUtil.dockerCopyWorkspace(cfg),
|
|
8
|
+
PackConfigUtil.dockerExposePorts(cfg),
|
|
9
|
+
PackConfigUtil.dockerEntrypoint(cfg),
|
|
10
|
+
].join('\n');
|