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
|
2016-04-14 13:04:46 +00:00
|
|
|
BASE_DISTRO =
|
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
|
2015-07-28 21:10:17 +00:00
|
|
|
JOB_NAME = 1
|
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-04-14 13:04:46 +00:00
|
|
|
ifdef BASE_DISTRO
|
|
|
|
$(info BASE_DISTRO SPECIFIED. START BUILDING ALPINE SUPERVISOR)
|
|
|
|
IMAGE = "resin/$(ARCH)-supervisor:$(SUPERVISOR_VERSION)-alpine"
|
|
|
|
DOCKERFILE = alpine.$(ARCH)
|
|
|
|
else
|
|
|
|
$(info BASE_DISTRO NOT SPECIFIED. START BUILDING DEBIAN SUPERVISOR)
|
|
|
|
IMAGE = "resin/$(ARCH)-supervisor:$(SUPERVISOR_VERSION)"
|
|
|
|
DOCKERFILE = $(ARCH)
|
|
|
|
endif
|
|
|
|
|
|
|
|
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)
|
|
|
|
SUPERVISOR_DIND_MOUNTS := ${SUPERVISOR_DIND_MOUNTS} -v /sys/fs/cgroup:/sys/fs/cgroup:ro
|
|
|
|
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 =
|
|
|
|
|
2014-10-17 11:23:20 +00:00
|
|
|
clean:
|
2015-02-17 00:52:45 +00:00
|
|
|
-rm Dockerfile
|
2014-10-07 17:41:49 +00:00
|
|
|
|
2015-06-02 12:47:33 +00:00
|
|
|
supervisor-dind:
|
2016-07-08 01:37:29 +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
|
|
|
|
2015-07-16 20:12:09 +00:00
|
|
|
run-supervisor: supervisor-dind stop-supervisor
|
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 \
|
|
|
|
&& echo "SUPERVISOR_EXTRA_MOUNTS=$(SUPERVISOR_EXTRA_MOUNTS)" >> config/localenv \
|
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
|
|
|
|
|
2015-07-23 17:00:37 +00:00
|
|
|
supervisor: gosuper
|
2016-04-14 13:04:46 +00:00
|
|
|
cp Dockerfile.$(DOCKERFILE) Dockerfile
|
2014-10-17 12:21:47 +00:00
|
|
|
echo "ENV VERSION "`jq -r .version package.json` >> Dockerfile
|
2015-10-14 21:50:26 +00:00
|
|
|
echo "ENV DEFAULT_PUBNUB_PUBLISH_KEY $(PUBNUB_PUBLISH_KEY)" >> Dockerfile
|
|
|
|
echo "ENV DEFAULT_PUBNUB_SUBSCRIBE_KEY $(PUBNUB_SUBSCRIBE_KEY)" >> Dockerfile
|
|
|
|
echo "ENV DEFAULT_MIXPANEL_TOKEN $(MIXPANEL_TOKEN)" >> Dockerfile
|
2016-06-30 17:37:52 +00:00
|
|
|
ifdef rt_https_proxy
|
|
|
|
echo "ENV HTTPS_PROXY $(rt_https_proxy)" >> Dockerfile
|
|
|
|
echo "ENV https_proxy $(rt_https_proxy)" >> Dockerfile
|
2016-06-28 18:22:24 +00:00
|
|
|
endif
|
2016-06-30 17:37:52 +00:00
|
|
|
ifdef rt_http_proxy
|
|
|
|
echo "ENV HTTP_PROXY $(rt_http_proxy)" >> Dockerfile
|
|
|
|
echo "ENV http_proxy $(rt_http_proxy)" >> Dockerfile
|
2016-06-30 17:47:01 +00:00
|
|
|
endif
|
|
|
|
ifdef rt_no_proxy
|
|
|
|
echo "ENV no_proxy $(rt_no_proxy)" >> Dockerfile
|
2016-06-28 18:22:24 +00:00
|
|
|
endif
|
2016-07-08 01:37:29 +00:00
|
|
|
docker build $(DOCKER_HTTP_PROXY) $(DOCKER_HTTPS_PROXY) $(DOCKER_NO_PROXY) --no-cache=$(DISABLE_CACHE) -t $(IMAGE) .
|
2015-02-20 16:08:18 +00:00
|
|
|
-rm Dockerfile
|
2014-07-03 15:29:49 +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
|
|
|
|
2015-07-17 20:47:26 +00:00
|
|
|
go-builder:
|
2015-07-31 17:17:57 +00:00
|
|
|
-cp tools/dind/config.json ./gosuper/
|
2016-07-08 01:37:29 +00:00
|
|
|
cd gosuper && docker build $(DOCKER_HTTP_PROXY) $(DOCKER_HTTPS_PROXY) $(DOCKER_NO_PROXY) -t resin/go-supervisor-builder:$(SUPERVISOR_VERSION) .
|
2015-07-31 17:17:57 +00:00
|
|
|
-rm ./gosuper/config.json
|
2015-07-17 20:47:26 +00:00
|
|
|
|
|
|
|
gosuper: go-builder
|
2015-08-11 16:02:44 +00:00
|
|
|
-mkdir -p bin
|
2015-08-03 19:06:03 +00:00
|
|
|
-docker rm --volumes -f resin_build_gosuper_$(JOB_NAME) || true
|
2016-06-28 18:42:52 +00:00
|
|
|
docker run --rm --name resin_build_gosuper_$(JOB_NAME) -v $(shell pwd)/gosuper/bin:/usr/src/app/bin -e USER_ID=$(shell id -u) -e GROUP_ID=$(shell id -g) -e GOARCH=$(GOARCH) -e GOARM=$(GOARM) resin/go-supervisor-builder:$(SUPERVISOR_VERSION)
|
2015-08-11 16:02:44 +00:00
|
|
|
mv gosuper/bin/linux_$(GOARCH)/gosuper bin/gosuper
|
2015-07-23 21:14:50 +00:00
|
|
|
|
|
|
|
test-gosuper: go-builder
|
2015-08-03 19:06:03 +00:00
|
|
|
-docker rm --volumes -f resin_test_gosuper_$(JOB_NAME) || true
|
2016-06-28 18:42:52 +00:00
|
|
|
docker run --rm --name resin_test_gosuper_$(JOB_NAME) -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-builder:$(SUPERVISOR_VERSION) bash -c "cd src/resin-supervisor/gosuper && ./test_formatting.sh && go test -v ./gosuper"
|
2015-07-31 17:17:57 +00:00
|
|
|
|
|
|
|
format-gosuper: go-builder
|
2015-08-03 19:06:03 +00:00
|
|
|
-docker rm --volumes -f resin_test_gosuper_$(JOB_NAME) || true
|
2016-06-28 18:42:52 +00:00
|
|
|
docker run --rm --name resin_test_gosuper_$(JOB_NAME) -v $(shell pwd)/gosuper:/usr/src/app/src/resin-supervisor/gosuper resin/go-supervisor-builder:$(SUPERVISOR_VERSION) bash -c "cd src/resin-supervisor/gosuper && go fmt ./..."
|
2015-07-28 21:10:17 +00:00
|
|
|
|
|
|
|
test-integration: go-builder
|
2015-08-03 19:06:03 +00:00
|
|
|
-docker rm --volumes -f resin_test_integration_$(JOB_NAME) || true
|
2016-06-28 18:42:52 +00:00
|
|
|
docker run --rm --name resin_test_integration_$(JOB_NAME) --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-builder:$(SUPERVISOR_VERSION) bash -c "cd src/resin-supervisor/gosuper && go test -v ./supertest"
|
2015-07-17 20:47:26 +00:00
|
|
|
|
2015-06-02 12:47:33 +00:00
|
|
|
.PHONY: supervisor deploy supervisor-dind run-supervisor
|