@milaboratories/pl-deployments 1.1.6 → 1.1.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.
@@ -1,8 +1,10 @@
1
1
  import type { MiLogger } from '@milaboratories/ts-helpers';
2
2
  import { assertNever } from '@milaboratories/ts-helpers';
3
- import { downloadPlBinary, DownloadBinaryResult } from './pl_binary_download';
3
+ import { downloadBinary } from './pl_binary_download';
4
4
  import { getDefaultPlVersion } from './pl_version';
5
5
  import os from 'os';
6
+ import upath from 'upath';
7
+ import { newOs, OSType } from './os_and_arch';
6
8
 
7
9
  /** Shows how the binary should be got. */
8
10
  export type PlBinarySource = PlBinarySourceDownload | PlBinarySourceLocal;
@@ -28,7 +30,8 @@ export async function resolveLocalPlBinaryPath(
28
30
  ): Promise<string> {
29
31
  switch (src.type) {
30
32
  case 'Download':
31
- return (await downloadPlBinary(logger, downloadDir, src.version, os.arch(), os.platform())).binaryPath!;
33
+ const ops = await downloadBinary(logger, downloadDir, 'pl', `pl-${src.version}`, os.arch(), os.platform());
34
+ return upath.join(ops.baseName, 'binaries', osToBinaryName[newOs(os.platform())]);
32
35
 
33
36
  case 'Local':
34
37
  return src.path;
@@ -37,3 +40,9 @@ export async function resolveLocalPlBinaryPath(
37
40
  assertNever(src);
38
41
  }
39
42
  }
43
+
44
+ export const osToBinaryName: Record<OSType, string> = {
45
+ linux: 'platforma',
46
+ macos: 'platforma',
47
+ windows: 'platforma.exe',
48
+ };
@@ -11,13 +11,19 @@ import decompress from 'decompress';
11
11
  import type { ArchType, OSType } from './os_and_arch';
12
12
  import { newOs, newArch } from './os_and_arch';
13
13
 
14
+ const cdn = 'https://cdn.platforma.bio/software';
15
+ // We'll download things from Global Access if downloading from CDN has failed
16
+ // (it might be that it's blocked from the company's network.)
17
+ const gaCdn = 'https://cdn-ga.pl-open.science/software';
18
+
14
19
  export type DownloadBinaryResult = {
15
20
  archiveUrl: string;
21
+ alternativeArchiveGAUrl: string;
22
+ wasDownloadedFrom?: string;
16
23
  archivePath: string;
17
24
  archiveType: ArchiveType;
18
25
  targetFolder: string;
19
26
  baseName: string;
20
- binaryPath?: string;
21
27
  };
22
28
 
23
29
  export async function downloadBinaryNoExtract(
@@ -29,9 +35,15 @@ export async function downloadBinaryNoExtract(
29
35
  platform: string,
30
36
  ): Promise<DownloadBinaryResult> {
31
37
  const opts = getPathsForDownload(softwareName, tgzName, baseDir, newArch(arch), newOs(platform));
32
- const { archiveUrl, archivePath } = opts;
38
+ const { archiveUrl, alternativeArchiveGAUrl, archivePath } = opts;
33
39
 
34
- await downloadArchive(logger, archiveUrl, archivePath);
40
+ try {
41
+ await downloadArchive(logger, archiveUrl, archivePath);
42
+ opts.wasDownloadedFrom = archiveUrl;
43
+ } catch (e: unknown) {
44
+ await downloadArchive(logger, alternativeArchiveGAUrl, archivePath);
45
+ opts.wasDownloadedFrom = alternativeArchiveGAUrl;
46
+ }
35
47
 
36
48
  return opts;
37
49
  }
@@ -45,25 +57,16 @@ export async function downloadBinary(
45
57
  platform: string,
46
58
  ): Promise<DownloadBinaryResult> {
47
59
  const opts = getPathsForDownload(softwareName, archiveName, baseDir, newArch(arch), newOs(platform));
48
- const { archiveUrl, archivePath, archiveType, targetFolder, baseName } = opts;
49
-
50
- await downloadArchive(logger, archiveUrl, archivePath);
51
- await extractArchive(logger, archivePath, archiveType, targetFolder);
60
+ const { archiveUrl, alternativeArchiveGAUrl, archivePath, archiveType, targetFolder, baseName } = opts;
52
61
 
53
- return opts;
54
- }
55
-
56
- export async function downloadPlBinary(
57
- logger: MiLogger,
58
- baseDir: string,
59
- plVersion: string,
60
- arch: string,
61
- platform: string,
62
- ): Promise<DownloadBinaryResult> {
63
- const opts = localDownloadPlOptions(plVersion, baseDir, newArch(arch), newOs(platform));
64
- const { archiveUrl, archivePath, archiveType, targetFolder, binaryPath } = opts;
62
+ try {
63
+ await downloadArchive(logger, archiveUrl, archivePath);
64
+ opts.wasDownloadedFrom = archiveUrl;
65
+ } catch (e: unknown) {
66
+ await downloadArchive(logger, alternativeArchiveGAUrl, archivePath);
67
+ opts.wasDownloadedFrom = alternativeArchiveGAUrl;
68
+ }
65
69
 
66
- await downloadArchive(logger, archiveUrl, archivePath);
67
70
  await extractArchive(logger, archivePath, archiveType, targetFolder);
68
71
 
69
72
  return opts;
@@ -80,13 +83,15 @@ function getPathsForDownload(
80
83
  const archiveType = osToArchiveType[os];
81
84
 
82
85
  const archiveFileName = `${baseName}.${archiveType}`;
83
- const archiveUrl = `https://cdn.platforma.bio/software/${softwareName}/${os}/${archiveFileName}`;
86
+ const archiveUrl = `${cdn}/${softwareName}/${os}/${archiveFileName}`;
87
+ const alternativeArchiveGAUrl = `${gaCdn}/${softwareName}/${os}/${archiveFileName}`;
84
88
  const archivePath = upath.join(baseDir, archiveFileName);
85
89
  // folder where binary distribution of pl will be unpacked
86
90
  const targetFolder = upath.join(baseDir, baseName);
87
91
 
88
92
  return {
89
93
  archiveUrl,
94
+ alternativeArchiveGAUrl,
90
95
  archivePath,
91
96
  archiveType,
92
97
  targetFolder,
@@ -94,34 +99,6 @@ function getPathsForDownload(
94
99
  };
95
100
  }
96
101
 
97
- export function localDownloadPlOptions(
98
- plVersion: string,
99
- baseDir: string,
100
- arch: ArchType,
101
- os: OSType,
102
- ): DownloadBinaryResult {
103
- const baseName = `pl-${plVersion}-${arch}`;
104
- const archiveType = osToArchiveType[os];
105
-
106
- const archiveFileName = `${baseName}.${archiveType}`;
107
- const archiveUrl = `https://cdn.platforma.bio/software/pl/${os}/${archiveFileName}`;
108
- const archivePath = upath.join(baseDir, archiveFileName);
109
-
110
- // folder where binary distribution of pl will be unpacked
111
- const targetFolder = upath.join(baseDir, baseName);
112
-
113
- const binaryPath = upath.join(baseName, 'binaries', osToBinaryName[os]);
114
-
115
- return {
116
- archiveUrl,
117
- archivePath,
118
- archiveType,
119
- targetFolder,
120
- binaryPath,
121
- baseName,
122
- };
123
- }
124
-
125
102
  export type DownloadInfo = {
126
103
  dstArchive?: string;
127
104
  fileExisted?: boolean;
@@ -250,9 +227,3 @@ const osToArchiveType: Record<OSType, ArchiveType> = {
250
227
  macos: 'tgz',
251
228
  windows: 'zip',
252
229
  };
253
-
254
- const osToBinaryName: Record<OSType, string> = {
255
- linux: 'platforma',
256
- macos: 'platforma',
257
- windows: 'platforma.exe',
258
- };
package/src/local/pl.ts CHANGED
@@ -162,7 +162,9 @@ export async function localPlatformaInit(logger: MiLogger, _ops: LocalPlOptions)
162
162
  logger.info(`writing configuration '${configPath}'...`);
163
163
  await fsp.writeFile(configPath, ops.config);
164
164
 
165
- const baseBinaryPath = await resolveLocalPlBinaryPath(logger, upath.join(workDir, 'binaries'), ops.plBinary);
165
+ const plBinPath = upath.join(workDir, 'binaries');
166
+ const baseBinaryPath = await resolveLocalPlBinaryPath(logger, plBinPath, ops.plBinary);
167
+
166
168
  const binaryPath = trace('binaryPath', upath.join('binaries', baseBinaryPath));
167
169
 
168
170
  const processOpts: ProcessOptions = {
@@ -5,7 +5,7 @@ import upath from 'upath';
5
5
  import { getDefaultPlVersion } from '../../common/pl_version';
6
6
  import { existsSync, unlinkSync, rmSync } from 'fs';
7
7
  import { newArch } from '../../common/os_and_arch';
8
- import { downloadBinary, downloadPlBinary } from '../../common/pl_binary_download';
8
+ import { downloadBinary } from '../../common/pl_binary_download';
9
9
  import { ConsoleLoggerAdapter } from '@milaboratories/ts-helpers';
10
10
  import * as plpath from '../pl_paths';
11
11
 
@@ -39,12 +39,15 @@ describe('SshPl', async () => {
39
39
  expect(platformInfo).toHaveProperty('platform');
40
40
  expect(platformInfo).toHaveProperty('arch');
41
41
 
42
- expect(platformInfo?.arch).toBe('x86_64');
42
+ // expect(platformInfo?.arch).toBe('x86_64');
43
43
  expect(platformInfo?.platform).toBe('Linux');
44
44
  });
45
45
 
46
46
  it('Check start/stop cmd', async () => {
47
- await sshPl.platformaInit(downloadDestination);
47
+ await sshPl.platformaInit({
48
+ localWorkdir: downloadDestination,
49
+ license: {type: 'env'},
50
+ });
48
51
  expect(await sshPl.isAlive()).toBe(true);
49
52
 
50
53
  await sshPl.stop();
@@ -71,7 +74,10 @@ describe('SshPl', async () => {
71
74
  });
72
75
 
73
76
  it('platformaInit', async () => {
74
- const result = await sshPl.platformaInit(downloadDestination);
77
+ const result = await sshPl.platformaInit({
78
+ localWorkdir: downloadDestination,
79
+ license: { type: 'env' },
80
+ });
75
81
 
76
82
  const remoteHome = await sshPl.getUserHomeDirectory();
77
83
 
@@ -84,10 +90,10 @@ describe('SshPl', async () => {
84
90
  it('Transfer Platforma to server', async () => {
85
91
  const arch = await sshPl.getArch();
86
92
 
87
- const plPath = await downloadPlBinary(
93
+ const plPath = await downloadBinary(
88
94
  new ConsoleLoggerAdapter(),
89
95
  downloadDestination,
90
- getDefaultPlVersion(),
96
+ 'pl', `pl-${getDefaultPlVersion()}`,
91
97
  arch.arch,
92
98
  arch.platform,
93
99
  );
@@ -104,7 +110,10 @@ describe('SshPl', async () => {
104
110
  });
105
111
 
106
112
  it('Get free port', async () => {
107
- await sshPl?.platformaInit(downloadDestination);
113
+ await sshPl.platformaInit({
114
+ localWorkdir: downloadDestination,
115
+ license: { type: 'env' },
116
+ })
108
117
  const isAlive = await sshPl?.isAlive();
109
118
  expect(isAlive).toBe(true);
110
119
 
@@ -154,10 +163,10 @@ describe('SshPl download binaries', async () => {
154
163
  it('Download pl. We have archive and extracted data', async () => {
155
164
  const arch = await sshPl.getArch();
156
165
 
157
- const result = await downloadPlBinary(
166
+ const result = await downloadBinary(
158
167
  new ConsoleLoggerAdapter(),
159
168
  downloadDestination,
160
- getDefaultPlVersion(),
169
+ 'pl', `pl-${getDefaultPlVersion()}`,
161
170
  arch.arch,
162
171
  arch.platform,
163
172
  );
package/src/ssh/pl.ts CHANGED
@@ -9,7 +9,7 @@ import * as plpath from './pl_paths';
9
9
  import { getDefaultPlVersion } from '../common/pl_version';
10
10
 
11
11
  import net from 'net';
12
- import type { SshPlConfigGenerationResult } from '@milaboratories/pl-config';
12
+ import type { PlLicenseMode, SshPlConfigGenerationResult } from '@milaboratories/pl-config';
13
13
  import { generateSshPlConfigs, getFreePort } from '@milaboratories/pl-config';
14
14
  import { supervisorStatus, supervisorStop as supervisorCtlShutdown, generateSupervisordConfig, supervisorCtlStart } from './supervisord';
15
15
 
@@ -98,8 +98,8 @@ export class SshPl {
98
98
  return true;
99
99
  }
100
100
 
101
- public async platformaInit(localWorkdir: string): Promise<SshInitReturnTypes> {
102
- const state: PlatformaInitState = { localWorkdir };
101
+ public async platformaInit(ops: SshPlConfig): Promise<SshInitReturnTypes> {
102
+ const state: PlatformaInitState = { localWorkdir: ops.localWorkdir };
103
103
 
104
104
  try {
105
105
  state.arch = await this.getArch();
@@ -115,7 +115,7 @@ export class SshPl {
115
115
  }
116
116
 
117
117
  const downloadRes = await this.downloadBinariesAndUploadToTheServer(
118
- localWorkdir, state.remoteHome, state.arch,
118
+ ops.localWorkdir, state.remoteHome, state.arch,
119
119
  );
120
120
  state.binPaths = { ...downloadRes, history: undefined };
121
121
  state.downloadedBinaries = downloadRes.history;
@@ -428,6 +428,11 @@ export type SshPlatformaPorts = {
428
428
 
429
429
  type Arch = { platform: string; arch: string };
430
430
 
431
+ export type SshPlConfig = {
432
+ localWorkdir: string;
433
+ license: PlLicenseMode;
434
+ }
435
+
431
436
  export type SshInitReturnTypes = {
432
437
  plUser: string;
433
438
  plPassword: string;