Split scripts by ## (and remove comments / whitespace) to facilitate caching, add option for multicore to make
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
/build/Dockerfile
|
/build/Dockerfile
|
||||||
/build/tmp.*
|
/build/tmp.*
|
||||||
|
/build/parts/*
|
||||||
@@ -3,6 +3,7 @@ FROM = debian:jessie
|
|||||||
MODE = minimal
|
MODE = minimal
|
||||||
ARGS = --rm=false --no-cache=false
|
ARGS = --rm=false --no-cache=false
|
||||||
PROXY = $(shell ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | cut -d' ' -f1)
|
PROXY = $(shell ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | cut -d' ' -f1)
|
||||||
|
JOBS = 2
|
||||||
include $(wildcard $(DOCKER_HOME)/build/make/*.mk)
|
include $(wildcard $(DOCKER_HOME)/build/make/*.mk)
|
||||||
|
|
||||||
define add
|
define add
|
||||||
@@ -28,7 +29,7 @@ define runit
|
|||||||
endef
|
endef
|
||||||
|
|
||||||
define script
|
define script
|
||||||
$(call execute,scripts/$(1).sh,$(TMP)/$(1).sh)
|
@python3 $(DOCKER_HOME)/build/parts.py $(1) $(FILE) $(TMP)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
all: build bin service clean
|
all: build bin service clean
|
||||||
@@ -40,19 +41,26 @@ build: prepare base
|
|||||||
ifneq ($(PROXY),)
|
ifneq ($(PROXY),)
|
||||||
@$(eval ARGS += --build-arg HTTP_PROXY=http://$(PROXY):3142)
|
@$(eval ARGS += --build-arg HTTP_PROXY=http://$(PROXY):3142)
|
||||||
endif
|
endif
|
||||||
@docker build -t $(NAME):$(VERSION) $(ARGS) -f $(FILE) $(DOCKER_HOME)/build
|
ifneq ($(JOBS),)
|
||||||
|
@$(eval ARGS += --build-arg JOBS="-j $(JOBS)")
|
||||||
|
endif
|
||||||
|
docker build -t $(NAME):$(VERSION) $(ARGS) -f $(FILE) $(DOCKER_HOME)/build
|
||||||
@rm ${FILE}
|
@rm ${FILE}
|
||||||
|
|
||||||
prepare:
|
prepare:
|
||||||
@$(eval FILE = $(shell mktemp -p $(DOCKER_HOME)/build))
|
@$(eval FILE = $(shell mktemp -p $(DOCKER_HOME)/build))
|
||||||
|
@rm $(DOCKER_HOME)/build/tmp.*
|
||||||
@echo FROM $(FROM) > ${FILE}
|
@echo FROM $(FROM) > ${FILE}
|
||||||
|
@echo 'ARG JOBS="-j $(JOBS)"' >> ${FILE}
|
||||||
@echo ENV MODE $(MODE) >> ${FILE}
|
@echo ENV MODE $(MODE) >> ${FILE}
|
||||||
$(call add,config,/build/config)
|
$(call add,config,/build/config)
|
||||||
$(call add,init,/opt/init)
|
$(call add,init,/opt/init)
|
||||||
@echo 'RUN chmod +x /opt/init' >> ${FILE}
|
@echo 'RUN chmod +x /opt/init' >> ${FILE}
|
||||||
|
@mkdir -p $(DOCKER_HOME)/build/parts
|
||||||
$(call script,prepare)
|
$(call script,prepare)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
@rm -rf $(DOCKER_HOME)/build/parts
|
||||||
@rm -f ${FILE}
|
@rm -f ${FILE}
|
||||||
@rm -rf build
|
@rm -rf build
|
||||||
@rm -rf id_rsa
|
@rm -rf id_rsa
|
||||||
|
|||||||
38
build/parts.py
Normal file
38
build/parts.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
|
file = sys.argv[1]
|
||||||
|
docker = open(sys.argv[2], 'a')
|
||||||
|
tmp = sys.argv[3]
|
||||||
|
|
||||||
|
# Remove all normal comments
|
||||||
|
path = '{}/build/scripts/{}.sh'.format(os.environ['DOCKER_HOME'], file)
|
||||||
|
contents = ''
|
||||||
|
for line in open(path):
|
||||||
|
line = line.strip()
|
||||||
|
if len(line) > 0 and not line.startswith('# '):
|
||||||
|
contents += line + '\n'
|
||||||
|
|
||||||
|
# Split on comments starting with ##
|
||||||
|
parts = re.split('## .*', contents)
|
||||||
|
first = parts.pop(0).strip()
|
||||||
|
|
||||||
|
# Iterate over parts, except header
|
||||||
|
i = 0
|
||||||
|
for part in parts:
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
# Add reading environment variables
|
||||||
|
extra = '' if file == 'prepare' else 'export_container_environment\n'
|
||||||
|
|
||||||
|
# Write parts file
|
||||||
|
contents = '{}\n{}{}'.format(first, extra, part)
|
||||||
|
partfile = '{}_{}.sh'.format(file, i)
|
||||||
|
path = '{}/build/parts/{}'.format(os.environ['DOCKER_HOME'], partfile)
|
||||||
|
open(path, 'w').write(contents)
|
||||||
|
os.chmod(path, 0o100)
|
||||||
|
|
||||||
|
# Append to Dockerfile
|
||||||
|
docker.write('ADD parts/{} {}/{}\n'.format(partfile, tmp, partfile))
|
||||||
|
docker.write('RUN {}/{}\n'.format(tmp, partfile))
|
||||||
Reference in New Issue
Block a user