Commit Graph

1089 Commits

Author SHA1 Message Date
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