forked from iximiuz/docker-to-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
100 lines (80 loc) · 2.06 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
COL_RED="\033[0;31m"
COL_GRN="\033[0;32m"
COL_END="\033[0m"
LOOPDEVICE=$(shell losetup -f)
REPO=docker-to-linux
.PHONY:
debian: debian.img
.PHONY:
ubuntu: ubuntu.img
.PHONY:
alpine: alpine.img
.PHONY:
debian.tar:
@make DISTR="debian" linux.tar
.PHONY:
debian.img:
@make DISTR="debian" linux.img
.PHONY:
ubuntu.tar:
@make DISTR="ubuntu" linux.tar
.PHONY:
ubuntu.img:
@echo $(LOOPDEVICE)
@make DISTR="ubuntu" linux.img
.PHONY:
alpine.tar:
@make DISTR="alpine" linux.tar
.PHONY:
alpine.img:
@make DISTR="alpine" linux.img
linux.tar:
@echo ${COL_GRN}"[Dump ${DISTR} directory structure to tar archive]"${COL_END}
docker build -f ${DISTR}/Dockerfile -t ${REPO}/${DISTR} .
docker export -o linux.tar `docker run -d ${REPO}/${DISTR} /bin/true`
linux.dir: linux.tar
@echo ${COL_GRN}"[Extract ${DISTR} tar archive]"${COL_END}
mkdir linux.dir
tar -xvf linux.tar -C linux.dir
linux.img: builder linux.dir
@echo ${COL_GRN}"[Create ${DISTR} disk image]"${COL_END}
docker run -it \
-v `pwd`:/os:rw \
-e DISTR=${DISTR} \
--privileged \
--cap-add SYS_ADMIN \
--device $(LOOPDEVICE) \
${REPO}/builder bash /os/create_image.sh $(LOOPDEVICE)
.PHONY:
builder:
@echo ${COL_GRN}"[Ensure builder is ready]"${COL_END}
@if [ "`docker images -q ${REPO}/builder`" = '' ]; then\
docker build -f Dockerfile -t ${REPO}/builder .;\
fi
.PHONY:
builder-interactive:
docker run -it \
-v `pwd`:/os:rw \
--cap-add SYS_ADMIN \
--device $(LOOPDEVICE) \
${REPO}/builder bash
.PHONY:
clean: clean-docker-procs clean-docker-images
@echo ${COL_GRN}"[Remove leftovers]"${COL_END}
rm -rf mnt linux.tar linux.dir linux.img linux.vdi
.PHONY:
clean-docker-procs:
@echo ${COL_GRN}"[Remove Docker Processes]"${COL_END}
@if [ "`docker ps -qa -f=label=com.iximiuz-project=${REPO}`" != '' ]; then\
docker rm `docker ps -qa -f=label=com.iximiuz-project=${REPO}`;\
else\
echo "<noop>";\
fi
.PHONY:
clean-docker-images:
@echo ${COL_GRN}"[Remove Docker Images]"${COL_END}
@if [ "`docker images -q ${REPO}/*`" != '' ]; then\
docker rmi `docker images -q ${REPO}/*`;\
else\
echo "<noop>";\
fi