Balena Supervisor: balena's agent on devices.
Go to file
2015-10-13 13:45:04 -03:00
automation Integration test is now working. 2015-10-13 13:43:36 -03:00
bin enter.sh: Split env vars by NULL byte instead of whitespace 2015-10-13 13:43:36 -03:00
config/supervisor Reorganize files, and purge sends 404 when there's no directory. 2015-10-13 13:43:36 -03:00
gosuper Purge handles strings and numbers, and is tested with a table 2015-10-13 13:45:03 -03:00
src Download/update/remove/install all apps in a map 2015-10-13 13:45:03 -03:00
tools/dind Update resin-base for supervisor-dind to include ifupdown for the vpn. 2015-10-13 13:45:03 -03:00
.dockerignore Handle App not found in purge, + cleanup 2015-10-13 13:43:36 -03:00
.editorconfig add editor config 2015-10-13 13:39:37 -03:00
.gitattributes Add a .gitattributes file to make sure files for use on linux have linux style line-endings. 2015-10-13 13:03:14 -03:00
.gitignore gosuper for other GOARCH should never get to the supervisor image 2015-10-13 13:43:37 -03:00
01_nodoc Save space by using a dpkg config to avoid installing unnecessary docs/locales. 2015-10-13 13:36:13 -03:00
CHANGELOG.md Changelog for update locking 2015-10-13 13:45:04 -03:00
coffeelint.json add coffeelint 2015-10-13 13:39:37 -03:00
Dockerfile.amd64 gosuper for other GOARCH should never get to the supervisor image 2015-10-13 13:43:37 -03:00
Dockerfile.armv7hf gosuper for other GOARCH should never get to the supervisor image 2015-10-13 13:43:37 -03:00
Dockerfile.i386 gosuper for other GOARCH should never get to the supervisor image 2015-10-13 13:43:37 -03:00
Dockerfile.rpi gosuper for other GOARCH should never get to the supervisor image 2015-10-13 13:43:37 -03:00
entry.sh Reorganize files, and purge sends 404 when there's no directory. 2015-10-13 13:43:36 -03:00
Makefile gosuper for other GOARCH should never get to the supervisor image 2015-10-13 13:43:37 -03:00
package.json First attempt at locking updates with files 2015-10-13 13:45:03 -03:00
postinstall.sh Save space by removing more npm install artifacts. 2015-10-13 13:36:13 -03:00
README.md Handle App not found in purge, + cleanup 2015-10-13 13:43:36 -03:00

Running supervisor in the dev env

Deploy your local version to the devenv registry

If you haven't done so yet, login to the devenv registry:

docker login registry.resindev.io

Use username "resin" and the registry's default login details if you haven't changed them.

make ARCH=amd64 deploy

This will build the image if you haven't done it yet. A different registry can be specified with the DEPLOY_REGISTRY env var.

Set up config

Edit tools/dind/config.json to contain the values for a staging config.json.

This file can be obtained in several ways, for instance:

  • Download an Intel Edison image from staging, open config.img with an archive tool like peazip
  • Download a Raspberry Pi 2 image, flash it to an SD card, then mount partition 5 (resin-conf).

Tip: to avoid git marking config.json as modified, you can run:

git update-index --assume-unchanged tools/dind/config.json

Start the supervisor instance

make ARCH=amd64 run-supervisor

This will setup a docker-in-docker instance with an image that runs the supervisor image.

By default it will pull from the devenv registry (registry.resindev.io).

A different registry can be specified with the DEPLOY_REGISTRY env var.

e.g.

make ARCH=amd64 DEPLOY_REGISTRY= run-supervisor

to pull the jenkins built images from the docker hub.

View the containers logs

logs supervisor -f

View the supervisor logs

enter supervisor
tail /var/log/supervisor-log/resin_supervisor_stdout.log -f

Stop the supervisor

make stop-supervisor

This will stop the container and remove it, also removing its volumes.

Working with the Go supervisor

The Dockerfile used to build the Go supervisor is Dockerfile.gosuper, and the code for the Go supervisor lives in the gosuper directory.

To build it, run:

make ARCH=amd64 gosuper

This will build and run the docker image that builds the Go supervisor and outputs the executable at gosuper/bin.

Adding Go dependencies

This project uses Godep to manage its Go dependencies. In order for it to work, this repo needs to be withing the src directory in a valid Go workspace. This can easily be achieved in the devenv by having the repo in the devenv's src directory and setting the GOPATH environment variable to such directory's parent (that is, the resin-containers directory).

If these conditions are met, a new dependency can be added with:

go get github.com/path/to/dependency

Then we add the corresponding import statement in our code (e.g. main.go):

import "github.com/path/to/dependency"

And we save it to Godeps.json with:

cd gosuper
godep save -r ./...

(The -r switch will modify the import statement to use Godep's _workspace)

Testing

Gosuper

The Go supervisor can be tested by running:

make ARCH=amd64 test-gosuper

The test suite is at gosuper/main_test.go.

Integration test

The integration test tests the supervisor API by hitting its endpoints. To run it, first run the supervisor as explained in the first section of this document.

Once it's running, you can run the test with:

make ARCH=amd64 test-integration

The tests will fail if the supervisor API is down - bear in mind that the supervisor image takes a while to start the actual supervisor program, so you might have to wait a few minutes between running the supervisor and testing it. The test expects the supervisor to be already running the application (so that the app is already on the SQLite database), so check the dashboard to see if the app has already downloaded.