From 53c00e7df8e2de6aaac97e69c0d6aa328f0cbb2a Mon Sep 17 00:00:00 2001 From: Rik Veenboer Date: Fri, 26 Dec 2014 15:05:47 +0100 Subject: [PATCH] Modify setup for more flexible building process --- build/Makefile | 57 ++++++++++++++++++++---- build/boot/{01_hamachi.sh => hamachi.sh} | 0 build/boot/{00_hosts.sh => hosts.sh} | 0 build/make/base.mk | 16 +++---- build/make/compile.mk | 2 + build/make/cron.mk | 4 +- build/make/gmrender.mk | 3 ++ build/make/hosts.mk | 4 +- build/make/logrotate.mk | 2 + build/make/minidlna.mk | 3 ++ build/make/sshd.mk | 4 +- build/make/syslog.mk | 4 +- build/make/upnpproxy.mk | 3 ++ 13 files changed, 76 insertions(+), 26 deletions(-) rename build/boot/{01_hamachi.sh => hamachi.sh} (100%) rename build/boot/{00_hosts.sh => hosts.sh} (100%) create mode 100644 build/make/compile.mk create mode 100644 build/make/gmrender.mk create mode 100644 build/make/logrotate.mk create mode 100644 build/make/minidlna.mk create mode 100644 build/make/upnpproxy.mk diff --git a/build/Makefile b/build/Makefile index e506485..1fbba35 100644 --- a/build/Makefile +++ b/build/Makefile @@ -1,14 +1,54 @@ -include $(wildcard /opt/docker/build/make/*.mk) -BASE = /opt/docker/build +HOME = $(DOCKER_HOME) +BASE = $(HOME)/build +DIR = $(HOME)/images/$(NAME) +FILE = $(DIR)/Dockerfile +FROM = ubuntu:trusty +PORT = 8001 +MODE = minimal +ARGS = --no-cache + +include $(wildcard $(HOME)/build/make/*.mk) + +define download + @echo 'RUN wget -q $(1) $$HOST_ADDR:$$HOST_PORT/$(2) $(3)' >> ${FILE} +endef + +define execute + $(call download,-O -,$(1),| bash) +endef + +define script + $(call execute,scripts/$(1).sh) +endef + +define boot + $(call download,-O /opt/init.d/$(1)_$(2),boot/$(2).sh) +endef + +define runit + @echo 'RUN mkdir -p /etc/service/$(1)' >> ${FILE} + $(call download,-O /etc/service/$(1)/run,runit/$(1)) +endef all: build bin service clean -build: - cp $(BASE)/Dockerfile . - docker build -t $(NAME):$(VERSION) --rm . +build: prepare + $(call script,cleanup) + @echo 'CMD ["/opt/init"]' >> ${FILE} + @$(shell cd ${BASE} && python -m SimpleHTTPServer $(PORT) > /dev/null &) + @docker build -t $(NAME):$(VERSION) --rm=true $(ARGS) ${DIR} + @kill -9 $(lsof -i tcp:8001 -t) -directory: - @mkdir -p build/boot build/runit build/scripts +prepare: + @echo FROM $(FROM) > ${FILE} + @echo ENV MODE $(MODE) >> ${FILE} + @$(eval HOST_ADDR := $(shell ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{print $$1}')) + @echo ENV HOST_ADDR $(HOST_ADDR) >> ${FILE} + @echo ENV HOST_PORT $(PORT) >> ${FILE} + @echo 'RUN apt-get install -y wget' >> ${FILE} + $(call download,-P /build,config,) + $(call download,-P /build,init) + $(call script,prepare) service: @if test "${DEPENDS}" != ""; then \ @@ -23,6 +63,7 @@ service: @mv init.conf /etc/init/docker-$(NAME).conf bin: + @rm -r bin @mkdir -p bin @ln -sf $(BASE)/bin/run bin @ln -sf $(BASE)/bin/ssh bin @@ -31,7 +72,7 @@ bin: @sed -i "1iARGS=\"$(SSH)\"" bin/ssh clean: - @rm -f Dockerfile + @rm -f ${FILE} @rm -rf build @rm -rf id_rsa diff --git a/build/boot/01_hamachi.sh b/build/boot/hamachi.sh similarity index 100% rename from build/boot/01_hamachi.sh rename to build/boot/hamachi.sh diff --git a/build/boot/00_hosts.sh b/build/boot/hosts.sh similarity index 100% rename from build/boot/00_hosts.sh rename to build/boot/hosts.sh diff --git a/build/make/base.mk b/build/make/base.mk index 607880d..d48d16c 100644 --- a/build/make/base.mk +++ b/build/make/base.mk @@ -1,10 +1,6 @@ -base: directory cron syslog sshd hosts - ln -f $(BASE)/config build - ln -f $(BASE)/init build - ln -f $(BASE)/scripts/*_prepare.sh build/scripts - ln -f $(BASE)/scripts/*_boot.sh build/scripts - ln -f $(BASE)/scripts/*_init.sh build/scripts - ln -f $(BASE)/scripts/*_runit.sh build/scripts - ln -f $(BASE)/scripts/*_logrotate.sh build/scripts - ln -f $(BASE)/scripts/*_utilities.sh build/scripts - ln -f $(BASE)/scripts/*_cleanup.sh build/scripts \ No newline at end of file +base: cron syslog sshd hosts +# $(call script,boot) +# $(call script,init) +# $(call script,runit) +# $(call script,logrotate) +# $(call script,utilities) \ No newline at end of file diff --git a/build/make/compile.mk b/build/make/compile.mk new file mode 100644 index 0000000..3a92e2a --- /dev/null +++ b/build/make/compile.mk @@ -0,0 +1,2 @@ +compile: + ln -f $(BASE)/scripts/*_$@.sh build/scripts \ No newline at end of file diff --git a/build/make/cron.mk b/build/make/cron.mk index 66c367b..cd81234 100644 --- a/build/make/cron.mk +++ b/build/make/cron.mk @@ -1,3 +1,3 @@ cron: - ln -f $(BASE)/scripts/*_$@.sh build/scripts - ln -f $(BASE)/runit/$@ build/runit \ No newline at end of file + $(call script,$@) + $(call runit,$@) \ No newline at end of file diff --git a/build/make/gmrender.mk b/build/make/gmrender.mk new file mode 100644 index 0000000..3f4a335 --- /dev/null +++ b/build/make/gmrender.mk @@ -0,0 +1,3 @@ +gmrender: compile + cp $(BASE)/scripts/*_$@.sh build/scripts + cp $(BASE)/runit/$@ build/runit \ No newline at end of file diff --git a/build/make/hosts.mk b/build/make/hosts.mk index 7d1ac1c..2d5f2c1 100644 --- a/build/make/hosts.mk +++ b/build/make/hosts.mk @@ -1,3 +1,3 @@ hosts: - ln -f $(BASE)/scripts/*_$@.sh build/scripts - ln -f $(BASE)/boot/*_$@.sh build/boot \ No newline at end of file + $(call script,$@) + $(call boot,01,$@) \ No newline at end of file diff --git a/build/make/logrotate.mk b/build/make/logrotate.mk new file mode 100644 index 0000000..5643790 --- /dev/null +++ b/build/make/logrotate.mk @@ -0,0 +1,2 @@ +logrotate: + ln -f $(BASE)/scripts/*_$@.sh build/scripts \ No newline at end of file diff --git a/build/make/minidlna.mk b/build/make/minidlna.mk new file mode 100644 index 0000000..d10365b --- /dev/null +++ b/build/make/minidlna.mk @@ -0,0 +1,3 @@ +minidlna: compile + ln -f $(BASE)/scripts/*_$@.sh build/scripts + ln -f $(BASE)/runit/$@ build/runit \ No newline at end of file diff --git a/build/make/sshd.mk b/build/make/sshd.mk index 3478c37..4c137e3 100644 --- a/build/make/sshd.mk +++ b/build/make/sshd.mk @@ -1,3 +1,3 @@ sshd: - ln -f $(BASE)/scripts/*_$@.sh build/scripts - ln -f $(BASE)/runit/$@ build/runit \ No newline at end of file + $(call script,$@) + $(call runit,$@) \ No newline at end of file diff --git a/build/make/syslog.mk b/build/make/syslog.mk index 9d52c48..782585a 100644 --- a/build/make/syslog.mk +++ b/build/make/syslog.mk @@ -1,3 +1,3 @@ syslog: - ln -f $(BASE)/scripts/*_$@.sh build/scripts - ln -f $(BASE)/runit/$@ build/runit \ No newline at end of file + $(call script,$@) + $(call runit,$@) \ No newline at end of file diff --git a/build/make/upnpproxy.mk b/build/make/upnpproxy.mk new file mode 100644 index 0000000..7d59382 --- /dev/null +++ b/build/make/upnpproxy.mk @@ -0,0 +1,3 @@ +upnpproxy: compile + cp $(BASE)/scripts/*_$@.sh build/scripts + cp $(BASE)/runit/$@ build/runit \ No newline at end of file