2016-07-07 20:07:15 +00:00
|
|
|
OS := $(shell uname)
|
|
|
|
|
2016-06-28 18:22:24 +00:00
|
|
|
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
|
|
|
|
|
2016-06-30 17:47:01 +00:00
|
|
|
ifdef no_proxy
|
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
|
|
|
endif
|
|
|
|
|
2016-06-30 17:37:52 +00:00
|
|
|
ifdef use_proxy_at_runtime
|
|
|
|
rt_http_proxy=$(http_proxy)
|
|
|
|
rt_https_proxy=$(https_proxy)
|
2016-06-30 17:47:01 +00:00
|
|
|
rt_no_proxy=$(no_proxy)
|
2016-06-30 17:37:52 +00:00
|
|
|
endif
|
|
|
|
|
2016-07-05 17:48:14 +00:00
|
|
|
DISABLE_CACHE = 'false'
|
2014-07-03 15:29:49 +00:00
|
|
|
|
2016-01-19 02:59:26 +00:00
|
|
|
ARCH = rpi# rpi/amd64/i386/armv7hf/armel
|
2014-07-03 15:29:49 +00:00
|
|
|
|
2015-10-04 18:17:22 +00:00
|
|
|
DEPLOY_REGISTRY =
|
2015-02-11 17:21:10 +00:00
|
|
|
|
2015-06-02 12:47:33 +00:00
|
|
|
SUPERVISOR_VERSION = master
|
2014-07-03 15:29:49 +00:00
|
|
|
|
2015-10-01 11:07:58 +00:00
|
|
|
all: supervisor
|
2014-07-03 15:29:49 +00:00
|
|
|
|
2015-10-14 19:53:33 +00:00
|
|
|
PUBNUB_SUBSCRIBE_KEY = sub-c-bananas
|
|
|
|
PUBNUB_PUBLISH_KEY = pub-c-bananas
|
|
|
|
MIXPANEL_TOKEN = bananasbananas
|
|
|
|
|
2016-05-08 15:59:19 +00:00
|
|
|
PASSWORDLESS_DROPBEAR = false
|
2016-07-07 20:07:15 +00:00
|
|
|
|
2016-06-03 17:21:46 +00:00
|
|
|
IMAGE = "resin/$(ARCH)-supervisor:$(SUPERVISOR_VERSION)"
|
|
|
|
DOCKERFILE = $(ARCH)
|
2016-04-14 13:04:46 +00:00
|
|
|
|
|
|
|
SUPERVISOR_IMAGE=$(DEPLOY_REGISTRY)$(IMAGE)
|
|
|
|
|
2015-07-17 20:47:26 +00:00
|
|
|
ifeq ($(ARCH),rpi)
|
|
|
|
GOARCH = arm
|
2016-01-19 17:14:02 +00:00
|
|
|
GOARM = 6
|
2015-07-17 20:47:26 +00:00
|
|
|
endif
|
|
|
|
ifeq ($(ARCH),armv7hf)
|
|
|
|
GOARCH = arm
|
2016-01-19 17:14:02 +00:00
|
|
|
GOARM = 7
|
2015-07-17 20:47:26 +00:00
|
|
|
endif
|
2016-01-19 02:59:26 +00:00
|
|
|
ifeq ($(ARCH),armel)
|
|
|
|
GOARCH = arm
|
2016-01-19 17:14:02 +00:00
|
|
|
GOARM = 5
|
2016-01-19 02:59:26 +00:00
|
|
|
endif
|
2015-07-17 20:47:26 +00:00
|
|
|
ifeq ($(ARCH),i386)
|
|
|
|
GOARCH = 386
|
|
|
|
endif
|
|
|
|
ifeq ($(ARCH),amd64)
|
|
|
|
GOARCH = amd64
|
|
|
|
endif
|
2016-07-07 20:07:15 +00:00
|
|
|
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
|
2016-07-07 20:07:15 +00:00
|
|
|
endif
|
2015-09-02 19:19:24 +00:00
|
|
|
ifdef PRELOADED_IMAGE
|
|
|
|
SUPERVISOR_DIND_MOUNTS := ${SUPERVISOR_DIND_MOUNTS} -v $$(pwd)/apps.json:/usr/src/app/config/apps.json
|
|
|
|
else
|
|
|
|
PRELOADED_IMAGE=
|
|
|
|
endif
|
2015-07-17 20:47:26 +00:00
|
|
|
|
2016-07-05 17:48:14 +00:00
|
|
|
SUPERVISOR_EXTRA_MOUNTS =
|
|
|
|
|
2016-07-08 02:22:59 +00:00
|
|
|
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}\""; \
|
2016-07-08 02:22:59 +00:00
|
|
|
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}\""; \
|
2016-07-08 02:22:59 +00:00
|
|
|
fi; \
|
|
|
|
if [ -n "${rt_no_proxy}" ]; then \
|
2016-08-23 13:23:18 +00:00
|
|
|
proxies="$${proxies[*]} \"no_proxy=${rt_no_proxy}\""; \
|
2016-07-08 02:22:59 +00:00
|
|
|
fi; \
|
2016-08-23 13:23:18 +00:00
|
|
|
if [ -n "${proxies}" ]; then \
|
2016-07-08 02:22:59 +00:00
|
|
|
echo "[Service]" > ${DOCKERD_PROXY}; \
|
|
|
|
echo "Environment=$${proxies[*]}" >> ${DOCKERD_PROXY}; \
|
|
|
|
else \
|
|
|
|
touch ${DOCKERD_PROXY}; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
supervisor-dind: ${DOCKERD_PROXY}
|
2016-09-06 13:41:17 +00:00
|
|
|
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) .
|
2015-06-02 12:47:33 +00:00
|
|
|
|
2016-07-08 02:22:59 +00:00
|
|
|
run-supervisor: stop-supervisor supervisor-dind
|
2015-06-02 12:47:33 +00:00
|
|
|
cd tools/dind \
|
2016-07-07 20:07:15 +00:00
|
|
|
&& echo "SUPERVISOR_IMAGE=$(SUPERVISOR_IMAGE)" > config/localenv \
|
|
|
|
&& echo "PRELOADED_IMAGE=$(PRELOADED_IMAGE)" >> config/localenv \
|
2016-07-08 02:22:59 +00:00
|
|
|
&& 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 \
|
2015-09-02 19:19:24 +00:00
|
|
|
&& docker run -d --name resin_supervisor_1 --privileged ${SUPERVISOR_DIND_MOUNTS} resin/resin-supervisor-dind:$(SUPERVISOR_VERSION)
|
2015-06-02 12:47:33 +00:00
|
|
|
|
2015-07-16 16:23:14 +00:00
|
|
|
stop-supervisor:
|
2015-07-31 17:17:57 +00:00
|
|
|
# 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
|
2015-08-03 19:06:03 +00:00
|
|
|
-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
|
2015-07-16 16:23:14 +00:00
|
|
|
|
2016-07-06 09:25:48 +00:00
|
|
|
refresh-supervisor-src:
|
2016-07-06 08:47:25 +00:00
|
|
|
echo " * Compiling CoffeeScript.." \
|
|
|
|
&& coffee -c ./src \
|
|
|
|
&& echo " * Restarting supervisor container.." \
|
|
|
|
&& docker exec -ti resin_supervisor_1 docker restart resin_supervisor
|
|
|
|
|
2016-06-03 17:21:46 +00:00
|
|
|
supervisor: nodesuper gosuper
|
|
|
|
sed 's/%%ARCH%%/$(ARCH)/g' Dockerfile.runtime.template > Dockerfile.runtime.$(ARCH)
|
2016-09-23 22:15:00 +00:00
|
|
|
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)
|
2016-06-30 17:37:52 +00:00
|
|
|
ifdef rt_https_proxy
|
2016-09-23 22:15:00 +00:00
|
|
|
echo "ENV HTTPS_PROXY=$(rt_https_proxy) \\" >> Dockerfile.runtime.$(ARCH)
|
|
|
|
echo " https_proxy=$(rt_https_proxy)" >> Dockerfile.runtime.$(ARCH)
|
2016-06-28 18:22:24 +00:00
|
|
|
endif
|
2016-06-30 17:37:52 +00:00
|
|
|
ifdef rt_http_proxy
|
2016-09-23 22:15:00 +00:00
|
|
|
echo "ENV HTTP_PROXY=$(rt_http_proxy) \\" >> Dockerfile.runtime.$(ARCH)
|
|
|
|
echo " http_proxy=$(rt_http_proxy)" >> Dockerfile.runtime.$(ARCH)
|
2016-06-30 17:47:01 +00:00
|
|
|
endif
|
|
|
|
ifdef rt_no_proxy
|
2016-09-23 22:15:00 +00:00
|
|
|
echo "ENV no_proxy=$(rt_no_proxy)" >> Dockerfile.runtime.$(ARCH)
|
2016-06-28 18:22:24 +00:00
|
|
|
endif
|
2016-06-03 17:21:46 +00:00
|
|
|
docker build \
|
|
|
|
$(DOCKER_HTTP_PROXY) \
|
|
|
|
$(DOCKER_HTTPS_PROXY) \
|
|
|
|
$(DOCKER_NO_PROXY) \
|
|
|
|
-f Dockerfile.runtime.$(ARCH) \
|
|
|
|
--pull \
|
|
|
|
-t $(IMAGE) .
|
2014-07-03 15:29:49 +00:00
|
|
|
|
2016-06-03 17:21:46 +00:00
|
|
|
lint:
|
|
|
|
docker run --rm resin/node-supervisor-$(ARCH):$(SUPERVISOR_VERSION) bash -c 'npm install resin-lint && npm run lint'
|
2016-07-19 21:37:46 +00:00
|
|
|
|
2015-02-11 17:21:10 +00:00
|
|
|
deploy: supervisor
|
2015-10-04 18:17:22 +00:00
|
|
|
docker tag -f $(IMAGE) $(SUPERVISOR_IMAGE)
|
|
|
|
bash retry_docker_push.sh $(SUPERVISOR_IMAGE)
|
2015-02-11 17:21:10 +00:00
|
|
|
|
2016-06-03 17:21:46 +00:00
|
|
|
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)
|
2015-07-23 21:14:50 +00:00
|
|
|
|
2016-09-06 13:41:17 +00:00
|
|
|
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
|
2015-07-17 20:47:26 +00:00
|
|
|
|
2016-06-03 17:21:46 +00:00
|
|
|
.PHONY: supervisor deploy supervisor-dind run-supervisor gosuper nodesuper
|