-
Notifications
You must be signed in to change notification settings - Fork 1
/
makefile
149 lines (118 loc) · 4.73 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# {{{ -- meta
HOSTARCH := x86_64# on travis.ci
ARCH := $(shell uname -m | sed "s_armv7l_armhf_")# armhf/x86_64 auto-detect on build and run
OPSYS := alpine
SHCOMMAND := /bin/bash
SVCNAME := buildbot
USERNAME := woahbase
ROLE := master# master / worker
DOCKERSRC := $(OPSYS)-python3#
DOCKEREPO := $(OPSYS)-$(SVCNAME)
IMAGETAG := $(USERNAME)/alpine-build$(ROLE):$(ARCH)
WORKERNAME := $(shell cat /etc/hostname)
REQUIRED_PIP := "PyMySQL txrequests"#
REQUIRED_APK := "curl git"# openssh-client git make docker
BUILDBOT_HOME := /home/alpine/buildbot-config
# for creating workers
MASTERADDRESS := localhost
PASSWORD := insecurebydefault# worker credentials : WORKERNAME / PASSWORD
CNTNAME := build$(ROLE) # name for container name : docker_name, hostname : name
# -- }}}
# {{{ -- flags
BUILDFLAGS := --rm --force-rm --compress -f $(CURDIR)/Dockerfile_$(ARCH) -t $(IMAGETAG) \
--build-arg ARCH=$(ARCH) \
--build-arg DOCKERSRC=$(DOCKERSRC) \
--build-arg USERNAME=$(USERNAME) \
--build-arg ROLE=$(ROLE) \
--label org.label-schema.build-date=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") \
--label org.label-schema.name=$(DOCKEREPO) \
--label org.label-schema.schema-version="1.0" \
--label org.label-schema.url="https://woahbase.online/" \
--label org.label-schema.usage="https://woahbase.online/\#/images/$(DOCKEREPO)" \
--label org.label-schema.vcs-ref=$(shell git rev-parse --short HEAD) \
--label org.label-schema.vcs-url="https://github.com/$(USERNAME)/$(DOCKEREPO)" \
--label org.label-schema.vendor=$(USERNAME)
CACHEFLAGS := --no-cache=true --pull
MOUNTFLAGS := -v $(CURDIR)/config:$(BUILDBOT_HOME)
NAMEFLAGS := --name docker_$(CNTNAME) --hostname $(CNTNAME)
OTHERFLAGS := # -v /etc/hosts:/etc/hosts:ro -v /etc/localtime:/etc/localtime:ro -e TZ=Asia/Kolkata
PORTFLAGS := -p 9989:9989 -p 8010:8010 -p 9990:9990
PROXYFLAGS := --build-arg http_proxy=$(http_proxy) --build-arg https_proxy=$(https_proxy) --build-arg no_proxy=$(no_proxy)
RUNFLAGS := -c 256 -m 256m \
-e PGID=$(shell id -g) -e PUID=$(shell id -u) \
-e WORKERNAME=$(WORKERNAME) -e BUILDBOT_HOME=$(BUILDBOT_HOME) \
-e REQUIRED_PIP=$(REQUIRED_PIP) -e REQUIRED_APK=$(REQUIRED_APK) \
-e http_proxy=$(http_proxy) -e https_proxy=$(https_proxy) -e no_proxy=$(no_proxy)
# -- }}}
# {{{ -- docker targets
all : run #setup first
build :
echo "Building for $(ARCH) from $(HOSTARCH)";
if [ "$(ARCH)" != "$(HOSTARCH)" ]; then make regbinfmt ; fi;
docker build $(BUILDFLAGS) $(CACHEFLAGS) $(PROXYFLAGS) .
clean :
docker images | awk '(NR>1) && ($$2!~/none/) {print $$1":"$$2}' | grep "$(USERNAME)/build$(ROLE)" | xargs -n1 docker rmi
rm -rf ./config/*
logs :
if [ "$(ROLE)" = "master" ]; \
then \
docker exec -it docker_$(CNTNAME) tail -f $(BUILDBOT_HOME)/$(WORKERNAME)-master/twistd.log; \
elif [ "$(ROLE)" = "worker" ]; \
then \
docker exec -it docker_$(CNTNAME) tail -f $(BUILDBOT_HOME)/$(WORKERNAME)-worker/twistd.log; \
fi;
pull :
docker pull $(IMAGETAG)
push :
docker push $(IMAGETAG); \
if [ "$(ARCH)" = "$(HOSTARCH)" ]; \
then \
LATESTTAG=$$(echo $(IMAGETAG) | sed 's/:$(ARCH)/:latest/'); \
docker tag $(IMAGETAG) $${LATESTTAG}; \
docker push $${LATESTTAG}; \
fi;
restart :
docker ps -a | grep 'docker_$(CNTNAME)' -q && docker restart docker_$(CNTNAME) || echo "Service not running.";
rm : stop
docker rm -f docker_$(CNTNAME)
run :
if [ "$(ROLE)" = "master" ]; \
then \
docker run --rm -it $(NAMEFLAGS) $(RUNFLAGS) -e ROLE=$(ROLE) \
$(PORTFLAGS) $(MOUNTFLAGS) $(OTHERFLAGS) $(IMAGETAG); \
elif [ "$(ROLE)" = "worker" ]; \
then \
docker run --rm -it $(NAMEFLAGS) $(RUNFLAGS) -e ROLE=$(ROLE) \
$(MOUNTFLAGS) $(OTHERFLAGS) $(IMAGETAG); \
fi;
rshell :
docker exec -u root -it docker_$(CNTNAME) $(SHCOMMAND)
setup :
if [ "$(ROLE)" = "master" ]; \
then \
docker run --rm -it $(NAMEFLAGS) $(RUNFLAGS) \
-e ROLE=$(ROLE) -e PASSWORD=$(PASSWORD) \
$(PORTFLAGS) $(MOUNTFLAGS) $(OTHERFLAGS) $(IMAGETAG); \
elif [ "$(ROLE)" = "worker" ]; \
then \
docker run --rm -it $(NAMEFLAGS) $(RUNFLAGS) -e ROLE=$(ROLE) \
-e MASTERADDRESS=$(MASTERADDRESS) -e PASSWORD=$(PASSWORD) \
$(MOUNTFLAGS) $(OTHERFLAGS) $(IMAGETAG); \
fi;
shell :
docker exec -it docker_$(CNTNAME) $(SHCOMMAND)
stop :
docker stop -t 2 docker_$(CNTNAME)
test :
if [ "$(ROLE)" = "master" ]; \
then \
docker run --rm -it $(NAMEFLAGS) $(RUNFLAGS) $(PORTFLAGS) $(MOUNTFLAGS) $(OTHERFLAGS) --entrypoint buildbot $(IMAGETAG) '--version'; \
elif [ "$(ROLE)" = "worker" ]; \
then \
docker run --rm -it $(NAMEFLAGS) $(RUNFLAGS) $(PORTFLAGS) $(MOUNTFLAGS) $(OTHERFLAGS) --entrypoint buildbot-worker $(IMAGETAG) '--version'; \
fi;
# -- }}}
# {{{ -- other targets
regbinfmt :
docker run --rm --privileged multiarch/qemu-user-static:register --reset
# -- }}}