-
Notifications
You must be signed in to change notification settings - Fork 6
/
makefile
115 lines (85 loc) · 3.36 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
# {{{ -- meta
HOSTARCH := $(shell uname -m | sed "s_armv6l_armhf_")# x86_64# on travis.ci
ARCH := $(shell uname -m | sed "s_armv6l_armhf_")# armhf/x86_64 auto-detect on build and run
OPSYS := alpine
SHCOMMAND := /bin/bash
SVCNAME := searx
USERNAME := woahbase
PUID := $(shell id -u)
PGID := $(shell id -g)# gid 100(users) usually pre exists
DOCKERSRC := $(OPSYS)-python3#
DOCKEREPO := $(OPSYS)-$(SVCNAME)
IMAGETAG := $(USERNAME)/$(DOCKEREPO):$(ARCH)
CNTNAME := $(SVCNAME) # name for container name : docker_name, hostname : name
BUILD_NUMBER := 0#assigned in .travis.yml
BRANCH := master
# -- }}}
# {{{ -- flags
BUILDFLAGS := --rm --force-rm --compress \
-f $(CURDIR)/Dockerfile_$(ARCH) \
-t $(IMAGETAG) \
--build-arg DOCKERSRC=$(USERNAME)/$(DOCKERSRC):$(ARCH) \
--build-arg PUID=$(PUID) \
--build-arg PGID=$(PGID) \
--build-arg http_proxy=$(http_proxy) \
--build-arg https_proxy=$(https_proxy) \
--build-arg no_proxy=$(no_proxy) \
--label online.woahbase.source-image=$(DOCKERSRC) \
--label online.woahbase.build-number=$(BUILD_NUMBER) \
--label online.woahbase.branch=$(BRANCH) \
--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)/data:/data
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 8888:8888
RUNFLAGS := -c 512 -m 512m -e PGID=$(PGID) -e PUID=$(PUID)
# -- }}}
# {{{ -- docker targets
all : run
build :
echo "Building for $(ARCH) from $(HOSTARCH)";
if [ "$(ARCH)" != "$(HOSTARCH)" ]; then make regbinfmt ; fi;
docker build $(BUILDFLAGS) $(CACHEFLAGS) .
clean :
docker images | awk '(NR>1) && ($$2!~/none/) {print $$1":"$$2}' | grep "$(USERNAME)/$(DOCKEREPO)" | xargs -n1 docker rmi
logs :
docker logs -f docker_$(CNTNAME)
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 :
docker rm -f docker_$(CNTNAME)
run :
docker run --rm -it $(NAMEFLAGS) $(RUNFLAGS) $(PORTFLAGS) $(MOUNTFLAGS) $(OTHERFLAGS) $(IMAGETAG)
shell :
docker run --rm -it $(NAMEFLAGS) $(RUNFLAGS) $(PORTFLAGS) $(MOUNTFLAGS) $(OTHERFLAGS) --entrypoint $(SHCOMMAND) $(IMAGETAG)
rdebug :
docker exec -u root -it docker_$(CNTNAME) $(SHCOMMAND)
debug :
docker exec -it docker_$(CNTNAME) $(SHCOMMAND)
stop :
docker stop -t 2 docker_$(CNTNAME)
test :
docker run --rm -it $(NAMEFLAGS) $(RUNFLAGS) $(PORTFLAGS) $(MOUNTFLAGS) $(OTHERFLAGS) $(IMAGETAG) sh -ec 'sleep 15; python -V'
# -- }}}
# {{{ -- other targets
regbinfmt :
docker run --rm --privileged multiarch/qemu-user-static:register --reset
# -- }}}