@balena/open-balena-api 31.2.6-build-service-install-filter-gc-c9e2c19bf3b53416385d9a272cb34f7d351d1b32-1 → 31.2.7-build-service-install-filter-gc-df260b150b12df0176acf3ee6f888cfe3479571a-1
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
|
|
1
1
|
import { tasks, sbvrUtils, permissions } from '@balena/pinejs';
|
2
2
|
import _ from 'lodash';
|
3
3
|
import { ASYNC_TASK_ATTEMPT_LIMIT, ASYNC_TASK_CREATE_SERVICE_INSTALLS_MAX_TIME_MS, } from '../../../lib/config.js';
|
4
|
+
import { ThisShouldNeverHappenError } from '../../../infra/error-handling/index.js';
|
4
5
|
const schema = {
|
5
6
|
type: 'object',
|
6
7
|
properties: {
|
@@ -43,7 +44,7 @@ const createServiceInstalls = async ({ devices, }) => {
|
|
43
44
|
},
|
44
45
|
},
|
45
46
|
};
|
46
|
-
const
|
47
|
+
const targetServicesByDevice = new Map((await api.resin.get({
|
47
48
|
resource: 'device',
|
48
49
|
passthrough: { req: permissions.rootRead },
|
49
50
|
options: {
|
@@ -57,14 +58,15 @@ const createServiceInstalls = async ({ devices, }) => {
|
|
57
58
|
id: { $in: devices },
|
58
59
|
},
|
59
60
|
},
|
60
|
-
})
|
61
|
-
|
62
|
-
...new Set(deviceWithServices.flatMap((device) => [
|
61
|
+
})).map((device) => {
|
62
|
+
const deviceServiceIds = [
|
63
63
|
...device.should_be_running__release,
|
64
64
|
...device.should_be_managed_by__release,
|
65
65
|
...device.should_be_operated_by__release,
|
66
|
-
].flatMap((release) => release.contains__image.flatMap((image) => image.image.map((img) => img.is_a_build_of__service.__id)))
|
67
|
-
|
66
|
+
].flatMap((release) => release.contains__image.flatMap((image) => image.image.map((img) => img.is_a_build_of__service.__id)));
|
67
|
+
return [device.id, [...new Set(deviceServiceIds)]];
|
68
|
+
}));
|
69
|
+
const serviceIds = [...new Set([...targetServicesByDevice.values()].flat())];
|
68
70
|
if (serviceIds.length === 0) {
|
69
71
|
console.info('[service-install-task] No service installs to create');
|
70
72
|
return 0;
|
@@ -137,23 +139,31 @@ const createServiceInstalls = async ({ devices, }) => {
|
|
137
139
|
console.info('[service-install-task] Task took too long. Created a new task for the remaining devices');
|
138
140
|
return totalSiCreated;
|
139
141
|
}
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
142
|
+
const targetServiceIds = targetServicesByDevice.get(device.id);
|
143
|
+
if (targetServiceIds == null) {
|
144
|
+
// This shouldn't be possible since devicesToAddServiceInstalls is a subset of targetServicesByDevice
|
145
|
+
ThisShouldNeverHappenError(`[service-install-task] Could not find device ${device.id} in the target targetServicesByDevice map`);
|
146
|
+
}
|
147
|
+
else {
|
148
|
+
// Use existingServiceIds as a Set for faster lookups on the follow up filter
|
149
|
+
const existingServiceIds = device.serviceInstalls;
|
150
|
+
const deviceServiceIds = _.difference(targetServiceIds, existingServiceIds);
|
151
|
+
await Promise.all(deviceServiceIds.map(async (serviceId) => {
|
152
|
+
// Create a service_install for this pair of service and device
|
153
|
+
await api.resin.post({
|
154
|
+
resource: 'service_install',
|
155
|
+
passthrough: { req: permissions.root, tx },
|
156
|
+
body: {
|
157
|
+
device: device.id,
|
158
|
+
installs__service: serviceId,
|
159
|
+
},
|
160
|
+
options: { returnResource: false },
|
161
|
+
});
|
162
|
+
}));
|
163
|
+
totalSiCreated += deviceServiceIds.length;
|
164
|
+
}
|
156
165
|
remainingDevices.delete(device.id);
|
166
|
+
targetServicesByDevice.delete(device.id);
|
157
167
|
}
|
158
168
|
return totalSiCreated;
|
159
169
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"service-installs.js","sourceRoot":"","sources":["../../../../src/features/ci-cd/tasks/service-installs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,EACN,wBAAwB,EACxB,8CAA8C,GAC9C,MAAM,wBAAwB,CAAC;
|
1
|
+
{"version":3,"file":"service-installs.js","sourceRoot":"","sources":["../../../../src/features/ci-cd/tasks/service-installs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,EACN,wBAAwB,EACxB,8CAA8C,GAC9C,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AAEpF,MAAM,MAAM,GAAG;IACd,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACX,OAAO,EAAE;YACR,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SACzB;KACD;IACD,QAAQ,EAAE,CAAC,SAAS,CAAC;CACrB,CAAC;AAEF,MAAM,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;AAM1B,KAAK,CAAC,cAAc,CACnB,yBAAyB,EACzB,KAAK,EAAE,OAAO,EAAE,EAAE;IACjB,IAAI,CAAC;QACJ,MAAM,cAAc,GAAG,MAAM,qBAAqB,CACjD,OAAO,CAAC,MAAyC,CACjD,CAAC;QACF,OAAO,CAAC,IAAI,CACX,kCAAkC,cAAc,mBAAmB,CACnE,CAAC;QACF,OAAO;YACN,MAAM,EAAE,WAAW;SACnB,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACZ,OAAO,CAAC,KAAK,CACZ,2DAA2D,CAAC,EAAE,CAC9D,CAAC;QACF,OAAO;YACN,KAAK,EAAE,GAAG,CAAC,EAAE;YACb,MAAM,EAAE,QAAQ;SAChB,CAAC;IACH,CAAC;AACF,CAAC,EACD,MAAM,CACN,CAAC;AAEF,MAAM,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BAC9B,qGAAqG;gBACrG,0BAA0B,CACzB,gDAAgD,MAAM,CAAC,EAAE,2CAA2C,CACpG,CAAC;YACH,CAAC;iBAAM,CAAC;gBACP,6EAA6E;gBAC7E,MAAM,kBAAkB,GAAG,MAAM,CAAC,eAAe,CAAC;gBAClD,MAAM,gBAAgB,GAAG,CAAC,CAAC,UAAU,CACpC,gBAAgB,EAChB,kBAAkB,CAClB,CAAC;gBAEF,MAAM,OAAO,CAAC,GAAG,CAChB,gBAAgB,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;oBACxC,+DAA+D;oBAC/D,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC;wBACpB,QAAQ,EAAE,iBAAiB;wBAC3B,WAAW,EAAE,EAAE,GAAG,EAAE,WAAW,CAAC,IAAI,EAAE,EAAE,EAAE;wBAC1C,IAAI,EAAE;4BACL,MAAM,EAAE,MAAM,CAAC,EAAE;4BACjB,iBAAiB,EAAE,SAAS;yBAC5B;wBACD,OAAO,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE;qBAClC,CAAC,CAAC;gBACJ,CAAC,CAAC,CACF,CAAC;gBAEF,cAAc,IAAI,gBAAgB,CAAC,MAAM,CAAC;YAC3C,CAAC;YACD,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACnC,sBAAsB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,cAAc,CAAC;IACvB,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@balena/open-balena-api",
|
3
3
|
"description": "Internet of things, Made Simple",
|
4
|
-
"version": "31.2.
|
4
|
+
"version": "31.2.7-build-service-install-filter-gc-df260b150b12df0176acf3ee6f888cfe3479571a-1",
|
5
5
|
"license": "AGPL-3.0",
|
6
6
|
"repository": {
|
7
7
|
"type": "git",
|
@@ -166,6 +166,6 @@
|
|
166
166
|
"loader": "ts-node/esm/transpile-only"
|
167
167
|
},
|
168
168
|
"versionist": {
|
169
|
-
"publishedAt": "2024-11-
|
169
|
+
"publishedAt": "2024-11-19T15:32:40.261Z"
|
170
170
|
}
|
171
171
|
}
|