2018-10-18 18:54:19 +00:00
# balena-supervisor Makefile
2017-07-07 21:48:47 +00:00
#
# If you're looking for an easy way to develop on the supervisor, check ./tools/dev/dindctl, which provides a simplified interface
# to this makefile.
#
# Build targets (require Docker 17.05 or greater):
2018-10-18 18:54:19 +00:00
# * supervisor (default) - builds a balena-supervisor image
# * deploy - pushes a balena-supervisor image to the registry, retrying up to 3 times
2017-12-14 03:55:26 +00:00
# * nodedeps, nodebuild - builds the node component, with the node_modules and src at /usr/src/app and /build (also includes a rootfs-overlay there)
2017-07-10 16:37:36 +00:00
# * supervisor-dind: build the development docker-in-docker supervisor that run-supervisor uses (requires a SUPERVISOR_IMAGE to be available locally)
2017-07-07 21:48:47 +00:00
#
# Variables for build targets:
# * ARCH: amd64/rpi/i386/armv7hf/armel/aarch64 architecture for which to build the supervisor - default: amd64
2018-10-18 18:54:19 +00:00
# * IMAGE: image to build or deploy - default: balena/$(ARCH)-supervisor:latest
2018-07-18 00:39:57 +00:00
# * MIXPANEL_TOKEN: (optional) default mixpanel key to embed in the supervisor image
2017-07-07 21:48:47 +00:00
# * DISABLE_CACHE: if set to true, run build with no cache - default: false
# * DOCKER_BUILD_OPTIONS: Additional options for docker build, like --cache-from parameters
#
# Test/development targets:
2018-10-18 18:54:19 +00:00
# * run-supervisor, stop-supervisor - build and start or stop a docker-in-docker balena-supervisor (requires aufs, ability to run privileged containers, and a SUPERVISOR_IMAGE to be available locally)
2017-07-07 21:48:47 +00:00
#
# Variables for test/dev targets:
# * IMAGE: image to build and run (either for run-supervisor or test-gosuper/integration)
2017-07-10 16:37:36 +00:00
# * SUPERVISOR_IMAGE: In run-supervisor and supervisor-dind, the supervisor image to run inside the docker-in-docker image
2017-07-07 21:48:47 +00:00
# * PRELOADED_IMAGE: If true, will preload user app image from tools/dev/apps.json and bind mount apps.json into the docker-in-docker supervisor
2018-02-09 19:30:15 +00:00
# * MOUNT_DIST: If true, mount the dist folder into the docker-in-docker supervisor
# * MOUNT_NODE_MODULES: If true, mount the node_modules folder into the docker-in-docker supervisor
2019-11-12 11:47:07 +00:00
# * CONTAINER_NAME: For run-supervisor, specify the container name for the docker-in-docker container (default: supervisor which produces container balena-container-supervisor)
2017-10-10 17:21:21 +00:00
# * CONFIG_FILENAME: For run-supervisor, specify the filename to mount as config.json, relative to tools/dind/ (default: config.json)
2019-11-12 11:47:07 +00:00
# * DIND_IMAGE: For run-supervisor, specify the balenaOS image to use (default: resin/resinos:2.12.5_rev1-intel-nuc)
2017-07-07 21:48:47 +00:00
#
2018-02-09 19:30:15 +00:00
# Based on https://stackoverflow.com/a/8540718/2549019
# Retrieves a repo part of the given docker image string
# Param:
# 1. String to parse in form 'repo[:tag]'.
repo = $( firstword $( subst :, ,$1 ) )
# Returns a tag (if any) on a docker image string.
# If there is no tag part in the string, returns latest
# Param:
# 1. String to parse in form 'repo[:tag]'.
tag = $( or $( word 2,$( subst :, ,$1 ) ) ,latest)
2017-07-07 21:48:47 +00:00
THIS_FILE := $( lastword $( MAKEFILE_LIST) )
help :
@cat $( THIS_FILE) | awk '{if(/^#/)print;else exit}' | sed 's/\#//'
2016-07-07 20:07:15 +00:00
OS := $( shell uname)
2017-07-07 21:48:47 +00:00
# If we're behind a proxy, use it during build
2016-06-28 18:22:24 +00:00
i f d e f h t t p _ p r o x y
DOCKER_HTTP_PROXY = --build-arg http_proxy = $( http_proxy)
e n d i f
i f d e f h t t p s _ p r o x y
DOCKER_HTTPS_PROXY = --build-arg https_proxy = $( https_proxy)
e n d i f
2016-06-30 17:47:01 +00:00
i f d e f n o _ p r o x y
2016-07-08 01:37:29 +00:00
DOCKER_NO_PROXY = --build-arg no_proxy = $( no_proxy)
2016-06-30 17:47:01 +00:00
e n d i f
2017-07-07 21:48:47 +00:00
DISABLE_CACHE ?= 'false'
2014-07-03 15:29:49 +00:00
2016-10-16 08:34:24 +00:00
DOCKER_VERSION := $( shell docker version --format '{{.Server.Version}}' )
DOCKER_MAJOR_VERSION := $( word 1, $( subst ., ,$( DOCKER_VERSION) ) )
DOCKER_MINOR_VERSION := $( word 2, $( subst ., ,$( DOCKER_VERSION) ) )
2017-07-07 21:48:47 +00:00
DOCKER_GE_17_05 := $( shell [ $( DOCKER_MAJOR_VERSION) -gt 17 -o \( $( DOCKER_MAJOR_VERSION) -eq 17 -a $( DOCKER_MINOR_VERSION) -ge 5 \) ] && echo true )
2015-10-14 19:53:33 +00:00
2018-07-18 00:39:57 +00:00
# Default values for Mixpanel key
2017-07-07 21:48:47 +00:00
MIXPANEL_TOKEN ?= bananasbananas
2016-07-07 20:07:15 +00:00
2017-07-07 21:48:47 +00:00
# Default architecture and output image
ARCH ?= amd64
2018-10-18 18:54:19 +00:00
IMAGE ?= balena/$( ARCH) -supervisor:master
2016-04-14 13:04:46 +00:00
2017-07-07 21:48:47 +00:00
# Default values for run-supervisor
2018-10-18 18:54:19 +00:00
SUPERVISOR_IMAGE ?= balena/$( ARCH) -supervisor:master
2018-02-09 19:30:15 +00:00
CONTAINER_NAME ?= supervisor
2017-10-10 17:21:21 +00:00
CONFIG_FILENAME ?= config.json
2018-02-09 19:30:15 +00:00
DIND_IMAGE ?= resin/resinos:2.12.5_rev1-intel-nuc
2016-04-14 13:04:46 +00:00
2017-07-07 21:48:47 +00:00
# Bind mounts and variables for the run-supervisor target
2018-02-09 19:30:15 +00:00
SUPERVISOR_DIND_MOUNTS := -v $$ ( pwd ) /config/supervisor-image.tar:/usr/src/supervisor-image.tar:ro -v $$ ( pwd ) /start-resin-supervisor:/usr/bin/start-resin-supervisor:ro -v $$ ( pwd ) /config/supervisor.conf:/etc/resin-supervisor/supervisor.conf
2017-07-07 21:48:47 +00:00
i f e q ( $( PRELOADED_IMAGE ) , t r u e )
2018-02-09 19:30:15 +00:00
SUPERVISOR_DIND_MOUNTS := ${ SUPERVISOR_DIND_MOUNTS } -v $$ ( pwd ) /apps.json:/mnt/data/apps.json
2015-09-02 19:19:24 +00:00
e l s e
PRELOADED_IMAGE =
e n d i f
2018-02-09 19:30:15 +00:00
i f e q ( $( MOUNT_DIST ) , t r u e )
SUPERVISOR_DIND_MOUNTS := ${ SUPERVISOR_DIND_MOUNTS } -v $$ ( pwd ) /../../dist:/resin-supervisor/dist
e n d i f
i f e q ( $( MOUNT_NODE_MODULES ) , t r u e )
SUPERVISOR_DIND_MOUNTS := ${ SUPERVISOR_DIND_MOUNTS } -v $$ ( pwd ) /../../node_modules:/resin-supervisor/node_modules
e n d i f
2015-07-17 20:47:26 +00:00
2018-12-07 17:54:16 +00:00
i f e q ( $( MOUNT_BACKUP ) , t r u e )
SUPERVISOR_DIND_MOUNTS := ${ SUPERVISOR_DIND_MOUNTS } -v $$ ( pwd ) /backup.tgz:/mnt/data/backup.tgz.mounted
e n d i f
2017-07-07 21:48:47 +00:00
i f d e f T A R G E T _ C O M P O N E N T
DOCKER_TARGET_COMPONENT := " --target= ${ TARGET_COMPONENT } "
e l s e
DOCKER_TARGET_COMPONENT :=
e n d i f
# Default target is to build the supervisor image
all : supervisor
2016-07-05 17:48:14 +00:00
2017-07-10 16:37:36 +00:00
supervisor-tar :
2018-02-09 19:30:15 +00:00
cd tools/dind \
&& mkdir -p config \
&& docker save --output config/supervisor-image.tar $( SUPERVISOR_IMAGE)
2017-07-10 16:37:36 +00:00
2018-02-09 19:30:15 +00:00
supervisor-conf :
2016-09-06 13:41:17 +00:00
cd tools/dind \
2018-02-09 19:30:15 +00:00
&& mkdir -p config \
&& echo " SUPERVISOR_IMAGE= $( call repo,$( SUPERVISOR_IMAGE) ) " > config/supervisor.conf \
&& echo " SUPERVISOR_TAG= $( call tag,$( SUPERVISOR_IMAGE) ) " >> config/supervisor.conf \
&& echo "LED_FILE=/dev/null" >> config/supervisor.conf
supervisor-dind : supervisor -tar supervisor -conf
run-supervisor : supervisor -dind
2015-06-02 12:47:33 +00:00
cd tools/dind \
2019-11-12 11:47:07 +00:00
&& ./balenaos-in-container/balenaos-in-container.sh \
2018-02-09 19:30:15 +00:00
--detach \
2019-11-12 11:34:40 +00:00
--config " $( CONFIG_FILENAME) " \
2018-02-09 19:30:15 +00:00
--image $( DIND_IMAGE) \
--id $( CONTAINER_NAME) \
--extra-args " ${ SUPERVISOR_DIND_MOUNTS } "
2015-06-02 12:47:33 +00:00
2015-07-16 16:23:14 +00:00
stop-supervisor :
2019-11-12 11:47:07 +00:00
-docker stop balena-container-$( CONTAINER_NAME) > /dev/null || true
-docker rm -f --volumes balena-container-$( CONTAINER_NAME) > /dev/null || true
2015-07-16 16:23:14 +00:00
2017-07-07 21:48:47 +00:00
supervisor-image :
i f n e q ( $( DOCKER_GE_ 17_ 05) , t r u e )
@echo "Docker >= 17.05 is needed to build the supervisor"
@exit 1
2016-06-28 18:22:24 +00:00
e n d i f
2016-06-03 17:21:46 +00:00
docker build \
$( DOCKER_HTTP_PROXY) \
$( DOCKER_HTTPS_PROXY) \
$( DOCKER_NO_PROXY) \
2017-07-07 21:48:47 +00:00
$( DOCKER_TARGET_COMPONENT) \
$( DOCKER_BUILD_OPTIONS) \
--no-cache= $( DISABLE_CACHE) \
--build-arg ARCH = $( ARCH) \
--build-arg VERSION = $( shell jq -r .version package.json) \
--build-arg DEFAULT_MIXPANEL_TOKEN = $( MIXPANEL_TOKEN) \
2019-07-19 17:19:59 +00:00
` if [ -n " $$ DEBUG " ] ; then echo '-f Dockerfile.debug' ; fi ` \
2016-06-03 17:21:46 +00:00
-t $( IMAGE) .
2014-07-03 15:29:49 +00:00
2017-07-07 21:48:47 +00:00
supervisor :
@$( MAKE) -f $( THIS_FILE) IMAGE = $( IMAGE) ARCH = $( ARCH) supervisor-image
2016-07-19 21:37:46 +00:00
2017-07-07 21:48:47 +00:00
deploy :
@bash retry_docker_push.sh $( IMAGE)
2017-12-14 03:55:26 +00:00
nodedeps :
$( MAKE) -f $( THIS_FILE) TARGET_COMPONENT = node-deps IMAGE = $( IMAGE) ARCH = $( ARCH) supervisor-image
nodebuild :
$( MAKE) -f $( THIS_FILE) TARGET_COMPONENT = node-build IMAGE = $( IMAGE) ARCH = $( ARCH) supervisor-image
2016-06-03 17:21:46 +00:00
2018-03-16 14:01:50 +00:00
.PHONY : supervisor deploy nodedeps nodebuild supervisor -dind run -supervisor