Commit Graph

1434 Commits

Author SHA1 Message Date
Rich Bayliss
96c68166a1
application-manager: Convert to a singleton
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-09-14 11:23:36 +01:00
Rich Bayliss
e3864915bc
device-state: Convert to a singleton
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-09-14 09:31:12 +01:00
Rich Bayliss
d50f7791e1
api-binder: Convert to a singleton
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-09-14 09:31:12 +01:00
Cameron Diver
f305a333ba Add device system information to state endpoint patch
Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-09-03 14:40:29 +01:00
Miguel Casqueira
662826d349 added support for configuring ODMDATA
Closes: 1206
Change-type: minor
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-08-29 09:05:27 -04:00
Rich Bayliss
f0c2a3cba7
bug: Resolve mDNS API URLs
Due to switching to Alpine the ability to resolve mDNS
hostnames was lost. This patch overrides the lookup and
manually resolves the names.

Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-08-27 11:34:18 +01:00
Miguel Casqueira
7ea49bf4fb Preventing removing all configurations if device has no backends
Closes: #1437
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-08-24 13:41:17 -04:00
Cameron Diver
de4c1b2538 Don't enforce the vc4-fkms-v3d dtoverlay on rpi4
Change-type: patch
Closes: #1404
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-08-20 10:21:02 +01:00
Pagan Gazzard
379730a9e1 Update typed-error to 3.x
Update typed-error from 2.0.0 to 3.2.1

Change-type: patch
2020-08-19 10:07:54 +01:00
Pagan Gazzard
90fab43022 Update pinejs-client-request to 7.2.1
Update pinejs-client-request from 7.1.0 to 7.2.1

Change-type: patch
2020-08-18 18:28:10 +01:00
Miguel Casqueira
1d62209505 Refactor device-config to support configuring multiple backends
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-08-12 15:05:03 -04:00
Miguel Casqueira
ff404456b3 Refactor configurable backend class names
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-08-12 14:29:58 -04:00
Rich Bayliss
5aecd94e24
bug: Firewall not blocking supervisor access from outside the device
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-08-12 13:43:33 +01:00
Rich Bayliss
e9b536a889
bug: Allow DNS through firewall for local containers
We provide a local DNS server for containers to use and this
was not allowed through the firewall when enabled.

Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-08-11 15:17:06 +01:00
Cameron Diver
aa823c1cfc Fix device-tag fetching function
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-08-05 13:30:34 +01:00
Pagan Gazzard
511cbbe74e Update pinejs-client-request and make use of a named key
Update pinejs-client-request from 7.0.0 to 7.1.0

Change-type: patch
2020-08-03 09:27:11 +00:00
Nitish Agarwal
11cac2dd69 Fixes #1299 v1 start/stop endpoint issue with service access.
Change-Type: patch
Signed-off-by: Nitish Agarwal <1592163+nitishagar@users.noreply.github.com>
2020-07-31 23:08:50 +05:30
Rich Bayliss
59561132cc
bug: Fix undefined containerId object
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-07-31 11:51:15 +01:00
Miguel Casqueira
9b37ce96f9 fix matching extra_uEnv backend with unsupported devices
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-07-30 14:04:37 -04:00
Pagan Gazzard
ffe3da6261 Fix an issue with reporting initial config using a stale target state
Change-type: patch
2020-07-30 10:48:54 +01:00
Matthew McGinn
15c57a86b4
fix up "atleast" -> "at least"
Change-type: patch
Signed-off-by: Matthew McGinn <matthew@balena.io>
2020-07-29 11:55:22 -04:00
Miguel Casqueira
cac2e3612c Support setting device/fleet configuration in extra_uEnv.txt
Closes: #1385
Change-Type: minor
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-07-28 16:36:16 -04:00
Pagan Gazzard
eeda7e3ab1 Extract current state reporting to its own module
Change-type: minor
2020-07-24 17:35:17 +01:00
dt-rush
41987d8e76 log detection of changes to VPN status
Change-type: patch
Signed-off-by: dt-rush <nickp@balena.io>
2020-07-23 19:20:59 -04:00
Rich Bayliss
60132134de
common: Fix bug where aliases might be undefined
Should handle the scenario where the network aliases are undefined.

Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-07-23 16:41:40 +01:00
Miguel Casqueira
3b3babfd62 Fix docker-util using incorrect reference for function
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-07-21 20:02:20 -04:00
Cameron Diver
d14d8f31cc Fix purge and restart invocations by providing instanced apps
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-07-20 18:18:07 +01:00
Cameron Diver
d2a7d3b965 Fix purge invocations of new singletons
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-07-20 18:17:01 +01:00
Rich Bayliss
898c7e71da
bug: Fix unhandled promise rejection
When invoking iptables-restore it can fail. This wasn't handled
and this makes sure that it fails gracefully.

Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-07-13 13:05:12 +01:00
Cameron Diver
270f9f854a Fix bug where a promise was not resolved in db-format
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-07-08 12:05:09 +01:00
Cameron Diver
5337c0102c Convert deviceConfig module to a singleton
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-07-08 12:05:09 +01:00
Cameron Diver
03ca0ee9ad
avahi: Control with HOST_DISCOVERABILITY
The host config variable HOST_DISCOVERABILITY can be set to
true or false, controlling the state of the avahi service. This
determines if the device advertises it's presence over mDNS.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-07-06 13:02:29 +01:00
Rich Bayliss
28c5a44e71
firewall: Add Host Firewall functionality
Controlled by BALENA_HOST_FIREWALL_MODE, the firewall can
either be 'on' or 'off'.

- In the 'off' state, all traffic is allowed.
- In the 'on' state, only traffic for the core services provided
  by Balena is allowed.

Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-07-01 18:43:08 +01:00
Miguel Casqueira
59fc589eb2 Added support for configuring FDT directive in extlinux.conf
Change-type: minor
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-06-23 15:56:10 -04:00
Miguel Casqueira
3098abeca5 Refactor backends into seperate files and added tests for extlinux
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-06-23 15:56:10 -04:00
Rich Bayliss
1b91ef3405
state: Report device MAC address to the API
When reporting device information, send the MAC address of any
interfaces on the system. Also expose in the Supervisor API at
the route GET /v1/device.

Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-06-22 10:41:06 +01:00
Pagan Gazzard
c15f77434b Update pinejs-client-request to 7.x
Update pinejs-client-request from 5.2.0 to 7.0.0

Change-type: patch
2020-06-18 12:24:52 +00:00
Cameron Diver
0e8d92e08a Make service-manager module a singleton
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-17 14:56:57 +00:00
Cameron Diver
adaad786af Make volume-manager module a singleton
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-17 14:56:57 +00:00
Cameron Diver
8fc97b9de8 Make network-manager module a singleton
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-17 14:56:57 +00:00
Akis Kesoglou
1dccbaecd8 Use API v6
See: https://github.com/balena-io/open-balena/issues/80
Change-type: minor
2020-06-15 13:57:32 +03:00
Cameron Diver
695d91d494 Db-format module code fixups
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-15 10:53:21 +01:00
Robert Günzler
ae646a07ec Add label to expose gpu to container
In the absence of an upstream implementation of the DeviceRequest API introduced
as part of Docker API v1.40 we roll our own using a feature label.

As per my comment in the code, we fall back to the default behavior of
docker cli's `--gpu` and request single device with the `gpu` capabilty.
The only implementation at the moment is the NVIDIA driver; here:
https://github.com/balena-os/balena-engine/blob/master/daemon/nvidia_linux.go

Background on the composefile implementation:
https://github.com/compose-spec/compose-spec/issues/74
https://github.com/docker/compose/issues/6691

Change-type: patch
Connects-to: https://github.com/balena-os/balena-jetson/pull/75
Signed-off-by: Robert Günzler <robertg@balena.io>
2020-06-11 14:06:16 +02:00
Cameron Diver
b31d5007fb Move database app processing out to its own module
This is part of the work to make the application-manager module much
less monolithic, in preperation for system apps and more generally
multi-app.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-11 11:55:11 +01:00
Cameron Diver
c0e170c61f Make target-state-cache a singleton
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-11 11:55:11 +01:00
Cameron Diver
b5918f0d84 Respect an initialDeviceName field in the config.json
Closes: #909
Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-10 13:27:03 +01:00
Cameron Diver
2b3dc2fbce Make images module a singleton
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-10 11:29:28 +01:00
Rich Bayliss
b89425c607
fix: API auth missing on state GET/PATCH
When performing a state GET/PATCH the authentication header was being
missed off.

Change-type: patch
Signed-off-by: Rich Bayliss
2020-06-09 15:03:16 +01:00
Cameron Diver
651e48b1bd Make logger module a singleton
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-08 17:19:20 +01:00
Pagan Gazzard
e37b52dd68 Fix exponential backoff for state polling
Change-type: patch
2020-06-08 15:41:11 +01:00
Cameron Diver
389e14ec6b Make the event-tracker module a singleton
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-08 10:13:33 +01:00
Pagan Gazzard
17a5d8dd49 Isolate target state fetching to its own module which emits on update
Change-type: minor
2020-06-03 17:37:38 -04:00
Cameron Diver
aad20e2c2f Make docker module a singleton
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-02 17:57:18 +01:00
Cameron Diver
ff4a31a0e6 Make the config module a singleton
Change-type: patch
Co-authored-by: Pagan Gazzard <page@balena.io>
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-02 14:29:05 +01:00
Miguel Casqueira
5550a3a330 Refactor device-state healthchecks to log reason for failure
Closes: #1292
Change-type: minor
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-05-29 16:24:01 -04:00
Miguel Casqueira
ef83acdaeb Refactor api-binder healthchecks to log reason for failure
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-05-29 16:14:58 -04:00
Pagan Gazzard
1decd87c21 Update dependencies
Change-type: patch
2020-05-29 14:22:23 -04:00
Cameron Diver
1d7381327e Make the db module a singleton
We were treating the database class as a singleton, but still having to pass
around the db instance. Now we can simply require the db module and have
access to the database handle.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-05-29 15:02:38 +01:00
Cameron Diver
972b896c95 Check for ApiError before using it as such
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-05-26 14:43:59 +01:00
Cameron Diver
eaaa9c257e check for 409 status code, rather than string matching uuid conflicts
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-05-21 14:57:26 -04:00
Cameron Diver
87278c0d8c Use safeStateClone to avoid call-stack exceeding errors
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-05-21 16:47:09 +01:00
Miguel Casqueira
db7c27037c Improved handling of invalid appId in V2 state endpoint
Closes: #1294
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-05-19 10:53:19 -04:00
Pagan Gazzard
fb90042c39 Switch to balenaApi for the state patch as patching cannot be cached
Change-type: patch
2020-05-18 18:17:48 +00:00
Cameron Diver
6972dcd92d Fix leftover spurious return from typescript conversion
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-05-18 15:21:33 +01:00
Pagan Gazzard
dc187f0036 Catch errors in the target state poll so polling will always continue
Change-type: patch
2020-05-18 14:14:52 +01:00
Pagan Gazzard
afae5d15d4 Avoid querying instantUpdates on every state poll
Change-type: patch
2020-05-18 13:23:44 +01:00
Pagan Gazzard
b05d597ade Fix default request options
Change-type: patch
2020-05-16 14:05:47 +01:00
Miguel Casqueira
466c7999db Remove CoffeeScript tests and all CoffeeScript tools
Closes: #1318
Change-Type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-05-15 13:01:51 -04:00
Pagan Gazzard
758f3caa48 Update to @balena/lint 5.x
Change-type: patch
2020-05-15 12:08:42 +01:00
Cameron Diver
58c6a69e5a Add a random offset to the poll interval with each poll
Change-type: patch
Closes: #1242
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-05-15 10:34:06 +01:00
Cameron Diver
0bceffffb6 Cache service names in local log backend
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-05-14 09:41:40 +01:00
Miguel Casqueira
838c1ebba4 Correctly check if value is a valid Integer
Closes: #1180
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-05-12 12:42:14 -04:00
Miguel Casqueira
8295858b32 Added endpoint to check if VPN is connected
Change-type: minor
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-05-11 21:21:44 -04:00
Miguel Casqueira
402a85cf2b Decoupled checking VPN status from notify callback
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-05-11 20:43:03 -04:00
Pagan Gazzard
913418bb37 Remove unnecessary config.json keys
Change-type: patch
2020-05-08 12:56:42 +01:00
Miguel Casqueira
60c07fc2fc Move SupervisorAPI state change logs to appropriate functions
Closes: #1277
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-05-07 13:48:12 -04:00
Cameron Diver
8f09022d1f Don't use the openvpn alias to check VPN status
Closes: #1293
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-05-06 17:15:44 +01:00
Cameron Diver
31957566e5 Remove legacy fallback to DROP rule in iptables
This has not been necessary for a long time, and wwe can now remove it.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-05-05 12:15:19 +01:00
Cameron Diver
7b1f03ced5 Add an ESTABLISHED flag to API iptables rules
This allows a response to an input with dport=`supevisor api port` and
is required when the host OS is doing stateful firewalling.

This should not affect things when stateful firewalling is not in
effect, as the standard OUTPUT chain policy is ACCEPT, so we're just
being explicit about it.

Change-type: patch
Backport-to: next, current, sunset
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-05-05 12:15:12 +01:00
Miguel Casqueira
2007a98940 Added Bearer Authorization spec
Closes: #1249
Change-type: minor
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-05-04 13:22:58 -04:00
Cameron Diver
f599799950 Remove double printing of API status error
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-04-21 09:51:56 +01:00
Cameron Diver
f791424829 ⤴️ Upgrade migrations to work with knex
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-04-15 13:37:50 +01:00
Cameron Diver
a43d71d1ac 📄 Upgrade knex to avoid CVE-2019-10757
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-04-15 13:37:50 +01:00
Cameron Diver
826eec2e4f 🚀 Update supervisor to node12
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-04-13 14:36:59 +01:00
Cameron Diver
68936a10a8 Rename systemd.ts to dbus.ts
This is because it's more general, and just provides methods which act
over dbus.

Signed-off-by: Cameron Diver <cameron@balena.io>
2020-04-13 10:32:51 +01:00
Cameron Diver
37feb7e325 Move from dbus-native to dbus
Closes: #1049
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-04-13 10:07:14 +01:00
Cameron Diver
c9c0e650cb Support matching on device type within contracts
Closes: #1191
Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-04-09 10:45:07 +01:00
Pagan Gazzard
a59af6abe8 Workaround a circular dependency
Change-type: patch
2020-04-08 17:40:39 +01:00
Pagan Gazzard
a2ec35456b Convert application-manager.coffee to javascript
Change-type: patch
2020-04-08 12:15:06 +01:00
Cameron Diver
0a429f60a5 Add newTargetState event and use it for backup loading
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-04-07 14:50:34 +01:00
Cameron Diver
dda6270219 Don't wrap UpdatesLockedErrors with a detailed error
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-04-07 13:12:24 +01:00
Cameron Diver
0950b66c52 Allow spaces in volume definitions
Closes: #1247
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-04-07 10:35:34 +01:00
Pagan Gazzard
81927d7861 Update to balena-register-device 6.0.1
Change-type: patch
2020-04-06 17:45:03 +01:00
Pagan Gazzard
98e956831a Convert test/18-compose-network.coffee to javascript
Change-type: patch
2020-04-02 14:25:24 +01:00
Pagan Gazzard
dcb01cb863 Convert test/16-ports.spec.coffee to typescript
Change-type: patch
2020-04-02 14:25:21 +01:00
Cameron Diver
3c59944ce1 Pass in deviceId when fetching device tags
Change-type: patch
Closes: #1237
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-03-31 12:44:31 +01:00
Cameron Diver
3af89cd13f Add BALENA_DEVICE_ARCH environment variable for containers
Closes: #1232
Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-03-30 16:40:02 +01:00
Cameron Diver
6b827a3f57 Don't throw an error when getting an unhealthy state
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-03-30 10:07:50 +01:00
Pagan Gazzard
15fca80d2d Convert src/device-api/common.coffee to javascript
Change-type: patch
2020-03-28 13:38:34 +00:00
Pagan Gazzard
6ab69e1a69 Switch to mz for the proxyvisor
Change-type: patch
2020-03-27 17:50:30 +00:00
Pagan Gazzard
c1e5b98ae5 Convert proxyvisor to javascript
Change-type: patch
2020-03-27 17:49:01 +00:00
Pagan Gazzard
686f72ecf7 Remove unnecessary code from application-manager
Change-type: patch
2020-03-26 23:50:53 +00:00
Pagan Gazzard
2a50a4262d Improve types used by application-manager 2020-03-26 23:40:16 +00:00
Pagan Gazzard
968e2ba0fb Switch to a named export for application-manager
Change-type: patch
2020-03-26 23:39:21 +00:00
Pagan Gazzard
56c13fb963 Convert device-api/v1 to javascript
Change-type: patch
2020-03-25 12:16:53 +00:00
Pagan Gazzard
9c3295c912 Add type checking for javascript files
Change-type: patch
2020-03-24 16:37:28 +00:00
Cameron Diver
f2c606e1f9 Update dependencies
We also pin livepush in place while
https://github.com/balena-io-modules/livepush/issues/67
is fixed.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-03-24 14:52:22 +00:00
Pagan Gazzard
81966446d9 Update to balena-lint and enable javascript linting
Change-type: patch
2020-03-24 09:28:12 +00:00
Matthew McGinn
ab7e8b5514 logging: fix up some typos
Change-type: patch
Signed-off-by: Matthew McGinn <matthew@balena.io>
2020-03-16 15:28:50 -04:00
Pagan Gazzard
6e3db3bd60 Update dependencies
Change-type: patch
2020-03-13 17:18:05 +00:00
Cameron Diver
5c50f656c3 Allow semver comparison on l4t versions in contracts
We add an implicit .0 to the end of l4t versions which do not fulfill
semver, which allows us to always match using comparison operators, such
as < and <=.

Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-03-06 15:54:04 +00:00
Cameron Diver
7d47661928 Allow l4t versions with three numbers as well as two
Closes: #1210
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-03-06 10:27:43 +00:00
Rich Bayliss
e0d2bdfaa9
config: Support loading SSDT via ConfigFS
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-03-05 13:30:06 +00:00
Cameron Diver
cf76875f64
Improve dependent and preload typings
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-02-25 14:50:21 +07:00
Cameron Diver
c21da8f3db
Convert device-state module to typescript
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-02-25 14:50:21 +07:00
Cameron Diver
2309442555
Improve application-manager typings
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-02-25 14:50:20 +07:00
Cameron Diver
e161888516
Improve and extend internal typings
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-02-25 14:50:20 +07:00
Ivan
b5772740ae Add a containerId request parameter for journal-logs api endpoint, and pass it along to journalctl process options.
Change-Type: minor
Signed-off-by: Ivan <ivanign04.alt@gmail.com>
2020-02-22 16:42:38 -07:00
Cameron Diver
89a9d85e87
Add procfs label
Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-02-13 11:00:34 +07:00
Cameron Diver
947deb3cc6
Add a sysfs feature label
The new label `io.balena.features.sysfs` will mount the host /sys into
the container at /sys.

Relates to issue: #743

Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-02-13 11:00:34 +07:00
Cameron Diver
7dcb4fa887
Clean up the feature label function
Bring the labels into a more declarative format and run through them to
apply the various labels and env vars.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-02-13 11:00:33 +07:00
Cameron Diver
a27ce4f1dc
Dont error on a target state with multiple apps
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-02-10 12:06:12 +07:00
Rich Bayliss
fe5fd2b7ef
bug: Delay sending logs until the device is provisioned
Connects-to: #1189
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-02-06 10:21:27 +00:00
Cameron Diver
3ff3bce605 Allow getting the target state when not in local mode
Change-type: patch
Closes: #1176
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-01-30 11:24:59 +00:00
Pagan Gazzard
027701297b Update knex types
Change-type: patch
2020-01-17 13:59:24 +00:00
Pagan Gazzard
1a393dbb19 Update lodash types
Change-type: patch
2020-01-17 13:51:55 +00:00
Pagan Gazzard
0ef9cc189b Update types and fix issue with treating string as a number
Change-type: patch
2020-01-17 13:06:27 +00:00
Cameron Diver
6e7a190ff0
Remove unnecessary awaits
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-01-16 11:14:39 +00:00
Cameron Diver
53b6e8f1bb
Increase minimum backoff delay and use poll interval as max
This change will start the minimum backoff from 15s (up from 500ms) and
will use the appUpdatePollInterval configuration variable as the max.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-01-16 11:14:00 +00:00
Cameron Diver
426d8cd10a
Ensure that we always have the pi4 overlay assigned
Change-type: patch
Closes: #1171
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-01-08 17:06:19 +00:00
Cameron Diver
4b0f431f9b
Throttle state report patches to once per 10 seconds
Change-type: patch
Closes: #1158
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-12-19 12:32:38 +00:00
Cameron Diver
2d4ac24403
Report the correct error when we cannot remove a network
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-12-18 15:02:18 +00:00
Cameron Diver
8317a1843b
Always do a standard docker download on first pull
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-12-17 10:34:28 +00:00
Cameron Diver
4a74dffea9
Don't allow cross-app delta requests
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-12-16 12:58:09 +00:00
Cameron Diver
6db1f03411
fix: ⬇️ Force a regular pull when moving from v2 to v3 deltas
Change-type: patch
Fixes: #1072
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-12-16 10:42:46 +00:00
Roman Mazur
4895bb300a
Add steps info to applyState error message
This helps to debug/diagnose problems with state application faster.

Change-type: patch
Signed-off-by: Roman Mazur <roman@balena.io>
2019-12-12 16:22:43 +02:00
Roman Mazur
d9c669ebad
Hide init method in configJson
ConfigJson users now don't need to worry about initialization.
It's done lazily on the first public method call.

Implementation is also rewritten to follow async/await pattern.

Change-type: patch
Signed-off-by: Roman Mazur <roman@balena.io>
2019-12-11 19:19:47 +02:00
Cameron Diver
03a701cded
Always filter environment configuration
This means that if an image is created with a committed container, we
won't assume that it does not contain the balena env vars

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-12-09 11:28:34 +00:00
Rich Bayliss
c3cf8fbca2
volumes: Allow the use of the 'driver' setting in volumes
A compose file can now contain a volume which uses a different driver
from the default one; local.

Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2019-12-02 11:59:44 +00:00
Cameron Diver
8cece238a9 Set a mock l4t version for use with optional containers
Before this change a mixed device fleet with a subset using l4t would
not be able to have containers which only run on the l4t based boards.
We add a mock l4t version so the contracts will always be denied on
non-l4t boards, but the release itself won't fail to validate.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-11-29 11:07:04 +00:00
Cameron Diver
f4605d897e
Handle cancelDelay not being a function
Change-type: patch
Closes: #1080
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-11-28 11:28:04 +00:00
Cameron Diver
1a6c9d489a
Consider linux4tegra versions in container contracts
Also remove ability to match on OS versions

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-11-27 10:22:35 +00:00
Cameron Diver
e44c7073f9
Fix retrieval of container log timestamp from db
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-11-20 11:23:11 -08:00
Theodor Gherzan
8589dbf3d1
Refactor code to use async/await syntax
Signed-off-by: Theodor Gherzan <theodor@balena.io>
2019-11-16 19:43:22 +00:00
Theodor Gherzan
1570fd424b
Create config.txt if there isn't one already
Change-type: patch
Signed-off-by: Theodor Gherzan <theodor@balena.io>
2019-11-16 18:43:31 +00:00
Theodor Gherzan
659697ff79
Extract backup logic to migration
Part of device-state refactor
Fix the wrong usage of TargetState as DeviceApplicationState

Change-type: patch
Signed-off-by: Theodor Gherzan <theodor@balena.io>
2019-11-15 17:39:48 +00:00
Theodor Gherzan
54e9c2edd8
Run new prettier on code base
Signed-off-by: Theodor Gherzan <theodor@balena.io>
2019-11-15 14:51:24 +00:00
Pagan Gazzard
05a566dcb5 Switch to balenaos-in-container
Change-type: patch
2019-11-12 13:50:05 +00:00
Michel Wohlert
597f95e169 Check if appId is a number before purging
Change-Type: patch
Signed-off-by: Michel Wohlert <michel@1012consulting.io>
2019-11-10 08:07:57 -08:00
Theodor Gherzan
cf79ed8cdb
Extract normaliseLegacy as normalise to migration module
Change-type: patch
Signed-off-by: Theodor Gherzan <theodor@balena.io>
2019-11-07 17:48:50 +00:00
Cameron Diver
053e111626
Define the database type of the application
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-11-07 09:47:19 +00:00
Cameron Diver
09a8231fde
Extract loadTargetFromFile function to preload module
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-11-07 09:47:19 +00:00
Cameron Diver
fea80c5205
Define TargetApplicationState in types and remove Application type
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-11-06 17:52:16 +00:00
Roman Mazur
2143180d27
event-tracker: Use std mixpanel types
Custom type definitions are removed for mixpanel module since they are embedded
into their npm package.

Change-type: patch
Signed-off-by: Roman Mazur <roman@balena.io>
2019-11-05 18:09:09 +02:00
Cameron Diver
8223bf2ccb Report any optional containers that aren't being run
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-11-05 14:44:22 +00:00
Cameron Diver
f75b8aad2b
Support optional containers based on their contract
Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-11-05 10:11:30 +00:00
Cameron Diver
b5a427f2b9
Convert some coffeescript tests to typescript
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-10-30 10:58:32 +00:00
Cameron Diver
9651bc7028
Ensure that we reset rate limits after a successful target apply
Change-type: patch
Closes: #1117
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-10-28 11:54:11 +00:00
Cameron Diver
7b8e7ea8ca
Add a cache around the database application target state
Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-10-07 14:16:31 +01:00
Cameron Diver
d16403f654
Correctly validate container contracts
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-10-02 15:48:17 +01:00
Cameron Diver
14e442f943 Add support for container contracts
These contracts can specify an OS version and supervisor version that
they require. If any of the containers in a release have requirements
that are not met, the release is rejected, and the previous release
continues to run.

Change-type: minor
Closes: #1086
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-10-01 16:17:44 +01:00
Cameron Diver
9843f62e24 Upgrade io-ts and fp-ts to 2.0.0
Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-10-01 16:17:44 +01:00
Cameron Diver
5ce8ba8acf Add contract resolution code, which checks release requirements
Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-10-01 16:17:43 +01:00
Cameron Diver
2d168784b2 Avoid synchronous file accesses for os release info
This also required refactoring the request library to be generated with
a promise, as we now no longer get the information synchronously.

We also cache the release info, to avoid grabbing it again within the
same runtime, which does not make sense.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-10-01 16:17:43 +01:00
Cameron Diver
7239b93f4a Add a cache around the database application target state
Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-09-26 15:03:36 +01:00
Roman Mazur
8b4c9837fa
Unify API errors processing
With this change, we define a custom error handler as express middleware
which renders 503 error with JSON response that includes status and message
fields.

The handler also logs the error, so the stack can be inspected in supervisor
logs. It's also a point where we can report the error to analytics services.

This removes a bunch of error handlers written in every request handler
function. Behaviour should remain unchanged except the fact that
/healthy endpoint now returns 503 in case of failure instead of 500.

Change-type: patch
Signed-off-by: Roman Mazur <roman@balena.io>
2019-09-23 17:20:38 +03:00
Matthew McGinn
8d5633a11f
ping: move /ping out from authentication
Change-type: patch
Signed-off-by: Matthew McGinn <matthew@balena.io>
2019-09-20 15:16:47 +02:00
Cameron Diver
15a1f45fd7 Explicitly remove volumes when purging
Change-type: patch
Closes: #1083
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-09-18 08:48:26 +01:00
Cameron Diver
7d1da38184 Catch and report cloud stream writing errors
If an error fires when writing to the cloud stream, it can stop any
calling processes from completing. Given that a logging failure should
not cause other processes to cancel, we catch and report the error but
otherwise do nothing else.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-09-18 08:48:26 +01:00
Cameron Diver
e78f8eccdc
Correctly handle partial IPAM configurations for networks
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-09-16 12:27:06 +01:00
Gergely Imreh
ca9f8ffca1
device-state: correctly call volume creation on backup restore step
The `createFromPath` method takes 3 parameters, while in a previous
version it was only 2 (the new format splits the old format's first
parameter into two, and keeping the last), before the refactor in commit
23e564389d (supervisor v9.18.4)
The backup restoration call has not been updated and thus calls that
function the old (wrong) way, resulting in failed restore, and volume
management errors on a device that attempted a restore.

Change-type: patch
Signed-off-by: Gergely Imreh <gergely@balena.io>
2019-09-11 12:11:05 +01:00
Thomas
e3c1c333f0
Modification to unpacking volume backup
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-09-02 13:28:30 +01:00
Cameron Diver
48bccd34db Add journald format flag
Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-08-21 15:02:05 +01:00
Cameron Diver
2d924b83fc Update documentation and explicitly unpipe journald stream
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-08-21 15:02:05 +01:00
Cameron Diver
ded828da9a Correctly generate network or volume creation steps
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-08-21 10:48:38 +01:00
Cameron Diver
4f31b18670
Extract composition step work out to typescript compose module
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-08-19 17:00:39 +01:00
Cameron Diver
bd022df8bd
Add default exports for Volume and Network modules
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-08-19 17:00:38 +01:00
Cameron Diver
55ee5a468f
Remove unused local mode parameter from images.getAvailable
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-08-19 17:00:38 +01:00
Cameron Diver
76de276b92
Only consider certain array fields without order
Various fields returned from the docker daemon don't retain order (for
example the volumes field). We now only select certain array values to
compare taking order into account.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-08-19 14:55:06 +01:00
Cameron Diver
86e8a85640
Take order into account when comparing service config arrays
Change-type: patch
Closes: #1060
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-08-15 17:07:22 +01:00
Cameron Diver
43cbf7dbba
Add an endpoint and module for reading journald logs
Change-type: minor
Closes: #1003
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-08-09 11:08:29 +01:00
Cameron Diver
c62f4afe8d
api: Avoid cloneDeep when copying target state.
This can cause issues where the stack is exhausted
on large applications.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
Signed-off-by: Heds Simons <heds@balena.io>
2019-07-25 15:23:18 +01:00
Roman Mazur
4688524e45
Filter both null and omitted values
The docker daemon can sometimes return null for various fields,
or omit the field altogether. The best thing to do with using
the docker api is to always use == null to cover both instances.

Change-type: patch
Signed-off-by: Roman Mazur <roman@balena.io>
2019-07-25 13:03:04 +03:00
Roman Mazur
4b56022d93
Use typed error to report inspection problems
This will throw a typed error in case when supervisor cannot inspect
its own container.

Change-type: patch
Signed-off-by: Roman Mazur <roman@balena.io>
2019-07-25 13:03:03 +03:00
Roman Mazur
4846acb25e
Prevent supervisor from deleting itself
With recent changes to local mode behavior, supervisor removes all engine objects
that were not present before entering local mode.
With this change, supervisor also detects its own resources and does not delete them
if it was updated during local mode operations.

Change-type: patch
Signed-off-by: Roman Mazur <roman@balena.io>
2019-07-25 13:02:57 +03:00
Rich Bayliss
f9aa4681fa
api: Perform network checks if device is unmanaged
Without these checks the API GET /v1/device doesn't return a
value for `ip_address`.

Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2019-07-24 15:40:53 +01:00
Cameron Diver
c109a24874 Support network_modes of service:<servicename>
That way that this is performed is by first adding a depends_on entry
for the target service if it appears in a network mode. Then when we
generate the docker container for this service, we use the containerId
of the target container and replace the network_mode with
`container:<id>`.

When comparing state, we check that the containerId still points to the
contianerId of the target container, and in this way we ensure that
when a network mode target container changes, we change the dependent
container too.

Change-type: minor
Closes: #851
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-07-23 13:41:19 +01:00
Cameron Diver
e91fa6e7b3
fix: Always reboot when applying boot config
Change-type: patch
Closes: #1037
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-07-22 16:07:39 +01:00
Cameron Diver
cbb079e8dc
fix: Don't consider volume supervised labels when comparing
Change-type: patch
Closes: #1039
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-07-19 12:17:38 +01:00
Matthew McGinn
2cb6ecc150
device-api: fix up small typos
Change-type: patch
Signed-off-by: Matthew McGinn <matthew@balena.io>
2019-07-18 13:07:53 +01:00
Cameron Diver
a796777967 Don't attempt to cleanup any target state referenced volumes
The code before this change could potentially remove a volume which
should not be removed if a container was deleted before the call that
references said volume.

To avoid this, we additionally filter the list of volumes to cleanup by
any that are referenced in the target state. This means that cleanup
will never remove it, as long as it's still supposed to be there,
regardless of if a container references it or not.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-07-11 16:35:29 +01:00
Cameron Diver
e076622fe6 Don't remove volumes when switching into local mode
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-07-10 14:25:47 +01:00
Cameron Diver
3304825216 Add a supervisor endpoint to cleanup orphaned volumes
Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-07-10 14:25:44 +01:00
Cameron Diver
5357d4729d Only remove volumes when we're moving between applications
Change-type: major
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-07-10 14:25:22 +01:00
Cameron Diver
bb549a445b Dont try to set the commit if it's undefined
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-07-10 14:25:21 +01:00
Cameron Diver
37945b4aa5 Don't attempt to setup a log stream to the cloud before provision
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-07-09 13:21:05 +01:00
Cameron Diver
20a83e8e0a Add more typescript conversions and export utilities from existing
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-07-09 13:21:05 +01:00
Michel Wohlert
39c9810bbc Merge remote-tracking branch 'balena/master' into instantly-apply-update-on-api-request 2019-07-09 13:10:15 +02:00
Michel Wohlert
7a42b6719a Apply targetState immediately after update request
Cancel delayed promise if exists and schedule a new one without delay, when /v1/update is called

Change-type: patch
2019-07-06 00:06:42 +02:00
Cameron Diver
89807c21fa
Fix network composition parsing, and correctly report compose config
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-07-04 11:47:39 +01:00
Cameron Diver
e5d7379b74
Keep the network and volume models consistent across usage
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-07-03 10:42:42 +01:00
Cameron Diver
eaff3a2ee5
Pass around instantiated Network objects when comparing state
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-07-03 10:36:38 +01:00
Cameron Diver
23e564389d
Seperate volume handling into manager and object classes
This change also makes sure that in the application-manager workflow we
pass around instances of the Volume class, rather than just the config.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-07-03 10:36:37 +01:00
Pablo Carranza Velez
743c8406c9 fix: When reporting initial config, avoid creating a "VPN enabled" unnecessary override
Since we were comparing the VPN's value before adding the explicit "true", there were cases
were the VPN is off, and therefore "value" didn't match the default, so the supervisor would
create a device specific SUPERVISOR_VPN_CONTROL = true, which is unnecessary and causes issues if
users don't expect this and move the device to an app that has VPN disabled. The correct behavior
is to compare "varValue" and only create a device config var if this value differs from the default.

(This was the behavior before the TS conversion in 01ed7bb103 )

Change-type: patch
Signed-off-by: Pablo Carranza Velez <pablo@balena.io>
2019-07-01 12:28:46 -07:00
Roman Mazur
645bc6c185
Ensure we get input on parsing errors
We wrap JSON and date parsing code to ensure input data is logged in case of an error.

Change-type: minor
Signed-off-by: Roman Mazur <roman@balena.io>
2019-06-26 17:40:02 +03:00
Roman Mazur
7c4d8d7653
Ensure local mode switch runs before target state
This change makes DeviceState to wait until local mode switch is definitely
completed before actually applying the state, which avoids races in state cleanup.

Change-type: patch
Signed-off-by: Roman Mazur <roman@balena.io>
2019-06-26 17:40:02 +03:00
Roman Mazur
4974c9200c
Clean up local mode engine objects using snapshots
Snapshot is collected to compare with engine state when local mode is turned off.

Change-type: minor
Signed-off-by: Roman Mazur <roman@balena.io>
2019-06-26 17:40:01 +03:00
Roman Mazur
024b9c45f4
Report device state in local mode
In local mode, we now update device status on the backend,
but omit applications info in our updates.

Closes: #959
Change-type: minor
Signed-off-by: Roman Mazur <roman@balena.io>
2019-06-20 15:38:33 +03:00
Cameron Diver
8c69ae7645 Don't drop failed api patch data
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-06-20 12:56:10 +01:00
Cameron Diver
65019bb5bc
Fix typo in image selection
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-06-11 13:10:44 +01:00
Cameron Diver
b1e4e8399b
Re-parallelise current image retrieval code
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-06-11 07:50:38 +01:00
Cameron Diver
9c486275c9
Revert "Add a controlling variable for mixpanel reporting"
This reverts commit 1a7ed0f95b.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-06-10 20:53:33 +01:00
Cameron Diver
ea64f0b0b3 Upgrade typescript and fix warnings
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-06-10 15:35:43 +01:00
Cameron Diver
2276dd54e1 Standardise all supervisor output logging
Also use the supervisor's own container logging monitoring code when
running livepush on the supervisor container.

Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-06-10 11:38:45 +01:00
Cameron Diver
1a7ed0f95b
Add a controlling variable for mixpanel reporting
Change-type: patch
Closes: #990
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-05-29 11:53:47 +01:00
Cameron Diver
8279678052
Add wrapper around container logs saving, to reduce db load
Changes are collected together and exist in memory, for querying and
saving. Once every 10 mins, every changed timestamp is flushed to the
database.

Change-type: patch
Closes: #987
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-05-28 15:56:11 +01:00
Cameron Diver
2a27b1d51f Move to resin-lint 3 and fix lint errors
This is a massive commit, but nothing related to runtime has actually
changed, only the lint errors have changed.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-05-26 18:54:09 +01:00
Cameron Diver
1155d757e4 Make delta application logs easier to parse for multicontainer
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-05-15 12:41:27 +01:00
Cameron Diver
4e783fcd86 Allow system messages to not be tracked
Also don't track update lock events

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-05-15 10:19:15 +01:00
Cameron Diver
50fdee4290 Format update lock logs with pretty-ms
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-05-15 10:19:14 +01:00
Cameron Diver
27b68b5845 Display update lock notification in dashboard logs
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-05-15 10:18:48 +01:00
Cameron Diver
5894a9baf3 Show better logs for UpdatesLockedError
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-05-15 10:18:47 +01:00
Cameron Diver
5ace459ad2 Clear backoff counter on new target state
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-05-15 10:18:47 +01:00
Cameron Diver
932a6f2997
Fix supervisor tests for node v10.12.0 and above
Changes in the node engine related to streams would cause the gzip
streams flush function to be called at the wrong times. The sinon fake
timers were also interacting with this.

We use setImmediate to call the flush function, and remove sinon timers
for the logging tests.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-05-10 12:36:46 +01:00
Cameron Diver
51703621a5
Cache delta auth token request results for 10 minutes
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-05-10 11:17:48 +01:00
Cameron Diver
76e0361b0e Fix dockerode type failures
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-05-03 11:31:13 +01:00
Cameron Diver
8424fb44f6 Perform case-insensitive checking when converting booleans from strings
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-05-01 12:33:20 +01:00
Cameron Diver
9fae4bab62 fix: Run db log cleanup on init - after migrations
Before this change the first time the cleanup code runs would be before
the migrations have had a chance to execute. This change makes it so
that the cleanup code always runs once the migrations have finished.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-04-25 16:56:29 +01:00
Cameron Diver
0fa47f635b
fix: Correctly handle multiple hosts ports pointing to a container port
When assigning multiple host ports to a single container port before
this change, the supervisor would incorrectly take only the first host
port into consideration. This change makes it so that every host port
per container port is considered.

Closes: #986
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-04-25 13:48:04 +01:00
Cameron Diver
9e3fae5852
compose: Remove unique expose entries after adding all entries
Prior to this change, we would `_.uniq` the expose value before adding
values from the port mappings. This could cause ports to get added
twice, which would cause the supervisor to think that there is a
configuration mismatch.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-04-11 10:20:20 +01:00
Cameron Diver
892cf1961e
Don't attempt to report any state during local mode
Even though this would never have attempted to report the state to the
api during local mode, it leaves behind artifacts which would cause the
state to be sometimes reported when exiting local mode. This would cause
the api to reject the update unecessarily.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-04-10 15:40:52 +01:00
Cameron Diver
80031b76e4
types: Upgrade dockerode types, and remove fixes which are superceded
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-04-08 10:46:28 +01:00
Cameron Diver
5943d3117c
Run database cleanup on startup in addition to once a day
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-04-05 10:06:29 +01:00
Cameron Diver
760b18dd2a
fix: Fix non-tty container message parsing
This had a bug where it was using the `in` operator on a list. It may
have worked for some cases, but would have failed for others.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-04-05 10:06:28 +01:00
Cameron Diver
e148ce0529
Report all logs from a container's runtime
We add a database table, which holds information about the last
timestamp of a log successfully reported to a backend (local or remote).
We then use this value to calculate from which point in time to start
reporting logs from the container. If this is the first time we've seen
a container, we get all logs, and for every log reported we save the
timestamp. If it is not the first time we've seen a container, we
request all logs since the last reported time, ensuring no interruption
of service.

Change-type: minor
Closes: #937
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-04-05 10:06:27 +01:00
Cameron Diver
25fd11bed3
Refactor container logging interface and rename logging-backends
Container logging is now handled by a class which attaches and emits
information from the container. We add these to the directory
logging-backends/, and rename it to logging/.

Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-04-05 10:06:26 +01:00
Cameron Diver
196f173e13
ux: Show a supervisor starting log message in dashboard
Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-04-05 10:06:25 +01:00
Cameron Diver
0504776169
ux: Remove service already running log message
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-04-05 10:06:24 +01:00
Pablo Carranza Velez
9961ebb41d In /v1/update, return 202 when we're not updating immediately
We also add a catch to any errors when getting configuration, and send 503 in this case, even if it's
unlikely.

Change-type: patch
Signed-off-by: Pablo Carranza Velez <pablo@balena.io>
2019-04-03 09:15:50 -07:00
Pablo Carranza Velez
8f07bf62de Add a random jitter to target state polls, and a config var to ignore update notifications and not poll immediately after startup
This commit does two related things:

* We make the poll interval a random time between 0.5 and 1.5 times the configured interval.
* We introduce the BALENA_SUPERVISOR_INSTANT_UPDATE_TRIGGER configuration variable, that defaults to true. If this variable is set
to false, then calls to /v1/update are ignored, and on startup the supervisor waits for a poll interval before getting the target state.

This will help especially on cases where there's a large number of devices on a single network. By disabling instant updates and setting a large
poll interval, we can now achieve a sitation where not all devices apply an update at the same time, which can help avoid
overwhelming the network.

Change-type: minor
Signed-off-by: Pablo Carranza Velez <pablo@balena.io>
2019-04-03 09:15:49 -07:00
Cameron Diver
9a343316b2
Fix service comparison when starting a stopped service
When comparing a stopped container after a start request, the container
ID will be present in the target state (where usually it is not). We
were already filtering this value out of the current state, but
neglected to do so for the target state. This change now ensures we
remove it from both alias lists if it exists.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-04-03 13:08:22 +01:00
Pablo Carranza Velez
c902706600 Fix migration of legacy apps when there's more than one app in the local DB
In an edge case observed in the field, a supervisor's database held two applications
because the device had been moved and the update lock was set in the old app. This causes
the updated supervisor to be unable to start, logging "No compatible releases found in API",
because it can't fetch the release for the app it was moved from.

This commit changes the migration code to iterate through all apps, and remove any for which
we can't get a release.

Change-type: patch
Signed-off-by: Pablo Carranza Velez <pablo@balena.io>
2019-03-28 17:14:06 -07:00
Cameron Diver
175cbfee50
Fix typo in delta request error message
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-03-28 12:31:50 +00:00
Cameron Diver
c4b7fb481a
Remove log-timestamp due to having journald logs
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-03-28 10:27:22 +00:00
Cameron Diver
1570935b2c
misc: Fix lint errors
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-03-28 10:27:22 +00:00
Cameron Diver
b3192679c7
fix: Correctly compare and generate network membership aliases
Before this change, service name resolution would only occur in the
default network. This was because we were not explicitly adding aliases
of the service names to the aliases fields.

We also fix the comparison, which would do funny things based on
container IDs, which was correct but unnecessary.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-03-28 10:27:21 +00:00
CameronDiver
e956242d45
Merge pull request #949 from balena-io/use-default-device-config
When a device config variables requested value is not valid, fallback to the default
2019-03-28 09:43:30 +00:00
Cameron Diver
c7499a6b12
device-config: Show invalid values in dashboard logs
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-03-27 14:03:45 +00:00
Cameron Diver
83d53cfb56
events: Allow system messages to not be tracked
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-03-27 13:14:40 +00:00
Cameron Diver
c211efe399
device-config: Use default values for any invalid target values
If a value is requested which does not pass validation, we instead set
it to the default value, to ensure that the state engine continues to
work and move towards the target state.

Change-type: minor
Closes: #938
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-03-27 13:08:04 +00:00