@alwaysai/device-agent 1.4.0 → 2.0.0
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/lib/application-control/config.d.ts.map +1 -1
- package/lib/application-control/config.js +10 -5
- package/lib/application-control/config.js.map +1 -1
- package/lib/application-control/environment-variables.d.ts +1 -5
- package/lib/application-control/environment-variables.d.ts.map +1 -1
- package/lib/application-control/environment-variables.js +9 -26
- package/lib/application-control/environment-variables.js.map +1 -1
- package/lib/application-control/environment-variables.test.js +27 -7
- package/lib/application-control/environment-variables.test.js.map +1 -1
- package/lib/application-control/index.d.ts +4 -4
- package/lib/application-control/index.d.ts.map +1 -1
- package/lib/application-control/index.js +1 -4
- package/lib/application-control/index.js.map +1 -1
- package/lib/application-control/install.d.ts.map +1 -1
- package/lib/application-control/install.js +9 -7
- package/lib/application-control/install.js.map +1 -1
- package/lib/application-control/models.d.ts +5 -11
- package/lib/application-control/models.d.ts.map +1 -1
- package/lib/application-control/models.js +27 -64
- package/lib/application-control/models.js.map +1 -1
- package/lib/application-control/status.d.ts.map +1 -1
- package/lib/application-control/status.js +10 -12
- package/lib/application-control/status.js.map +1 -1
- package/lib/application-control/utils.d.ts +0 -4
- package/lib/application-control/utils.d.ts.map +1 -1
- package/lib/application-control/utils.js +3 -26
- package/lib/application-control/utils.js.map +1 -1
- package/lib/cloud-connection/bootstrap-provision.js +3 -2
- package/lib/cloud-connection/bootstrap-provision.js.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts +11 -16
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.js +295 -246
- package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
- package/lib/cloud-connection/device-agent.d.ts.map +1 -1
- package/lib/cloud-connection/device-agent.js +11 -9
- package/lib/cloud-connection/device-agent.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.d.ts +18 -27
- package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -1
- package/lib/cloud-connection/live-updates-handler.js +58 -170
- package/lib/cloud-connection/live-updates-handler.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.test.js +76 -54
- package/lib/cloud-connection/live-updates-handler.test.js.map +1 -1
- package/lib/cloud-connection/passthrough-handler.d.ts +9 -4
- package/lib/cloud-connection/passthrough-handler.d.ts.map +1 -1
- package/lib/cloud-connection/passthrough-handler.js +95 -62
- package/lib/cloud-connection/passthrough-handler.js.map +1 -1
- package/lib/cloud-connection/shadow-handler.d.ts +5 -1
- package/lib/cloud-connection/shadow-handler.d.ts.map +1 -1
- package/lib/cloud-connection/shadow-handler.js +63 -31
- package/lib/cloud-connection/shadow-handler.js.map +1 -1
- package/lib/cloud-connection/shadow-handler.test.js +45 -57
- package/lib/cloud-connection/shadow-handler.test.js.map +1 -1
- package/lib/cloud-connection/shadow.d.ts.map +1 -1
- package/lib/cloud-connection/shadow.js +2 -1
- package/lib/cloud-connection/shadow.js.map +1 -1
- package/lib/cloud-connection/transaction-manager.d.ts +7 -2
- package/lib/cloud-connection/transaction-manager.d.ts.map +1 -1
- package/lib/cloud-connection/transaction-manager.js +29 -29
- package/lib/cloud-connection/transaction-manager.js.map +1 -1
- package/lib/cloud-connection/transaction-manager.test.js +105 -3
- package/lib/cloud-connection/transaction-manager.test.js.map +1 -1
- package/lib/device-control/device-control.d.ts +14 -6
- package/lib/device-control/device-control.d.ts.map +1 -1
- package/lib/device-control/device-control.js +172 -72
- package/lib/device-control/device-control.js.map +1 -1
- package/lib/docker/docker-compose.d.ts +14 -0
- package/lib/docker/docker-compose.d.ts.map +1 -0
- package/lib/docker/docker-compose.js +57 -0
- package/lib/docker/docker-compose.js.map +1 -0
- package/lib/index.js +2 -5
- package/lib/index.js.map +1 -1
- package/lib/infrastructure/agent-config.d.ts +46 -14
- package/lib/infrastructure/agent-config.d.ts.map +1 -1
- package/lib/infrastructure/agent-config.js +36 -21
- package/lib/infrastructure/agent-config.js.map +1 -1
- package/lib/infrastructure/agent-config.test.js +6 -1
- package/lib/infrastructure/agent-config.test.js.map +1 -1
- package/lib/infrastructure/config-check-utility.d.ts +6 -0
- package/lib/infrastructure/config-check-utility.d.ts.map +1 -0
- package/lib/infrastructure/config-check-utility.js +67 -0
- package/lib/infrastructure/config-check-utility.js.map +1 -0
- package/lib/infrastructure/config-check-utility.test.d.ts +2 -0
- package/lib/infrastructure/config-check-utility.test.d.ts.map +1 -0
- package/lib/infrastructure/config-check-utility.test.js +109 -0
- package/lib/infrastructure/config-check-utility.test.js.map +1 -0
- package/lib/infrastructure/device-certificate.d.ts +10 -0
- package/lib/infrastructure/device-certificate.d.ts.map +1 -0
- package/lib/infrastructure/device-certificate.js +47 -0
- package/lib/infrastructure/device-certificate.js.map +1 -0
- package/lib/infrastructure/device-certificate.test.d.ts +2 -0
- package/lib/infrastructure/device-certificate.test.d.ts.map +1 -0
- package/lib/infrastructure/device-certificate.test.js +24 -0
- package/lib/infrastructure/device-certificate.test.js.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-file.test.d.ts +2 -0
- package/lib/infrastructure/legacy-migration/legacy-file.test.d.ts.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-file.test.js +61 -0
- package/lib/infrastructure/legacy-migration/legacy-file.test.js.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-files.d.ts +75 -0
- package/lib/infrastructure/legacy-migration/legacy-files.d.ts.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-files.js +75 -0
- package/lib/infrastructure/legacy-migration/legacy-files.js.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.d.ts +6 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.d.ts.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.js +149 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.js.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.test.d.ts +2 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.test.d.ts.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.test.js +226 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.test.js.map +1 -0
- package/lib/infrastructure/require-files-present-ready.test.d.ts +2 -0
- package/lib/infrastructure/require-files-present-ready.test.d.ts.map +1 -0
- package/lib/infrastructure/require-files-present-ready.test.js +44 -0
- package/lib/infrastructure/require-files-present-ready.test.js.map +1 -0
- package/lib/infrastructure/required-config-checks.d.ts +2 -0
- package/lib/infrastructure/required-config-checks.d.ts.map +1 -0
- package/lib/infrastructure/required-config-checks.js +30 -0
- package/lib/infrastructure/required-config-checks.js.map +1 -0
- package/lib/infrastructure/tokens-and-device-cfg.d.ts.map +1 -1
- package/lib/infrastructure/tokens-and-device-cfg.js +11 -8
- package/lib/infrastructure/tokens-and-device-cfg.js.map +1 -1
- package/lib/local-connection/rabbitmq-connection.d.ts.map +1 -1
- package/lib/local-connection/rabbitmq-connection.js +21 -21
- package/lib/local-connection/rabbitmq-connection.js.map +1 -1
- package/lib/secure-tunneling/secure-tunneling.d.ts +15 -23
- package/lib/secure-tunneling/secure-tunneling.d.ts.map +1 -1
- package/lib/secure-tunneling/secure-tunneling.js +52 -47
- package/lib/secure-tunneling/secure-tunneling.js.map +1 -1
- package/lib/secure-tunneling/secure-tunneling.test.js +29 -31
- package/lib/secure-tunneling/secure-tunneling.test.js.map +1 -1
- package/lib/subcommands/app/analytics.d.ts.map +1 -1
- package/lib/subcommands/app/analytics.js +1 -2
- package/lib/subcommands/app/analytics.js.map +1 -1
- package/lib/subcommands/app/env-vars.d.ts +4 -0
- package/lib/subcommands/app/env-vars.d.ts.map +1 -1
- package/lib/subcommands/app/env-vars.js +52 -6
- package/lib/subcommands/app/env-vars.js.map +1 -1
- package/lib/subcommands/app/index.d.ts.map +1 -1
- package/lib/subcommands/app/index.js +1 -3
- package/lib/subcommands/app/index.js.map +1 -1
- package/lib/subcommands/app/models.d.ts +0 -11
- package/lib/subcommands/app/models.d.ts.map +1 -1
- package/lib/subcommands/app/models.js +2 -58
- package/lib/subcommands/app/models.js.map +1 -1
- package/lib/subcommands/app/shadow.d.ts.map +1 -1
- package/lib/subcommands/app/shadow.js +6 -5
- package/lib/subcommands/app/shadow.js.map +1 -1
- package/lib/subcommands/app/version.d.ts.map +1 -1
- package/lib/subcommands/app/version.js +2 -4
- package/lib/subcommands/app/version.js.map +1 -1
- package/lib/subcommands/config.d.ts +2 -0
- package/lib/subcommands/config.d.ts.map +1 -0
- package/lib/subcommands/config.js +39 -0
- package/lib/subcommands/config.js.map +1 -0
- package/lib/subcommands/device/clean.d.ts +1 -1
- package/lib/subcommands/device/clean.d.ts.map +1 -1
- package/lib/subcommands/device/clean.js +25 -15
- package/lib/subcommands/device/clean.js.map +1 -1
- package/lib/subcommands/device/get-info.d.ts +2 -0
- package/lib/subcommands/device/get-info.d.ts.map +1 -0
- package/lib/subcommands/device/get-info.js +36 -0
- package/lib/subcommands/device/get-info.js.map +1 -0
- package/lib/subcommands/device/index.d.ts.map +1 -1
- package/lib/subcommands/device/index.js +13 -2
- package/lib/subcommands/device/index.js.map +1 -1
- package/lib/subcommands/device/init.d.ts +5 -0
- package/lib/subcommands/device/init.d.ts.map +1 -0
- package/lib/subcommands/device/{device.js → init.js} +10 -49
- package/lib/subcommands/device/init.js.map +1 -0
- package/lib/subcommands/device/migrate.d.ts +2 -0
- package/lib/subcommands/device/migrate.d.ts.map +1 -0
- package/lib/subcommands/device/migrate.js +24 -0
- package/lib/subcommands/device/migrate.js.map +1 -0
- package/lib/subcommands/device/refresh.d.ts +2 -0
- package/lib/subcommands/device/refresh.d.ts.map +1 -0
- package/lib/subcommands/device/refresh.js +25 -0
- package/lib/subcommands/device/refresh.js.map +1 -0
- package/lib/subcommands/device/restart.d.ts +2 -0
- package/lib/subcommands/device/restart.d.ts.map +1 -0
- package/lib/subcommands/device/restart.js +14 -0
- package/lib/subcommands/device/restart.js.map +1 -0
- package/lib/subcommands/index.d.ts +1 -1
- package/lib/subcommands/index.d.ts.map +1 -1
- package/lib/subcommands/index.js +3 -1
- package/lib/subcommands/index.js.map +1 -1
- package/lib/subcommands/rabbitmq-connection.d.ts +1 -1
- package/lib/subcommands/rabbitmq-connection.d.ts.map +1 -1
- package/lib/util/aai-error.d.ts +12 -0
- package/lib/util/aai-error.d.ts.map +1 -0
- package/lib/util/aai-error.js +11 -0
- package/lib/util/aai-error.js.map +1 -0
- package/lib/util/aws-regions.d.ts +2 -0
- package/lib/util/aws-regions.d.ts.map +1 -0
- package/lib/util/{cloud-mode-ready.js → aws-regions.js} +2 -20
- package/lib/util/aws-regions.js.map +1 -0
- package/lib/util/check-for-updates.d.ts +3 -0
- package/lib/util/check-for-updates.d.ts.map +1 -0
- package/lib/util/check-for-updates.js +46 -0
- package/lib/util/check-for-updates.js.map +1 -0
- package/lib/util/clean-certs.d.ts.map +1 -1
- package/lib/util/clean-certs.js +5 -4
- package/lib/util/clean-certs.js.map +1 -1
- package/lib/util/directories.d.ts +4 -18
- package/lib/util/directories.d.ts.map +1 -1
- package/lib/util/directories.js +18 -32
- package/lib/util/directories.js.map +1 -1
- package/lib/util/file.d.ts +11 -0
- package/lib/util/file.d.ts.map +1 -0
- package/lib/util/file.js +127 -0
- package/lib/util/file.js.map +1 -0
- package/lib/util/file.test.d.ts +2 -0
- package/lib/util/file.test.d.ts.map +1 -0
- package/lib/util/file.test.js +87 -0
- package/lib/util/file.test.js.map +1 -0
- package/lib/util/get-device-id.d.ts.map +1 -1
- package/lib/util/get-device-id.js +7 -1
- package/lib/util/get-device-id.js.map +1 -1
- package/lib/util/http-client.js +3 -3
- package/lib/util/http-client.js.map +1 -1
- package/package.json +22 -19
- package/readme.md +15 -35
- package/src/application-control/config.ts +10 -13
- package/src/application-control/environment-variables.test.ts +28 -7
- package/src/application-control/environment-variables.ts +13 -40
- package/src/application-control/index.ts +3 -16
- package/src/application-control/install.ts +16 -10
- package/src/application-control/models.ts +40 -98
- package/src/application-control/status.ts +9 -7
- package/src/application-control/utils.ts +1 -29
- package/src/cloud-connection/bootstrap-provision.ts +7 -7
- package/src/cloud-connection/device-agent-cloud-connection.ts +647 -509
- package/src/cloud-connection/device-agent.ts +16 -7
- package/src/cloud-connection/live-updates-handler.test.ts +137 -64
- package/src/cloud-connection/live-updates-handler.ts +103 -234
- package/src/cloud-connection/passthrough-handler.ts +134 -75
- package/src/cloud-connection/shadow-handler.test.ts +45 -57
- package/src/cloud-connection/shadow-handler.ts +114 -56
- package/src/cloud-connection/shadow.ts +4 -1
- package/src/cloud-connection/transaction-manager.test.ts +127 -3
- package/src/cloud-connection/transaction-manager.ts +68 -39
- package/src/device-control/device-control.ts +179 -72
- package/src/docker/docker-compose.ts +61 -0
- package/src/index.ts +2 -6
- package/src/infrastructure/agent-config.test.ts +9 -2
- package/src/infrastructure/agent-config.ts +45 -46
- package/src/infrastructure/config-check-utility.test.ts +154 -0
- package/src/infrastructure/config-check-utility.ts +77 -0
- package/src/infrastructure/device-certificate.test.ts +40 -0
- package/src/infrastructure/device-certificate.ts +58 -0
- package/src/infrastructure/legacy-migration/legacy-file.test.ts +88 -0
- package/src/infrastructure/legacy-migration/legacy-files.ts +101 -0
- package/src/infrastructure/legacy-migration/legacy-migration.test.ts +396 -0
- package/src/infrastructure/legacy-migration/legacy-migration.ts +229 -0
- package/src/infrastructure/require-files-present-ready.test.ts +53 -0
- package/src/infrastructure/required-config-checks.ts +33 -0
- package/src/infrastructure/tokens-and-device-cfg.ts +12 -10
- package/src/local-connection/rabbitmq-connection.ts +28 -23
- package/src/secure-tunneling/secure-tunneling.test.ts +37 -39
- package/src/secure-tunneling/secure-tunneling.ts +74 -69
- package/src/subcommands/app/analytics.ts +2 -4
- package/src/subcommands/app/env-vars.ts +72 -9
- package/src/subcommands/app/index.ts +3 -11
- package/src/subcommands/app/models.ts +5 -81
- package/src/subcommands/app/shadow.ts +6 -5
- package/src/subcommands/app/version.ts +3 -4
- package/src/subcommands/config.ts +42 -0
- package/src/subcommands/device/clean.ts +32 -18
- package/src/subcommands/device/get-info.ts +49 -0
- package/src/subcommands/device/index.ts +13 -2
- package/src/subcommands/device/{device.ts → init.ts} +11 -69
- package/src/subcommands/device/migrate.ts +20 -0
- package/src/subcommands/device/refresh.ts +23 -0
- package/src/subcommands/device/restart.ts +11 -0
- package/src/subcommands/index.ts +3 -1
- package/src/util/aai-error.ts +20 -0
- package/src/util/{cloud-mode-ready.ts → aws-regions.ts} +0 -24
- package/src/util/check-for-updates.ts +53 -0
- package/src/util/clean-certs.ts +8 -4
- package/src/util/directories.ts +23 -67
- package/src/util/file.test.ts +90 -0
- package/src/util/file.ts +156 -0
- package/src/util/get-device-id.ts +7 -7
- package/src/util/http-client.ts +2 -2
- package/lib/docker/docker-compose-cmd.d.ts +0 -5
- package/lib/docker/docker-compose-cmd.d.ts.map +0 -1
- package/lib/docker/docker-compose-cmd.js +0 -16
- package/lib/docker/docker-compose-cmd.js.map +0 -1
- package/lib/subcommands/device/device.d.ts +0 -7
- package/lib/subcommands/device/device.d.ts.map +0 -1
- package/lib/subcommands/device/device.js.map +0 -1
- package/lib/util/cloud-mode-ready.d.ts +0 -3
- package/lib/util/cloud-mode-ready.d.ts.map +0 -1
- package/lib/util/cloud-mode-ready.js.map +0 -1
- package/lib/util/download-file.d.ts +0 -6
- package/lib/util/download-file.d.ts.map +0 -1
- package/lib/util/download-file.js +0 -25
- package/lib/util/download-file.js.map +0 -1
- package/lib/util/fetch-with-timeout.d.ts +0 -4
- package/lib/util/fetch-with-timeout.d.ts.map +0 -1
- package/lib/util/fetch-with-timeout.js +0 -30
- package/lib/util/fetch-with-timeout.js.map +0 -1
- package/lib/util/parsing.d.ts +0 -2
- package/lib/util/parsing.d.ts.map +0 -1
- package/lib/util/parsing.js +0 -17
- package/lib/util/parsing.js.map +0 -1
- package/lib/util/safe-rimraf.d.ts +0 -2
- package/lib/util/safe-rimraf.d.ts.map +0 -1
- package/lib/util/safe-rimraf.js +0 -16
- package/lib/util/safe-rimraf.js.map +0 -1
- package/src/docker/docker-compose-cmd.ts +0 -15
- package/src/util/download-file.ts +0 -25
- package/src/util/fetch-with-timeout.ts +0 -35
- package/src/util/parsing.ts +0 -11
- package/src/util/safe-rimraf.ts +0 -14
|
@@ -1,30 +1,18 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
1
|
import { ModelInstallPayload } from '@alwaysai/device-agent-schemas';
|
|
3
|
-
import {
|
|
4
|
-
appModelsAddComponent,
|
|
5
|
-
appModelsRemoveAllComponent,
|
|
6
|
-
appModelsRemoveComponent,
|
|
7
|
-
appModelsUpdateComponent
|
|
8
|
-
} from 'alwaysai/lib/components/app';
|
|
9
2
|
import { JsSpawner } from 'alwaysai/lib/util';
|
|
10
3
|
import { logger } from '../util/logger';
|
|
11
4
|
import { existsSync, createReadStream } from 'fs';
|
|
12
5
|
import { join, dirname } from 'path';
|
|
13
6
|
import { AgentConfigFile } from '../infrastructure/agent-config';
|
|
14
7
|
import { copyDir } from '../util/copy-dir';
|
|
15
|
-
import { runInDir } from '../util/run-in-dir';
|
|
16
8
|
import { isAppStarted, restartApp } from './status';
|
|
17
9
|
import { ModelDetails } from './types';
|
|
18
|
-
import {
|
|
19
|
-
buildApp,
|
|
20
|
-
downloadPackageUsingPresignedUrl,
|
|
21
|
-
getAppDir,
|
|
22
|
-
requireAppReady
|
|
23
|
-
} from './utils';
|
|
10
|
+
import { buildApp, getAppDir, requireAppReady } from './utils';
|
|
24
11
|
import { MODEL_JSON_FILE_NAME } from 'alwaysai/lib/core/model';
|
|
25
12
|
import { writeAppCfgFile } from './config';
|
|
26
|
-
import { AppConfig } from '@alwaysai/app-configuration-schemas';
|
|
27
13
|
import { APP_MODELS_DIRECTORY_NAME } from 'alwaysai/lib/paths';
|
|
14
|
+
import { downloadToFile, pruneDir } from '../util/file';
|
|
15
|
+
import { AppConfig } from '@alwaysai/app-configuration-schemas';
|
|
28
16
|
|
|
29
17
|
export async function getAppModels(props: { projectId: string }) {
|
|
30
18
|
const { projectId } = props;
|
|
@@ -48,75 +36,6 @@ export async function getAppModels(props: { projectId: string }) {
|
|
|
48
36
|
return modelDetails;
|
|
49
37
|
}
|
|
50
38
|
|
|
51
|
-
export async function removeModel(props: {
|
|
52
|
-
projectId: string;
|
|
53
|
-
modelId: string;
|
|
54
|
-
}) {
|
|
55
|
-
const { projectId, modelId } = props;
|
|
56
|
-
await requireAppReady({ projectId });
|
|
57
|
-
|
|
58
|
-
const appDir = getAppDir(projectId);
|
|
59
|
-
|
|
60
|
-
await runInDir(
|
|
61
|
-
appModelsRemoveComponent,
|
|
62
|
-
[
|
|
63
|
-
{
|
|
64
|
-
id: modelId,
|
|
65
|
-
purge: true,
|
|
66
|
-
removeFromProject: false
|
|
67
|
-
}
|
|
68
|
-
],
|
|
69
|
-
appDir
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export async function replaceModels(props: {
|
|
74
|
-
projectId: string;
|
|
75
|
-
modelIds: string[];
|
|
76
|
-
}) {
|
|
77
|
-
const { projectId, modelIds } = props;
|
|
78
|
-
await requireAppReady({ projectId });
|
|
79
|
-
|
|
80
|
-
const appDir = getAppDir(projectId);
|
|
81
|
-
|
|
82
|
-
await runInDir(
|
|
83
|
-
appModelsRemoveAllComponent,
|
|
84
|
-
[
|
|
85
|
-
{
|
|
86
|
-
purge: true,
|
|
87
|
-
removeFromProject: false
|
|
88
|
-
}
|
|
89
|
-
],
|
|
90
|
-
appDir
|
|
91
|
-
);
|
|
92
|
-
const modelsAddPromises: Promise<void>[] = [];
|
|
93
|
-
for (const modelId of modelIds) {
|
|
94
|
-
modelsAddPromises.push(
|
|
95
|
-
appModelsAddComponent({
|
|
96
|
-
yes: false,
|
|
97
|
-
dir: appDir,
|
|
98
|
-
id: modelId,
|
|
99
|
-
addToProject: false
|
|
100
|
-
})
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
await Promise.all(modelsAddPromises);
|
|
104
|
-
|
|
105
|
-
await buildApp({ appDir });
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export async function updateModels(props: { projectId: string }) {
|
|
109
|
-
const { projectId } = props;
|
|
110
|
-
await requireAppReady({ projectId });
|
|
111
|
-
|
|
112
|
-
const appDir = getAppDir(projectId);
|
|
113
|
-
await appModelsUpdateComponent({
|
|
114
|
-
yes: false,
|
|
115
|
-
dir: appDir
|
|
116
|
-
});
|
|
117
|
-
await buildApp({ appDir });
|
|
118
|
-
}
|
|
119
|
-
|
|
120
39
|
export async function installModelsWithPresignedURLs(
|
|
121
40
|
modelPayloads: ModelInstallPayload[],
|
|
122
41
|
targetDir: string
|
|
@@ -127,12 +46,12 @@ export async function installModelsWithPresignedURLs(
|
|
|
127
46
|
modelPayloads.map(async (payload: ModelInstallPayload) => {
|
|
128
47
|
logger.info(`Installing ${payload.id}: ${payload.version}`);
|
|
129
48
|
const version = payload.version;
|
|
130
|
-
const modelDest =
|
|
49
|
+
const modelDest = join(targetDir, payload.id);
|
|
131
50
|
await spawner.mkdirp(modelDest);
|
|
132
|
-
const localDest =
|
|
133
|
-
await
|
|
134
|
-
localDest,
|
|
135
|
-
|
|
51
|
+
const localDest = join(modelDest, `${payload.version}.tar.gz`);
|
|
52
|
+
await downloadToFile({
|
|
53
|
+
path: localDest,
|
|
54
|
+
url: payload.modelSignedUrl
|
|
136
55
|
});
|
|
137
56
|
await spawner.untar(createReadStream(localDest), dirname(modelDest));
|
|
138
57
|
await updateModelJson(modelDest, (modelJson) => ({
|
|
@@ -178,20 +97,21 @@ export async function updateModelsWithPresignedUrls(props: {
|
|
|
178
97
|
version: appReleaseHash
|
|
179
98
|
});
|
|
180
99
|
|
|
181
|
-
const ogDir =
|
|
182
|
-
// Copy all current models to restore dir in case of failure
|
|
183
|
-
const restoreDir = `${ogDir}.restore`;
|
|
184
|
-
await spawner.rimraf(restoreDir);
|
|
185
|
-
await copyDir({ srcPath: ogDir, destPath: restoreDir });
|
|
186
|
-
|
|
187
|
-
// Create temp dir to install new models
|
|
100
|
+
const ogDir = join(appDir, APP_MODELS_DIRECTORY_NAME);
|
|
188
101
|
const tmpDir = `${ogDir}.tmp`;
|
|
189
102
|
|
|
190
103
|
try {
|
|
191
104
|
await spawner.rimraf(tmpDir);
|
|
192
105
|
await copyDir({ srcPath: ogDir, destPath: tmpDir });
|
|
106
|
+
|
|
107
|
+
await pruneModels({
|
|
108
|
+
projectId,
|
|
109
|
+
appCfg: newAppCfg,
|
|
110
|
+
path: tmpDir
|
|
111
|
+
});
|
|
112
|
+
|
|
193
113
|
await installModelsWithPresignedURLs(modelInstallPayloads, tmpDir);
|
|
194
|
-
|
|
114
|
+
|
|
195
115
|
await spawner.rimraf(ogDir);
|
|
196
116
|
await copyDir({ srcPath: tmpDir, destPath: ogDir });
|
|
197
117
|
await spawner.rimraf(tmpDir);
|
|
@@ -211,6 +131,28 @@ export async function updateModelsWithPresignedUrls(props: {
|
|
|
211
131
|
logger.info(`Models installed for project ${projectId}`);
|
|
212
132
|
} finally {
|
|
213
133
|
await spawner.rimraf(tmpDir);
|
|
214
|
-
await spawner.rimraf(restoreDir);
|
|
215
134
|
}
|
|
216
135
|
}
|
|
136
|
+
|
|
137
|
+
export async function pruneModels(props: {
|
|
138
|
+
projectId: string;
|
|
139
|
+
appCfg: AppConfig;
|
|
140
|
+
path?: string;
|
|
141
|
+
}) {
|
|
142
|
+
const { projectId, appCfg, path } = props;
|
|
143
|
+
|
|
144
|
+
const modelsPath = path ?? join(getAppDir(projectId), 'models');
|
|
145
|
+
|
|
146
|
+
if (!existsSync(modelsPath)) {
|
|
147
|
+
logger.error(
|
|
148
|
+
`Attempted to prune models from ${modelsPath} for project app ${projectId} that does not exist or has no models dir.`
|
|
149
|
+
);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
await pruneDir({
|
|
154
|
+
path: modelsPath,
|
|
155
|
+
exclude: Object.keys(appCfg.models),
|
|
156
|
+
recurse: true
|
|
157
|
+
});
|
|
158
|
+
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
compose,
|
|
3
|
+
runStreamingDockerComposeCmd,
|
|
4
|
+
runDockerComposeCmd
|
|
5
|
+
} from '../docker/docker-compose';
|
|
2
6
|
import { JsSpawner } from 'alwaysai/lib/util';
|
|
3
7
|
|
|
4
8
|
import { runDockerLogin } from '../docker/docker-cmd';
|
|
@@ -48,9 +52,8 @@ export async function getAppState(props: {
|
|
|
48
52
|
const spawner = JsSpawner({ path: appDir });
|
|
49
53
|
for (const name of composeServices.data.services) {
|
|
50
54
|
// Get container name for service
|
|
51
|
-
const containerId = await
|
|
52
|
-
|
|
53
|
-
cwd: appDir,
|
|
55
|
+
const containerId = await runDockerComposeCmd({
|
|
56
|
+
dir: appDir,
|
|
54
57
|
args: ['ps', '-q', name]
|
|
55
58
|
});
|
|
56
59
|
if (containerId === '') {
|
|
@@ -136,10 +139,9 @@ export async function getAppLogs(props: {
|
|
|
136
139
|
const argsList = args || [];
|
|
137
140
|
|
|
138
141
|
// Use direct command with spawner in order to get a readable stream
|
|
139
|
-
return await
|
|
140
|
-
exe: 'docker-compose',
|
|
142
|
+
return await runStreamingDockerComposeCmd({
|
|
141
143
|
args: ['logs', '-f', ...argsList, ...serviceList],
|
|
142
|
-
|
|
144
|
+
dir: appDir
|
|
143
145
|
});
|
|
144
146
|
}
|
|
145
147
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import compose from 'docker-compose';
|
|
1
|
+
import { compose } from '../docker/docker-compose';
|
|
2
2
|
import * as path from 'path';
|
|
3
|
-
import * as fs from 'fs';
|
|
4
3
|
|
|
5
4
|
import { AgentConfigFile } from '../infrastructure/agent-config';
|
|
6
|
-
import { fetchWithTimeout } from '../util/fetch-with-timeout';
|
|
7
5
|
import {
|
|
8
6
|
getDockerComposeCmdForApp,
|
|
9
7
|
TargetJsonFile,
|
|
@@ -77,29 +75,3 @@ export async function buildApp(props: { appDir: string }) {
|
|
|
77
75
|
);
|
|
78
76
|
}
|
|
79
77
|
}
|
|
80
|
-
|
|
81
|
-
export async function downloadPackageUsingPresignedUrl(props: {
|
|
82
|
-
localDest: string;
|
|
83
|
-
presignedUrl: string;
|
|
84
|
-
}): Promise<void> {
|
|
85
|
-
const { localDest, presignedUrl } = props;
|
|
86
|
-
logger.debug(`Downloading package from ${presignedUrl}`);
|
|
87
|
-
let response: any;
|
|
88
|
-
try {
|
|
89
|
-
response = await fetchWithTimeout(presignedUrl);
|
|
90
|
-
} catch (e) {
|
|
91
|
-
const errorBody = e.type === 'aborted' ? e : await e.response.text();
|
|
92
|
-
throw new Error(
|
|
93
|
-
`downloadPackageUsingPresignedUrl: Error=${e}\n${errorBody}`
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Write the app package to the hash directory
|
|
99
|
-
*/
|
|
100
|
-
const stream = response.body.pipe(fs.createWriteStream(localDest));
|
|
101
|
-
await new Promise((resolve, reject) => {
|
|
102
|
-
stream.on('finish', resolve);
|
|
103
|
-
stream.on('error', reject);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getBootstrapCertificateFilePath,
|
|
3
|
+
getBootstrapPrivateKeyFilePath
|
|
4
|
+
} from '../infrastructure/device-certificate';
|
|
1
5
|
import { getIoTCoreEndpointUrl } from '../infrastructure/urls';
|
|
2
6
|
import { rmBootstrapCertsAndClose } from '../util/clean-certs';
|
|
3
|
-
import {
|
|
4
|
-
BOOTSTRAP_PRIVATE_KEY_FILE_PATH,
|
|
5
|
-
BOOTSTRAP_CERTIFICATE_FILE_PATH,
|
|
6
|
-
AWS_ROOT_CERTIFICATE_FILE_PATH
|
|
7
|
-
} from '../util/directories';
|
|
7
|
+
import { AWS_ROOT_CERTIFICATE_FILE_PATH } from '../util/directories';
|
|
8
8
|
import { getDeviceUuid } from '../util/get-device-id';
|
|
9
9
|
import { logger } from '../util/logger';
|
|
10
10
|
import { BootstrapAgent } from './device-agent';
|
|
@@ -14,8 +14,8 @@ export async function bootstrapProvision() {
|
|
|
14
14
|
|
|
15
15
|
const clientId = getDeviceUuid();
|
|
16
16
|
const bootstrapConfig = {
|
|
17
|
-
keyPath:
|
|
18
|
-
certPath:
|
|
17
|
+
keyPath: getBootstrapPrivateKeyFilePath(),
|
|
18
|
+
certPath: getBootstrapCertificateFilePath(),
|
|
19
19
|
caPath: AWS_ROOT_CERTIFICATE_FILE_PATH,
|
|
20
20
|
clientId,
|
|
21
21
|
host: getIoTCoreEndpointUrl()
|