-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
117 lines (106 loc) · 4.15 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
TAGNAME ?= ghcr.io/slub/ocrd_manager
SHELL = /bin/bash
build:
docker build -t $(TAGNAME) \
--build-arg VCS_REF=`git rev-parse --short HEAD` \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
.
define HELP
cat <<"EOF"
Targets:
- build (re)compile Docker image from sources
- run start up Docker container with SSH service
- test run example workflow on test data
Variables:
- TAGNAME name of Docker image to build/run
currently: "$(TAGNAME)"
- KEYS file to mount as .ssh/authorized_keys
currently: "$(KEYS)"
- PRIVATE file to mount as .ssh/id_rsa
currently: "$(PRIVATE)"
- DATA host directory to mount into `/data`
currently: "$(DATA)"
- WORKFLOWS host directory to mount into `/workflows`
currently: "$(WORKFLOWS)"
- UID user id to use in logins
currently: $(UID)
- GID group id to use in logins
currently: $(GID)
- UMASK user mask to use in logins
currently: $(UMASK)
- PORT TCP port for the (host-side) sshd server
currently: $(PORT)
- NETWORK Docker network to use (manage via "docker network")
currently: $(NETWORK)
- CONTROLLER network address:port for the controller client
(must be reachable from the container network)
currently: $(CONTROLLER)
EOF
endef
export HELP
help: ; @eval "$$HELP"
KEYS ?= $(firstword $(wildcard $(HOME)/.ssh/authorized_keys* $(HOME)/.ssh/id_*.pub))
PRIVATE ?= $(firstword $(filter-out %.pub,$(wildcard $(HOME)/.ssh/id_*)))
DATA ?= $(CURDIR)
WORKFLOWS ?= $(CURDIR)/workflows
UID ?= $(shell id -u)
GID ?= $(shell id -g)
UMASK ?= 0002
PORT ?= 9022
NETWORK ?= bridge
CONTROLLER_HOST ?= $(shell dig +short $$HOSTNAME)
CONTROLLER_PORT_SSH ?= 8022
run: $(DATA)
docker run -d --rm \
-p $(PORT):22 \
-h ocrd_manager \
--name ocrd_manager \
--network=$(NETWORK) \
-v $(DATA):/data \
-v $(WORKFLOWS):/workflows \
--mount type=bind,source=$(KEYS),target=/authorized_keys \
--mount type=bind,source=$(PRIVATE),target=/id_rsa \
-e UID=$(UID) -e GID=$(GID) -e UMASK=$(UMASK) \
-e CONTROLLER=$(CONTROLLER_HOST):$(CONTROLLER_PORT_SSH) \
$(TAGNAME)
$(DATA)/testdata-production:
mkdir -p $@/images
for page in {00000009..00000014}; do \
wget -P $@/images https://digital.slub-dresden.de/data/kitodo/LankDres_1760234508/LankDres_1760234508_tif/jpegs/$$page.tif.original.jpg; \
done
$(DATA)/testdata-presentation: PREFIX = https://digital.slub-dresden.de/data/kitodo/LankDres_1760234508
$(DATA)/testdata-presentation:
mkdir -p $@
wget -O $@/mets.xml $(PREFIX)/LankDres_1760234508_mets.xml
test: test-production test-presentation
# run synchronous (without ActiveMQ)
test-production: SCRIPT = process_images.sh --proc-id 1 --lang deu --script Fraktur
test-production: CONTAINER != docker container ls -n1 -qf name=ocrd-manager
test-production: $(DATA)/testdata-production
ifeq ($(NETWORK),bridge)
$(info using ocrd@localhost:$(PORT))
ssh -i $(PRIVATE) -Tn -p $(PORT) ocrd@localhost $(SCRIPT) $(<F)
else
$(if $(CONTAINER),$(info using $(CONTAINER)),$(error must run ocrd-manager before $@))
if test -t 0 -a -t 1; then TTY=-i; fi; \
docker exec $$TTY -t -u ocrd $(CONTAINER) $(SCRIPT) $(<F)
endif
test -d $</ocr/alto
test -s $</ocr/alto/00000009.tif.original.xml
test-presentation: PREFIX = https://digital.slub-dresden.de/data/kitodo/LankDres_1760234508
test-presentation: SCRIPT = process_mets.sh --pages PHYS_0017..PHYS_0021 --img-grp ORIGINAL --url-prefix $(PREFIX)
test-presentation: CONTAINER != docker container ls -n1 -qf name=ocrd-manager
test-presentation: $(DATA)/testdata-presentation
test-presentation:
ifeq ($(NETWORK),bridge)
$(info using ocrd@localhost:$(PORT))
ssh -i $(PRIVATE) -Tn -p $(PORT) ocrd@localhost $(SCRIPT) $(<F)/mets.xml
else
$(if $(CONTAINER),$(info using $(CONTAINER)),$(error must run ocrd-manager before $@))
if test -t 0 -a -t 1; then TTY=-i; fi; \
docker exec $$TTY -t -u ocrd $(CONTAINER) $(SCRIPT) $(<F)/mets.xml
endif
diff -u <(docker run --rm -v $(DATA):/data $(TAGNAME) ocrd workspace -d $(<F) find -G FULLTEXT -g PHYS_0017..PHYS_0021 -k url) <(for file in FULLTEXT/FULLTEXT_PHYS_00{17..21}.xml; do echo $(PREFIX)/$$file; done)
clean clean-testdata:
$(RM) -r $(DATA)/testdata* $(DATA)/ocr-d/testdata*
.PHONY: build run help test test-production test-presentation clean clean-testdata