balena-supervisor/Makefile

217 lines
6.8 KiB
Makefile
Raw Normal View History

OS := $(shell uname)
ifdef http_proxy
DOCKER_HTTP_PROXY=--build-arg http_proxy=$(http_proxy)
endif
ifdef https_proxy
DOCKER_HTTPS_PROXY=--build-arg https_proxy=$(https_proxy)
endif
ifdef no_proxy
DOCKER_NO_PROXY=--build-arg no_proxy=$(no_proxy)
endif
ifdef use_proxy_at_runtime
rt_http_proxy=$(http_proxy)
rt_https_proxy=$(https_proxy)
rt_no_proxy=$(no_proxy)
endif
DISABLE_CACHE = 'false'
2016-01-19 02:59:26 +00:00
ARCH = rpi# rpi/amd64/i386/armv7hf/armel
DEPLOY_REGISTRY =
SUPERVISOR_VERSION = master
all: supervisor
PUBNUB_SUBSCRIBE_KEY = sub-c-bananas
PUBNUB_PUBLISH_KEY = pub-c-bananas
MIXPANEL_TOKEN = bananasbananas
PASSWORDLESS_DROPBEAR = false
IMAGE = "resin/$(ARCH)-supervisor:$(SUPERVISOR_VERSION)"
DOCKERFILE = $(ARCH)
2016-04-14 13:04:46 +00:00
SUPERVISOR_IMAGE=$(DEPLOY_REGISTRY)$(IMAGE)
ifeq ($(ARCH),rpi)
GOARCH = arm
GOARM = 6
endif
ifeq ($(ARCH),armv7hf)
GOARCH = arm
GOARM = 7
endif
2016-01-19 02:59:26 +00:00
ifeq ($(ARCH),armel)
GOARCH = arm
GOARM = 5
2016-01-19 02:59:26 +00:00
endif
ifeq ($(ARCH),i386)
GOARCH = 386
endif
ifeq ($(ARCH),amd64)
GOARCH = amd64
endif
SUPERVISOR_DIND_MOUNTS := -v $$(pwd)/../../:/resin-supervisor -v $$(pwd)/config.json:/mnt/conf/config.json -v $$(pwd)/config/env:/usr/src/app/config/env -v $$(pwd)/config/localenv:/usr/src/app/config/localenv
ifeq ($(OS), Linux)
2016-09-10 10:20:28 +00:00
SUPERVISOR_DIND_MOUNTS := ${SUPERVISOR_DIND_MOUNTS} -v /sys/fs/cgroup:/sys/fs/cgroup:ro -v /bin/kmod:/bin/kmod
endif
ifdef PRELOADED_IMAGE
SUPERVISOR_DIND_MOUNTS := ${SUPERVISOR_DIND_MOUNTS} -v $$(pwd)/apps.json:/usr/src/app/config/apps.json
else
PRELOADED_IMAGE=
endif
SUPERVISOR_EXTRA_MOUNTS =
DOCKERD_PROXY=tools/dind/config/services/docker.service.d/proxy.conf
${DOCKERD_PROXY}:
rm -f ${DOCKERD_PROXY}
if [ -n "${rt_http_proxy}" ]; then \
2016-08-23 13:23:18 +00:00
proxies="\"HTTP_PROXY=${rt_http_proxy}\""; \
proxies="$${proxies[*]} \"http_proxy=${rt_http_proxy}\""; \
fi; \
if [ -n "${rt_https_proxy}" ]; then \
2016-08-23 13:23:18 +00:00
proxies="$${proxies[*]} \"HTTPS_PROXY=${rt_https_proxy}\""; \
proxies="$${proxies[*]} \"https_proxy=${rt_https_proxy}\""; \
fi; \
if [ -n "${rt_no_proxy}" ]; then \
2016-08-23 13:23:18 +00:00
proxies="$${proxies[*]} \"no_proxy=${rt_no_proxy}\""; \
fi; \
2016-08-23 13:23:18 +00:00
if [ -n "${proxies}" ]; then \
echo "[Service]" > ${DOCKERD_PROXY}; \
echo "Environment=$${proxies[*]}" >> ${DOCKERD_PROXY}; \
else \
touch ${DOCKERD_PROXY}; \
fi
supervisor-dind: ${DOCKERD_PROXY}
cd tools/dind \
&& docker build \
$(DOCKER_HTTP_PROXY) \
$(DOCKER_HTTPS_PROXY) \
$(DOCKER_NO_PROXY) \
--no-cache=$(DISABLE_CACHE) \
--build-arg PASSWORDLESS_DROPBEAR=$(PASSWORDLESS_DROPBEAR) \
-t resin/resin-supervisor-dind:$(SUPERVISOR_VERSION) .
run-supervisor: stop-supervisor supervisor-dind
cd tools/dind \
&& echo "SUPERVISOR_IMAGE=$(SUPERVISOR_IMAGE)" > config/localenv \
&& echo "PRELOADED_IMAGE=$(PRELOADED_IMAGE)" >> config/localenv \
&& echo "SUPERVISOR_EXTRA_MOUNTS=$(SUPERVISOR_EXTRA_MOUNTS)" >> config/localenv; \
if [ -n "$(rt_http_proxy)" ]; then \
echo "HTTP_PROXY=$(rt_http_proxy)" >> config/localenv \
&& echo "http_proxy=$(rt_http_proxy)" >> config/localenv; \
fi; \
if [ -n "$(rt_https_proxy)" ]; then \
echo "HTTPS_PROXY=$(rt_https_proxy)" >> config/localenv \
&& echo "https_proxy=$(rt_https_proxy)" >> config/localenv; \
fi; \
if [ -n "$(rt_no_proxy)" ]; then \
echo "no_proxy=$(rt_no_proxy)" >> config/localenv; \
fi \
&& docker run -d --name resin_supervisor_1 --privileged ${SUPERVISOR_DIND_MOUNTS} resin/resin-supervisor-dind:$(SUPERVISOR_VERSION)
stop-supervisor:
# Stop docker and remove volumes to prevent us from running out of loopback devices,
2015-07-16 20:12:09 +00:00
# as per https://github.com/jpetazzo/dind/issues/19
-docker exec resin_supervisor_1 bash -c "systemctl stop docker" || true
-docker stop resin_supervisor_1 > /dev/null || true
-docker rm -f --volumes resin_supervisor_1 > /dev/null || true
refresh-supervisor-src:
echo " * Compiling CoffeeScript.." \
&& coffee -c ./src \
&& echo " * Restarting supervisor container.." \
&& docker exec -ti resin_supervisor_1 docker restart resin_supervisor
supervisor: nodesuper gosuper
sed 's/%%ARCH%%/$(ARCH)/g' Dockerfile.runtime.template > Dockerfile.runtime.$(ARCH)
echo "ENV VERSION=$(shell jq -r .version package.json) \\" >> Dockerfile.runtime.$(ARCH)
echo " DEFAULT_PUBNUB_PUBLISH_KEY=$(PUBNUB_PUBLISH_KEY) \\" >> Dockerfile.runtime.$(ARCH)
echo " DEFAULT_PUBNUB_SUBSCRIBE_KEY=$(PUBNUB_SUBSCRIBE_KEY) \\" >> Dockerfile.runtime.$(ARCH)
echo " DEFAULT_MIXPANEL_TOKEN=$(MIXPANEL_TOKEN)" >> Dockerfile.runtime.$(ARCH)
ifdef rt_https_proxy
echo "ENV HTTPS_PROXY=$(rt_https_proxy) \\" >> Dockerfile.runtime.$(ARCH)
echo " https_proxy=$(rt_https_proxy)" >> Dockerfile.runtime.$(ARCH)
endif
ifdef rt_http_proxy
echo "ENV HTTP_PROXY=$(rt_http_proxy) \\" >> Dockerfile.runtime.$(ARCH)
echo " http_proxy=$(rt_http_proxy)" >> Dockerfile.runtime.$(ARCH)
endif
ifdef rt_no_proxy
echo "ENV no_proxy=$(rt_no_proxy)" >> Dockerfile.runtime.$(ARCH)
endif
docker build \
$(DOCKER_HTTP_PROXY) \
$(DOCKER_HTTPS_PROXY) \
$(DOCKER_NO_PROXY) \
-f Dockerfile.runtime.$(ARCH) \
--pull \
-t $(IMAGE) .
lint:
docker run --rm resin/node-supervisor-$(ARCH):$(SUPERVISOR_VERSION) bash -c 'npm install resin-lint && npm run lint'
deploy: supervisor
docker tag -f $(IMAGE) $(SUPERVISOR_IMAGE)
bash retry_docker_push.sh $(SUPERVISOR_IMAGE)
nodesuper:
sed 's/%%ARCH%%/$(ARCH)/g' Dockerfile.build.template > Dockerfile.build.$(ARCH)
docker build \
$(DOCKER_HTTP_PROXY) \
$(DOCKER_HTTPS_PROXY) \
$(DOCKER_NO_PROXY) \
-f Dockerfile.build.$(ARCH) \
-t resin/node-supervisor-$(ARCH):$(SUPERVISOR_VERSION) .
docker run --rm \
-v `pwd`/build/$(ARCH):/build \
resin/node-supervisor-$(ARCH):$(SUPERVISOR_VERSION)
gosuper:
cd gosuper && docker build \
$(DOCKER_HTTP_PROXY) \
$(DOCKER_HTTPS_PROXY) \
$(DOCKER_NO_PROXY) \
--build-arg GOARCH=$(GOARCH) \
--build-arg GOARM=$(GOARM) \
-t resin/go-supervisor-$(ARCH):$(SUPERVISOR_VERSION) .
docker run --rm \
-v `pwd`/build/$(ARCH):/build \
resin/go-supervisor-$(ARCH):$(SUPERVISOR_VERSION)
test-gosuper: gosuper
docker run \
--rm \
-v /var/run/dbus:/mnt/root/run/dbus \
-e DBUS_SYSTEM_BUS_ADDRESS="unix:path=/mnt/root/run/dbus/system_bus_socket" \
resin/go-supervisor-$(ARCH):$(SUPERVISOR_VERSION) bash -c \
'./test_formatting.sh && go test -v ./gosuper'
format-gosuper: gosuper
docker run \
--rm \
-v $(shell pwd)/gosuper:/go/src/resin-supervisor/gosuper \
resin/go-supervisor-$(ARCH):$(SUPERVISOR_VERSION) \
go fmt ./...
test-integration: gosuper
docker run \
--rm \
--net=host \
-e SUPERVISOR_IP="$(shell docker inspect --format '{{ .NetworkSettings.IPAddress }}' resin_supervisor_1)" \
--volumes-from resin_supervisor_1 \
-v /var/run/dbus:/mnt/root/run/dbus \
-e DBUS_SYSTEM_BUS_ADDRESS="unix:path=/mnt/root/run/dbus/system_bus_socket" \
resin/go-supervisor-$(ARCH):$(SUPERVISOR_VERSION) \
go test -v ./supertest
.PHONY: supervisor deploy supervisor-dind run-supervisor gosuper nodesuper