Commit Graph

433 Commits

Author SHA1 Message Date
Miguel Casqueira
204475d3dc Improved mutable (/data) file system detection
Change-type: patch
Closes: #1609
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2021-04-08 17:34:27 -04:00
Christina Wang
31effed426 Prevent unintended image removal when calling purge endpoints to remove volumes
Using safeStateClone within doPurge to applyIntermediateTarget after
successful volume purge has led to various type deficiencies being revealed
in common.js. Add several inline types in common.js to satisfy
the type checker (credit: Page <page@balena.io>). Delete common.d.ts
since it's not required and might mistakenly mask true I/O types of
functions in common.js.

Closes: #1611
Change-type: patch
Signed-off-by: Christina Wang <christina@balena.io>
2021-04-05 12:10:09 +00:00
Miguel Casqueira
ecbe9ee9f9 Patch list volumes to always return an array
Change-type: patch
Closes: #1636
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2021-04-01 20:31:09 -04:00
Matthew McGinn
f9a157c9ec typos: seperate -> separate
mainly to get the docs one, but figured i could hit them all

Change-type: patch
Signed-off-by: Matthew McGinn <matthew@balena.io>
2021-03-17 14:27:53 -04:00
Miguel Casqueira
183ea88a2a Infer legacy Volumes that do not have the supervised label
Change-type: patch
Closes: #1604
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2021-03-15 19:46:53 -04:00
Christina Wang
8948bde02a
Merge branch 'master' into v1-healthcheck-stub-fix 2021-02-19 11:07:33 +09:00
Miguel Casqueira
ec23d1d371 Refactor checkTruthy to return more predictable values
Change-type: patch
Closes: #1595
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2021-02-18 12:36:42 -05:00
Christina Wang
2953f313e6
Call restore for each healthcheck stub in v1 tests
Signed-off-by: Christina Wang <christina@balena.io>
Change-type: patch
2021-02-18 20:22:41 +09:00
Christina Wang
4e206e9c1a
Complete POST /v1/purge unit tests
Connects-to: #1327
Signed-off-by: Christina Wang <christina@balena.io>
2021-02-18 12:25:44 +09:00
Christina Wang
b3b1d47b34
Complete /v1/device/host-config unit tests, modify PATCH route
Change-type: minor
Signed-off-by: Christina Wang <christina@balena.io>
2021-02-18 12:25:44 +09:00
Christina Wang
f748c1a8e7
Add POST /v1/regenerate-api-key unit tests
Signed-off-by: Christina Wang <christina@balena.io>
2021-02-18 12:25:44 +09:00
Christina Wang
6e5c553c3f
Write POST /v1/blink unit test
Signed-off-by: Christina Wang <christina@balena.io>
2021-02-18 12:25:43 +09:00
Robert Günzler
f009d3a3e9
Fix gpu label support
The device request object was created with untouched fields left unset. When
comparing state to determine if a transition is required this would
result in a mismatch between:

    {
      Driver: '',
      Count: 1,
      DeviceIDs: null,
      Capabilities: [Array],
      Options: null
    }

and

    {
      Count: 1,
      Capabilities: [Array],
    }

Which in turn resulted in the target service being continously restarted.
The fix is to instantiate the object in full.

Connects-to: https://github.com/balena-io/balena-supervisor/issues/1449
Connects-to: ae646a07ec
Change-type: patch
Signed-off-by: Robert Günzler <robertg@balena.io>
2021-02-09 11:27:03 +01:00
Miguel Casqueira
ba1c857c4f Cancel pending apply target after /v1/update request
Closes: #1530
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2021-01-20 22:21:14 -05:00
Felipe Lalanne
4aa8090a56 Add support for BALENA_HOST_SPLASH_IMAGE config
Setting this this variable to a base64 encoded string will replace the splash
image on the device by rewriting `/mnt/boot/splash/balena-logo.png`.
This will also make a copy of the default balena logo so the splash can
be restored if the variable is removed.

Change-type: minor
Signed-off-by: Felipe Lalanne <felipe@balena.io>
2021-01-06 15:11:31 -03:00
Felipe Lalanne
e66a775c15 Move required configuration check to Backend
The `ensureRequiredOverlay` function is currently ran for any backend,
at this moment this causes no issue, since most configuration backends
are defined per single device type. However, with the option to modify splash
images, which is available for all device types, the function would add
unwanted configuration vars to the splash image configuration. Moving it
to the config txt backend solves this issue.
2021-01-05 18:30:07 -03:00
Felipe Lalanne
4cdf26f82f Improve supervisor API behavior when locks are set
This PR adds the following

* Supervisor v1 API application actions now return HTTP status code 423 when locks
  are preventing the action to be performed. Previously this resulted in a
  503 error
* Supervisor API v2 service actions now returns HTTP status code 423 when locks are
  preventing the action to be performed. Previously, this resulted in an
  exception logged by the supervisor and the API query timing out
* Supervisor API `/v2/applications/:appId/start-service` now does not
  check for a lock. Lock handling in v2 actions is now performed by each
  step executor
* `/v1/apps/:appId/start` now queries the target state and uses that
  information to execute the start step (as v2 does). Previously start
  resulted in `cannot get appId from undefined`
* Extra tests for API methods

Change-type: patch
Connects-to: #1523
Signed-off-by: Felipe Lalanne <felipe@balena.io>
2020-12-14 10:43:41 -03:00
Miguel Casqueira
8b37df492b Patched /v1/restart exception
Change-type: patch
Closes: #1509
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-11-30 15:42:49 -05:00
Miguel Casqueira
7a4473f65b Added test case for /v1/restart API
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-11-30 15:42:49 -05:00
Miguel Casqueira
733a2c5dc0 Consolidated Supervisor API tests into clearer files
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-11-30 15:42:49 -05:00
Rich Bayliss
02aeb4fc1c fix: Scoped keys breaking livepush with existing cloud images on the device
Closes: #1512
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-11-16 12:55:40 -05:00
Felipe Lalanne
e4e895630f Ensure the first target state request is applied
During first time run of the supervisor, the target state is queried
by `reportInitialEnv`. Since this happens early on the initialization
process, this target state report is missed by any listeners and this
can lead to the initial target state not beeing applied (see #1455).

This PR ensures that target state is re-emitted if there were no
listeners setup on call to update.

Change-type: patch
Signed-off-by: Felipe Lalanne <felipe@balena.io>
Connects-to: #1455
2020-11-13 10:19:27 -03:00
Rich Bayliss
591598e102
fix: Scoped keys not working in LocalMode
Some endpoints filter data based on the scope of the API key
used to make the request. When in LocalMode the check was not
being made correctly and all apps were considered out of scope.

Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-11-11 10:58:58 +00:00
Cameron Diver
f08316dc57 Allow storing commits against their appIds
This paves the way for running multiple applications and storing
information related to the application against the application itself. A
couple of hacks have been added to v1 and v2 endpoints to maintain
compatability but these should eventually be removed with the addition
of a v3 api.

Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-11-10 10:50:08 +00:00
Miguel Casqueira
cd0d53c39d Add more test coverage for compose/images
Closes: #1492
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-11-03 13:08:41 -05:00
Felipe Lalanne
01477e41b8 Mount docker socket under /host/run for services
Currently, when the label `io.balena.features.balena-socket` is set,
the balena engine socket is mounted under `/run/balena-engine.sock`.

This causes a problem when using systemd inside the container, since
this service remounts `/run` and `/run/lock` as tmpfs, causing the
socket to become unavailable.

Making a mount of the socket into `/host/run` solves this issue. This is
the same approach taken with DBUS.

Change-type: patch
Signed-off-by: Felipe Lalanne <felipe@balena.io>
Connects-to: #1494
2020-10-29 15:54:31 -03:00
Cameron Diver
9d19a45701 Use root mount point to find device-type.json
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-10-28 13:03:40 +00:00
Felipe Lalanne
f5183df356 Change source of deviceType to device-type.json
The source of truth for the device-type should be
device-type.json instead of config.json

Change-type: patch
Signed-off-by: Felipe Lalanne <felipe@balena.io>
Connects-to: #1472
2020-10-27 09:40:18 -03:00
Miguel Casqueira
77333f1e11 Fixed evaluating if updates are needed to reach target state
Closes: #1476
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-10-26 14:54:04 -04:00
Felipe Lalanne
dd5f62227a Improve calculation for used system memory
The memory information reported by the supervisor currently
estimates the value of used memory as `MemTotal - MemFree`.
However, linux systems will try to cache and buffer as much
memory as possible, which will affect the output of `MemFree`
(from /proc/meminfo) and in consequence the memory usage seen
by the user on the dashboard, which will appear much greater than
it is.

The correct calculation should be `MemTotal - MemFree - Buffers - Cached`,
which the calculation performed by `htop` and the `free` commands.

Change-type: patch
Signed-off-by: Felipe Lalanne <felipe@balena.io>
Connects-to: #1471
2020-10-14 13:15:17 -03:00
Cameron Diver
a2ceb5c931 Refactor system information filtering
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-10-12 15:44:07 +01:00
Cameron Diver
9e0c99e797 tests: Clean up and consistify naming scheme
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-10-12 14:41:21 +01:00
Cameron Diver
975129188a Remove superfluous current state reporting code from api-binder
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-10-12 11:53:19 +01:00
Matthew McGinn
8e65466f2d version: drop SUPERVISOR_VERSION env var
In order to make supervisor upgrades more transparent, lets move away
from this env var since it requires a container restart any time the supervisor
is upgraded. We should ultimately move towards providing the supervisors
set of capabilities, but that can come later

Connects-to: #1447
Change-type: major
Signed-off-by: Matthew McGinn <matthew@balena.io>
2020-09-29 11:22:30 -04:00
Felipe Lalanne
a5f3002e70 Fix config checks for ConfigFS backend
When trying to apply SSDT overlays in Up Board, the supervisor currently
gets stuck in a loop trying to apply target state. See #1465

This was due to a bug in parsing the configuration, which lead to
the method bootConfigChangeRequired returning true when no change was
needed.

Change-type: patch
Signed-off-by: Felipe Lalanne <felipe@balena.io>
Connects-to: #1465
2020-09-24 16:45:57 -03:00
Rich Bayliss
c08de8701e api: Implement scoped Supervisor API keys
Each service, when requesting access to the Supervisor API, will
now get an individual key which can be scoped to specific resources.
In this iteration the default scope will be to the application that
the service belongs to.

We also have a `global` scope which is used by the cloud API when in
managed mode.

Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-09-17 11:25:56 +00:00
Miguel Casqueira
07e644d0b6 Refactor extra_uEnv backend to match with more devices
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-09-15 14:19:59 -04:00
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
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
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
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
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
Miguel Casqueira
0999f57fa8 fix duplicate test file index
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-07-30 14:07:00 -04: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
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
6ef3bd2362
docker-utils: Test network gateway determination logic
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-07-22 13:17:16 +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
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
Miguel Casqueira
7a27b6c671 Refactor device-config tests styling
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
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
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
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
Miguel Casqueira
ffe814e447 Refactored @ts-ignore to @ts-expect-error in test file
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-06-08 13:24:19 -04: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
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
Miguel Casqueira
9fc2e86322 Convert all test files to TS and add .spec to all filenames
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-06-05 18:34:24 -04: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
Miguel Casqueira
f494178b2b Added test coverage for GET /v1/healthy
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-05-29 16:14:15 -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
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
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
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
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
f6aa4dd015 Fixed stubs for test suite
Closes: #1280
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-05-11 18:16:22 -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
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
Miguel Casqueira
698435a5c8 Added spec for current auth implementation
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-05-04 10:49:09 -04: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
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
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
d3221ca235 Convert test/18-startup.coffee to typescript
Change-type: patch
2020-04-02 14:25:26 +01:00
Pagan Gazzard
70b0705551 Convert test/19-compose-utils.coffee to javascript
Change-type: patch
2020-04-02 14:25:25 +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
d3cf650ac4 Convert test/17-config-utils.spec.coffee to javascript
Change-type: patch
2020-04-02 14:25:23 +01:00
Pagan Gazzard
dcb01cb863 Convert test/16-ports.spec.coffee to typescript
Change-type: patch
2020-04-02 14:25:21 +01:00
Pagan Gazzard
515fb059f4 Convert test/15-conversions.spec.coffee to javascript
Change-type: patch
2020-03-31 16:38:07 +01:00
Pagan Gazzard
fd4cec31e7 Convert test/12-logger.spec.coffee to javascript
Change-type: patch
2020-03-31 16:25:57 +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
Pagan Gazzard
7e6d32516d Tests: Add missing await
Change-type: patch
2020-03-23 19:02:17 +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
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
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
Ivan
f5c51be07d Add unit test to ensure journalctl process is spawned with expected
arguments.

Signed-off-by: Ivan <ivan@mish.guru>
2020-02-22 16:44:11 -07: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
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
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
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
Roman Mazur
f487711ba4
Add regression test for app manager init
If we had it eearlier, it would have prevented #1148.
When init is called, withImagesFromDockerAndDB in images.ts is called as well.

Change-type: patch
Signed-off-by: Roman Mazur <roman@balena.io>
2019-11-27 13:51:15 +02: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
Theodor Gherzan
d6adfa189f
Do not polute test output with unncessarry stack trace
Signed-off-by: Theodor Gherzan <theodor@balena.io>
2019-11-19 09:48:56 +00: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
54e9c2edd8
Run new prettier on code base
Signed-off-by: Theodor Gherzan <theodor@balena.io>
2019-11-15 14:51:24 +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
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
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
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
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
487e2c54a1 Add test number to test files name
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-10-01 16:17:42 +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
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
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
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
050c10dbb0 Add volume tests and fix test fixture setup for applications
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-07-10 14:25:46 +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
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
286ba58069
Add tests for Volume
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
Roman Mazur
aad1129f26
Fix tests run removing .only
The issue was introduced with one of the recent changes related to local mode cleanup.

Change-type: patch
Signed-off-by: Roman Mazur <roman@balena.io>
2019-06-27 14:56:54 +03: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
Roman Mazur
3f5239b07f
Remove mochainon dependnecy
Change-type: patch
Signed-off-by: Roman Mazur <roman@balena.io>
2019-06-19 23:31:58 +03: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
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
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
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
9e05bc2b71
misc: Fix spurious test errors
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-04-25 13:48:27 +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
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
Pablo Carranza Velez
3d0e35f2a2 Fix test for deviceConfig.getDefaults with the addition of SUPERVISOR_INSTANT_UPDATE_TRIGGER
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
Pablo Carranza Velez
ea6ebf8223 test: Add a test case for deviceConfig.getDefaults
This would help avoid bugs like the one fixed in 9.11.1.

Change-type: patch
Signed-off-by: Pablo Carranza Velez <pablo@balena.io>
2019-03-28 16:01:00 -07: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
Cameron Diver
84356b82b8
state-engine: Return a noop when waiting for a dependency
We run the risk of the state engine exiting early when a dependency is
not ready, especially in local mode. This changes forces a noop to be
returned when we are waiting on another service, which is the process
used elsewhere in the state engine.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-03-13 10:34:15 +00:00
Cameron Diver
911ee7f009
Run iptables rules synchronous to avoid locking errors
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-02-19 17:43:04 +00:00
Cameron Diver
5f82f6fd3f
Apply iptables rules to ipv6
Change-type: patch
Closes: #867
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-02-13 20:57:05 +00:00
Cameron Diver
49dbaaba12
Allow newlines to be part of environment variables
We were not allowing newlines previously by virtue of the regex not
allowing them. The docker daemon and supervisor handling code both
support them, so we allow them in the parsing code too.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-02-12 11:19:55 +00:00
Cameron Diver
6bf008cc85
Remove environment variable whitespace trimming
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-02-11 17:13:35 +00:00
Cameron Diver
88f19b4147
Set default delta apply timeout of 0
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-02-11 10:21:04 +00:00
Cameron Diver
f3264862ca
fix: Normalize ports from compose file on instantiation
Adjacent ports are always grouped together by docker when reporting the
container state (from an inspect), so adjacent ports defined in the
compose file would not match as they would not have been normalized.

We make sure to always normalize the input port configuration, so that
it will match the docker output (if it should).

We also don't sort in the fromComposePorts function anymore as that is
handled by the normalize function.

Closes: #897
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-02-08 15:14:07 +00:00
Cameron Diver
2e09ed071c
Ensure the balena-fin always has it's overlay assigned
Change-type: patch
Closes: #884
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-02-05 16:19:42 +00:00
Cameron Diver
db74e748a1
refactor: Fully type and validate config module set and get
We define the type for each config value, and validate the data when
retrieving and setting it.

Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-01-11 10:37:25 +00:00
Cameron Diver
01ed7bb103
refactor: Convert ApiBinder module to typescript
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-01-08 11:59:56 +00:00
Cameron Diver
3a130f4f9c
refactor: Change config modules export type to new-style
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-01-02 18:12:22 +00:00
Cameron Diver
dc34025545
refactor: Generate and normalise PortMaps from compose ports in-class
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-01-02 12:19:30 +00:00
Cameron Diver
e82749e63a
tests: Add test case for ascending ports issue
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-01-02 11:31:25 +00:00
Cameron Diver
b32fba43e1
refactor: Convert DeviceConfig module to typescript
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2018-12-21 17:18:35 +00:00
Cameron Diver
de5157c04c
refactor: Change export style of db to named
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2018-12-21 17:18:33 +00:00
Cameron Diver
96b614ad6a
Replace offline -> unmanaged in logs and tests
Signed-off-by: Cameron Diver <cameron@balena.io>
2018-12-17 10:53:24 +00:00
Cameron Diver
82602abf8d
config: Replace supervisorOfflineMode and offlineMode with unmanaged
Change-type: major
Signed-off-by: Cameron Diver <cameron@balena.io>
2018-12-14 15:01:41 +00:00
Cameron Diver
19f8b75766
Revert "localMode: Remove local mode from device-config"
This reverts commit eda477ff86.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2018-12-14 11:05:57 +00:00
Cameron Diver
64a8c03eba
unmanged: Don't require a device name when setting a target state
Also set a default device name of 'local', to avoid an undefined value.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2018-11-29 11:35:08 +00:00
Cameron Diver
eda477ff86
localMode: Remove local mode from device-config
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2018-11-29 11:35:07 +00:00
Cameron Diver
5c04df2cb8
compose: Fix network option field names and update dockerode types
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2018-11-28 17:43:31 +00:00
Cameron Diver
b37ce5e3d9
config: Set default apiKey of empty string to avoid undefined keys
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2018-11-28 14:53:09 +00:00
Cameron Diver
f48e85095b
events: Correctly proxy mixpanel events
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2018-11-21 13:09:06 +00:00
Cameron Diver
0ff52751d8
tests: Increase timeout for test suites
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2018-11-06 15:27:58 +00:00
Cameron Diver
e270652122
Remove ts-node from test process
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2018-11-06 12:05:35 +00:00
Pagan Gazzard
d6e9283a15 Fix coffee-script lint failures 2018-11-02 14:50:12 +00:00
Pablo Carranza Velez
8298487a88 Rename most of the documentation and variable names from resin to balena
Change-type: minor
Signed-off-by: Pablo Carranza Velez <pablo@balena.io>
2018-11-01 17:00:13 -07:00
Akis Kesoglou
b71c59c002 api-binder: Use API v5
Change-type: major
2018-11-01 13:17:30 +02:00
Pablo Carranza Velez
1e47d0c434 test: Use longer delays in logger tests
We've seen at least one case where the 10ms delay
wasn't enough, causing the tests to fail where they shouldn't.

(Ideally we should find a better way to detect when the streams
have finished propagating, but this will avoid failures in the meantime).

Change-type: patch
Signed-off-by: Pablo Carranza Velez <pablo@balena.io>
2018-10-25 16:48:06 -07:00
Pablo Carranza Velez
b3860b2b70 fix: Store and retrieve device config without namespaces
This avoids issues on provisioning where the current state
(esp. config.txt) that we want to save is retrieved without
a RESIN_ or BALENA_ prefix, causing those values to be lost.

Change-type: patch
Signed-off-by: Pablo Carranza Velez <pablo@balena.io>
2018-10-20 04:40:55 +02:00
Pablo Carranza Velez
24cbfbb860 deviceConfig: allow BALENA_ config variables
They will take precedence over any existing RESIN_ variables. We strip both namespaces now
whenever we get the target values.

This also fixes preloading with a legacy config (the interface to get the config keys from
the legacy apps.json was broken).

Change-type: minor
Signed-off-by: Pablo Carranza Velez <pablo@balena.io>
2018-10-18 17:20:53 +02:00
Pablo Carranza Velez
220f4b5810 service: Fix device name env vars by injecting and filtering in the interface with docker
Change-Type: patch
Signed-off-by: Pablo Carranza Velez <pablo@balena.io>
2018-10-18 14:49:00 +02:00
Pablo Carranza Velez
ed3f5522ae Replace io.resin labels (and their env vars) with io.balena equivalents
But we keep backwards compatibility by normalizing existing io.resin labels
into io.balena ones, and adding both RESIN_ and BALENA_ env vars for these features.

Change-Type: minor
Signed-off-by: Pablo Carranza Velez <pablo@balena.io>
2018-10-18 13:21:31 +02:00
Pablo Carranza Velez
8003f25c3d Add /tmp/balena lock and handover paths and BALENA_ env vars
We change the lockfile to /tmp/balena/updates.lock, and the resin-kill-me file to /tmp/balena/handover-complete.
In the host, we change to use /tmp/balena-supervisor instead of /tmp/resin-supervisor.

We add BALENA_ env vars in addition to the RESIN_ env vars.

We keep backwards compatibility by using both paths for the lockfile and handover, and keeping the RESIN_ env vars.

Changelog-entry: Move the handover and lock files to /tmp/balena, rename them, and add BALENA_ env vars
Change-type: minor
Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
2018-10-16 15:12:04 +02:00
Cameron Diver
6e2801380b
Support local logging via standard logging interface
Change-type: patch
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-10-10 13:02:40 +01:00
Cameron Diver
5537ae4e2e
fix: Correctly handle array based network definitions for service
Change-type: patch
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-10-08 11:29:32 +01:00
Cameron Diver
06bbf9751a
compose: Support changing the tty option for compose services
This enables the switch to be added to the compose, and the handling of
docker messages has been changed to ensure that the multiplexed logs
which result are handled properly.

Change-type: minor
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-09-24 12:04:51 +01:00
Cameron Diver
892d227cc2
compose/service: Convert module to typescript and add network config
Stability improvements;
* Printing of unsupported compose fields
* Added a lot of tests
* All compose configuration has a default value, enabling better
comparison

Change-type: minor
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-09-21 10:30:27 +01:00
Cameron Diver
e0231f15e9
Compose: Support more network creation options
Change-type: minor
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-09-21 10:30:27 +01:00
Cameron Diver
08b1c90ea1
fix: Fix event-tracker being passed no options object
Change-type: patch
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-09-04 16:02:06 -07:00
Cameron Diver
c1748436d8
fix: Import logger properly and add startup test
Change-type: patch
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-09-04 15:53:49 -07:00
Cameron Diver
8ca42062a3
events: Report supervisor version with any mixpanel events
Change-type: patch
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-09-04 13:17:20 -07:00
Cameron Diver
607c722b0b
events: Add rate limiting based on event name when reporting to mixpanel
Change-type: patch
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-09-04 13:17:17 -07:00
Cameron Diver
67b5503ac4
Fix: Change import of ports module to be extensionless in tests
Change-type: patch
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-09-03 09:39:06 -07:00
Cameron Diver
d3a18da573
Refactor: Convert logging module to typescript
Change-type: patch
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-09-03 09:39:06 -07:00
Cameron Diver
8ee26adbbe
Refactor: Convert event tracker module to typescript
Change-type: patch
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-09-03 09:36:21 -07:00
Cameron Diver
f7958e6c6b
Dont restart service on device name change
Change-type: patch
Closes: #659
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-07-25 10:45:05 +01:00
Petros Angelatos
202362241c
logger: Add unit tests
Change-type: minor
Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
2018-07-18 12:31:14 -07:00
Petros Angelatos
bba1da370b
logger: Remove pubnub leftovers
Change-type: minor
Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
2018-07-18 12:31:10 -07:00
Cameron Diver
1604fdf276
Allow the enabling and disabling of persistent logging via env var
Closes: #698
Change-type: minor
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-07-17 19:43:54 +01:00
Cameron Diver
0e29e5f6f7
Refactor config code to be consistent in location
Change-type: patch
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-07-16 17:48:03 +01:00
Cameron Diver
5e5ff05b4f
Re-enable majority of tests
Change-type: patch
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-07-16 16:43:50 +01:00
Cameron Diver
39d8ac0133
Change config function providers to be mutable
Also change logsChannelSecret value to be queried with the api backend,
so that logs are not shared between instances. This has been implemented
as the first config function provider with mutability.

Change-type: minor
Closes: #675
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-06-26 14:02:25 +01:00
Cameron Diver
4027d286d1
Add tests for new port module
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-06-25 09:46:07 +01:00
Cameron Diver
7b77e45f69
Store port ranges as ranges, to reduce memory usage
Before this change, port ranges were iterated and stored as an object
per port mapping. Now the port ranges are stored as ranges until they
need to be converted to objects. The need to convert to objects still
exists as this is the format which the docker remote API expects, but
hopefully this should alleviate bugs like #644 by making the memory more
shorter-lived.

Also added more tests.

Change-type: patch
Closes: #644
Signed-of-by: Cameron Diver <cameron@resin.io>
2018-06-25 09:46:01 +01:00
Cameron Diver
809bc87b88
Convert config module to typescript
Extract config.json handling code out to separate modules too.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-06-18 13:41:18 +01:00
Cameron Diver
089f31cb5d
Pin a device to a commit when preload has a pinDevice field
Change-type: minor
Closes: #668
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-06-11 20:27:16 +01:00
Cameron Diver
5622ddce94
Convert iptables module to typescript
Change-type: patch
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-06-11 10:20:17 +01:00
Cameron Diver
1e48d02781
Move config backend code out to classes which implement a common base
Change-type: patch
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-06-06 14:50:21 +01:00
Cameron Diver
89627a3392
Add support for extlinux configuration files
Currently the only supported variable is RESIN_HOST_EXTLINUX_isolcpus

Change-type: minor
Closes: #671
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-06-05 17:00:45 +01:00
Cameron Diver
dc59c83409
Move boot config related code to config-utils module
This commit abstracts all of the boot config code out of the
device-config module, ready to extend with different config backends.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-06-05 17:00:45 +01:00
Akis Kesoglou
8479801674 Add support for Balena deltas
Resin’s delta server supports Balena deltas as version 3 deltas. This commit adds support for triggering delta generation for Balena deltas, and applying them locally to the device via a simple pull.

The delta version to use when updating has been abstracted away as an env var that is user-defined. The default value is still instructing use of rsync deltas (v2).

Change-Type: minor
2018-05-23 20:59:56 +03:00
Cameron Diver
bc37ee56e4
Check against application source for target applications
The supervisor will now check that a source of an application matches
the current source, and only start it if so.

Change-type: patch
Closes: #658
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-05-22 12:11:57 +01:00
Cameron Diver
bea0b00804
Ignore leading and trailing whitespace when parsing env vars
Change-type: patch
Closes: #644
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-05-22 11:32:31 +01:00
Cameron Diver
ea8e8d2f5f
Don't generate config fields in offline mode
Change-type: patch
Closes: #648
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-05-21 14:45:32 +01:00
Cameron Diver
96d7bbefd0
Fix handling of systemd errors when polling for log to display
Change-type: patch
Closes: #610
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-05-08 15:12:13 +01:00
Cameron Diver
9150c3fdbc
Convert conversions module to typescript
Change-type: patch
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-05-02 09:36:21 +01:00
Pablo Carranza Velez
652b596c80 Add some more unit tests to the multicontainer supervisor
We add a bunch of additional unit tests, and also a coverage report using istanbul.

The tests are not meant to cover everything, but they're a first attempt at having *some* unit testing
on the supervisor. There's much to improve but hopefully it helps catch obvious errors.

Change-Type: patch
Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
2018-04-30 19:39:01 -07:00
Cameron Diver
ddbf3418de
Remove trailing slashes from working directories of services
This is to combat when a working directory is in the compose file for a
service with a trailing slash. Docker will strip this slash and that
means service comparisons will fail going forward - even if they are the
same.

Change-type: patch
Closes: #635
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-04-27 18:03:36 +01:00
Cameron Diver
5b8f1ce334
Add tests for validation code
Change-type: minor
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-04-27 16:09:50 +01:00
Pablo Carranza Velez
1ce9560427 Add additional tests to compose Service, and add linting to tests
Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
2018-04-11 15:15:30 -07:00
Cameron Diver
1c27ebc354
Fix parsing of non-unit memory numbers and add tests
Signed-off-by: Cameron Diver <cameron@resin.io>
2018-04-04 14:03:24 +01:00
Lucian Buzzo
9bca2557ea Add mocha to enable unit testing
Implements a simple test for `parseMemoryNumber`

change-type: minor
2018-04-04 13:22:17 +01:00