Skip to content

Commit 46273fb

Browse files
committed
- [test](test) Move all tests to separate folder.
1 parent cdb2df2 commit 46273fb

10 files changed

Lines changed: 275 additions & 73 deletions

File tree

.dockerignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
.gitignore
33
.github
44
.gitattributes
5-
demo
5+
src/notused
6+
local
7+
demo/

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: ruby
22
os: linux
3-
dist: bionic
3+
dist: jammy
44
services: docker
55
install: make build-all
66
script: make test-all

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.0.4
2+
3+
- [test](test) Move all tests to separate folder.
4+
15
# 1.0.3
26

37
- [nginx](Dockerfile) Rebuild with new version.

Makefile

Lines changed: 37 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,61 @@
1+
# Makefile
2+
#
3+
# build
4+
#
5+
16
-include *.mk
27

38
BLD_ARG ?= --build-arg DIST=nginx --build-arg REL=alpine
49
BLD_REPO ?= mlan/gitweb
510
BLD_VER ?= latest
611
BLD_TGT ?= full
12+
BLD_TGTS ?= base full
13+
BLD_CMT ?= HEAD
14+
BLD_DNLD ?= curl -o
715

8-
IMG_REPO ?= $(BLD_REPO)
9-
IMG_VER ?= $(BLD_VER)
10-
_version = $(if $(findstring $(BLD_TGT),$(1)),$(2),$(if $(findstring latest,$(2)),$(1),$(1)-$(2)))
11-
_ip = $(shell docker inspect -f \
12-
'{{range .NetworkSettings.Networks}}{{println .IPAddress}}{{end}}' \
13-
$(1) | head -n1)
14-
15-
TST_NAME ?= test-gitweb
16-
TST_BIND ?= 127.0.0.1:8080
17-
TST_INET ?= -p $(TST_BIND):80
18-
TST_VOLS ?= -v $$(pwd)/.git:/var/lib/git/repositories/docker-gitweb.git:ro
19-
TST_ENVV ?= -e PROJECTS_LIST=
20-
21-
TST_W8UP ?= 1
22-
TST_W8DN ?= 2
23-
24-
.PHONY:
25-
26-
build-all: build_base build_full
27-
28-
build: depends
29-
docker build $(BLD_ARG) --target $(BLD_TGT) -t $(BLD_REPO):$(BLD_VER) .
30-
31-
build_%: depends
32-
docker build $(BLD_ARG) --target $* -t $(BLD_REPO):$(call _version,$*,$(BLD_VER)) .
33-
34-
depends: Dockerfile
35-
36-
test-all: test_1 test_2
37-
38-
test_%: test-up_% test-waitu_% test-html_% test-down_% test-waitd_%
39-
40-
test-up_1:
41-
#
42-
#
43-
#
44-
# test (1) base, mount .git
45-
#
46-
#
47-
docker run --rm -d --name $(TST_NAME) $(TST_ENVV) $(TST_VOLS) $(TST_INET) $(IMG_REPO):$(call _version,base,$(IMG_VER))
16+
TST_REPO ?= $(BLD_REPO)
17+
TST_VER ?= $(BLD_VER)
18+
TST_ENV ?= -C test
19+
TST_TGTE ?= $(addprefix test-,all diff down env logs sh up)
20+
TST_INDX ?= 1 2
21+
TST_TGTI ?= $(addprefix test_,$(TST_INDX)) $(addprefix test-up_,$(TST_INDX))
4822

49-
test-up_2:
50-
#
51-
#
52-
#
53-
# test (2) full, mount .git
54-
#
55-
#
56-
docker run --rm -d --name $(TST_NAME) $(TST_ENVV) $(TST_VOLS) $(TST_INET) $(IMG_REPO):$(call _version,full,$(IMG_VER))
23+
export TST_REPO TST_VER
5724

58-
test-html_%:
59-
wget -O - $(TST_BIND) >/dev/null || false
60-
#
61-
#
62-
# test ($*) success ☺
25+
push:
6326
#
27+
# PLEASE REVIEW THESE IMAGES WHICH ARE ABOUT TO BE PUSHED TO THE REGISTRY
6428
#
29+
@docker image ls $(BLD_REPO)
6530
#
31+
# ARE YOU SURE YOU WANT TO PUSH THESE IMAGES TO THE REGISTRY? [yN]
32+
@read input; [ "$${input}" = "y" ]
33+
docker push --all-tags $(BLD_REPO)
6634

67-
test-down_%:
68-
docker stop $(TST_NAME) 2>/dev/null || true
35+
build-all: $(addprefix build_,$(BLD_TGTS))
6936

70-
test-waitu_%:
71-
sleep $(TST_W8UP)
37+
build: build_$(BLD_TGT)
7238

73-
test-waitd_%:
74-
sleep $(TST_W8DN)
39+
build_%: pre_build
40+
docker build $(BLD_ARG) --target $* \
41+
$(addprefix --tag $(BLD_REPO):,$(call bld_tags,$*,$(BLD_VER))) .
7542

76-
test-up: test-up_1
77-
78-
test-html: test-html_0
79-
80-
test-down: test-down_0
43+
pre_build: Dockerfile
8144

82-
8345
variables:
8446
make -pn | grep -A1 "^# makefile"| grep -v "^#\|^--" | sort | uniq
8547

48+
ps:
49+
docker ps -a
50+
8651
prune:
8752
docker image prune -f
8853

89-
prune-all:
90-
docker image prune
91-
docker container prune
92-
docker volume prune
93-
docker network prune
54+
clean:
55+
docker images | grep $(BLD_REPO) | awk '{print $$1 ":" $$2}' | uniq | xargs docker rmi
56+
57+
$(TST_TGTE):
58+
${MAKE} $(TST_ENV) $@
9459

60+
$(TST_TGTI):
61+
${MAKE} $(TST_ENV) $@

ROADMAP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Road map
22

3-
Nothing yet.
3+
Nothing yet.

bld.mk

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# bld.mk
2+
#
3+
# Docker build make-functions
4+
#
5+
6+
BLD_VER ?= latest
7+
BLD_TGT ?= full
8+
BLD_CMT ?= HEAD
9+
10+
#
11+
# $(call bld_tags,mini,) -> mini mini-1.2.3 mini-1.2 mini-1
12+
# $(call bld_tags,full,) -> latest full 1.2.3 1.2 1 full-1.2.3 full-1.2 full-1
13+
# $(call bld_tags,,) -> latest 1.2.3 1.2 1
14+
#
15+
# $(call bld_tags,mini,something) -> mini-something
16+
# $(call bld_tags,full,something) -> something full-something
17+
# $(call bld_tags,,something) -> something
18+
#
19+
# $(call bld_tags,mini,latest) -> mini
20+
# $(call bld_tags,full,latest) -> latest full
21+
# $(call bld_tags,,latest) -> latest
22+
#
23+
bld_tags = $(if $(2),\
24+
$(call bld_ver,$(1),$(2)),\
25+
$(call bld_ver,$(1),latest) $(call bld_ver,$(1),$(call bld_gittags)))
26+
27+
#
28+
# $(call bld_ver,mini,something) -> mini-something
29+
# $(call bld_ver,full,something) -> something full-something
30+
# $(call bld_ver,,something) -> something
31+
#
32+
# $(call bld_ver,mini,latest) -> mini
33+
# $(call bld_ver,full,latest) -> latest full
34+
# $(call bld_ver,,latest) -> latest
35+
#
36+
bld_ver = $(if $(1),\
37+
$(if $(findstring $(BLD_TGT),$(1)),\
38+
$(if $(findstring latest,$(2)),latest $(1),$(2) $(addprefix $(1)-,$(2))),\
39+
$(if $(findstring latest,$(2)),$(1),$(addprefix $(1)-,$(2)))),\
40+
$(2))
41+
42+
#
43+
# $(call bld_tag,full,) -> full
44+
# $(call bld_tag,,) -> latest
45+
#
46+
# $(call bld_tag,full,something) -> full-something
47+
# $(call bld_tag,,something) -> something
48+
#
49+
# $(call bld_tag,full,latest) -> full
50+
# $(call bld_tag,,latest) -> latest
51+
#
52+
bld_tag = $(strip $(if $(1),\
53+
$(if $(2),$(if $(findstring latest,$(2)),$(1),$(1)-$(2)),$(1)),\
54+
$(if $(2),$(2),latest)))
55+
56+
#
57+
# $(call bld_gittags,HEAD) -> 1.2.3 1.2 1
58+
#
59+
bld_gittags = $(subst v,,$(shell git tag --points-at $(BLD_CMT)))

dkr.mk

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# dkr.mk
2+
#
3+
# Container make-functions
4+
#
5+
6+
#
7+
# $(call dkr_srv_cnt,app) -> d03dda046e0b90c...
8+
#
9+
dkr_srv_cnt = $(shell docker-compose ps -q $(1) | head -n1)
10+
#
11+
# $(call dkr_cnt_ip,demo-app-1) -> 172.28.0.3
12+
#
13+
dkr_cnt_ip = $(shell docker inspect -f \
14+
'{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' \
15+
$(1) | head -n1)
16+
#
17+
# $(call dkr_srv_ip,app) -> 172.28.0.3
18+
#
19+
dkr_srv_ip = $(shell docker inspect -f \
20+
'{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' \
21+
$$(docker-compose ps -q $(1)) | head -n1)
22+
#
23+
# $(call dkr_cnt_pid,demo-app-1) -> 9755
24+
#
25+
dkr_cnt_pid = $(shell docker inspect --format '{{.State.Pid}}' $(1))
26+
#
27+
#cnt_ip_old = $(shell docker inspect -f \
28+
# '{{range .NetworkSettings.Networks}}{{println .IPAddress}}{{end}}' \
29+
# $(1) | head -n1)
30+
31+
#
32+
# $(call dkr_cnt_state,demo-app-1) -> docker inspect -f '{{.State.Status}}' demo-app-1
33+
#
34+
dkr_cnt_state = docker inspect -f '{{.State.Status}}' $(1)
35+
36+
#
37+
# $(call dkr_cnt_wait_run,test-db,180) -> i=0; time while ! [ "$(docker inspect -f '{{.State.Status}}' test-db)" = "running" ]; do sleep 1; i=$((i+1)); if [[ $i > 180 ]]; then echo test-db timeout with state: $(docker inspect -f '{{.State.Status}}' test-db); break; fi; done
38+
#
39+
dkr_cnt_wait_run = i=0; time while ! [ "$$($(call dkr_cnt_state, $(1)))" = "running" ]; do sleep 1; i=$$((i+1)); if [[ $$i > $(2) ]]; then echo $(1) timeout with state: $$($(call dkr_cnt_state, $(1))); break; fi; done
40+
41+
#
42+
# $(call dkr_srv_wait_run,180,app) -> wait up to 180s for app to enter state running
43+
#
44+
dkr_srv_wait_run = $(call dkr_cnt_wait_run,$(call dkr_srv_cnt $(1)),$(2))
45+
46+
#
47+
# $(call dkr_cnt_wait_log,app,ready for connections) -> time docker logs -f app | sed -n '/ready for connections/{p;q}'
48+
#
49+
dkr_cnt_wait_log = time docker logs -f $(1) 2>&1 | sed -n '/$(2)/{p;q}'
50+
51+
#
52+
# $(call dkr_pull_missing,mariadb:latest) -> if ! docker image inspect mariadb:latest &>/dev/null; then docker pull mariadb:latest; fi
53+
#
54+
dkr_pull_missing = if ! docker image inspect $(1) &>/dev/null; then docker pull $(1); fi
55+
56+
#
57+
# List IPs of containers
58+
#
59+
ip-list:
60+
@for srv in $$(docker ps --format "{{.Names}}"); do \
61+
echo $$srv $$(docker inspect -f \
62+
'{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $$srv); \
63+
done | column -t

test/Makefile

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Makefile
2+
#
3+
# test
4+
#
5+
6+
-include *.mk
7+
8+
TST_REPO ?= mlan/gitweb
9+
TST_VER ?= latest
10+
TST_NAME ?= test
11+
12+
TST_BIND ?= 127.0.0.1:8080
13+
TST_INET ?= -p $(TST_BIND):80
14+
TST_VOLS ?= -v $$(pwd)/../.git:/var/lib/git/repositories/docker-gitweb.git:ro
15+
TST_ENVV ?= -e PROJECTS_LIST=
16+
17+
TST_W8UP ?= 1
18+
TST_W8DN ?= 2
19+
20+
CNT_NAME ?= $(TST_NAME)-gui
21+
CNT_LIST ?= gui
22+
23+
NET_SYSP := $(shell command -v nft)
24+
25+
ifdef NET_SYSP
26+
NET_RULE := nft list ruleset
27+
else
28+
NET_RULE := iptables -t nat -nvL
29+
endif
30+
31+
test-all: $(addprefix test_,1 2)
32+
33+
test_%: test-up_% test-waitu_% test-html_% test-down_% test-waitd_%
34+
35+
test-up_1:
36+
#
37+
#
38+
#
39+
# test (1) base, mount .git
40+
#
41+
#
42+
docker run --rm -d --name $(CNT_NAME) $(TST_ENVV) $(TST_VOLS) $(TST_INET) $(TST_REPO):$(call bld_tag,base,$(TST_VER))
43+
44+
test-up_2:
45+
#
46+
#
47+
#
48+
# test (2) full, mount .git
49+
#
50+
#
51+
docker run --rm -d --name $(CNT_NAME) $(TST_ENVV) $(TST_VOLS) $(TST_INET) $(TST_REPO):$(call bld_tag,full,$(TST_VER))
52+
53+
test-html_%:
54+
wget -O - $(TST_BIND) >/dev/null || false
55+
#
56+
#
57+
# test ($*) success ☺
58+
#
59+
#
60+
#
61+
62+
test-down_%:
63+
docker stop $(CNT_NAME) 2>/dev/null || true
64+
65+
test-waitu_%:
66+
sleep $(TST_W8UP)
67+
68+
test-waitd_%:
69+
sleep $(TST_W8DN)
70+
71+
test-up: test-up_1
72+
73+
test-html: test-html_0
74+
75+
test-down: test-down_0
76+
77+
$(addprefix test-,diff env htop logs sh nsrule nsss):
78+
${MAKE} $(patsubst test-%,gui-%,$@)
79+
80+
$(addsuffix -sh,$(CNT_LIST)):
81+
docker exec -it $(patsubst %-sh,$(TST_NAME)-%,$@) sh -c 'exec $$(getent passwd root | sed "s/.*://g")'
82+
83+
$(addsuffix -env,$(CNT_LIST)):
84+
docker exec -it $(patsubst %-env,$(TST_NAME)-%,$@) env
85+
86+
$(addsuffix -logs,$(CNT_LIST)):
87+
docker container logs $(patsubst %-logs,$(TST_NAME)-%,$@)
88+
89+
$(addsuffix -diff,$(CNT_LIST)):
90+
docker container diff $(patsubst %-diff,$(TST_NAME)-%,$@)
91+
92+
$(addsuffix -tools,$(CNT_LIST)):
93+
docker exec -it $(patsubst %-tools,$(TST_NAME)-%,$@) \
94+
apk --no-cache --update add \
95+
nano less lsof htop bind-tools iputils strace util-linux
96+
97+
$(addsuffix -htop,$(CNT_LIST)):
98+
docker exec -it $(patsubst %-htop,$(TST_NAME)-%,$@) htop
99+
100+
$(addsuffix -nsrule,$(CNT_LIST)):
101+
sudo nsenter -n -t $(call dkr_cnt_pid,$(patsubst %-nsrule,$(TST_NAME)-%,$@)) $(NET_RULE)
102+
103+
$(addsuffix -nsss,$(CNT_LIST)):
104+
sudo nsenter -n -t $(call dkr_cnt_pid,$(patsubst %-nsss,$(TST_NAME)-%,$@)) ss -utnlp
105+

test/bld.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../bld.mk

test/dkr.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../dkr.mk

0 commit comments

Comments
 (0)