Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft for slim containers #386

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile-slim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ slim-venv: docker-compose.yaml .env $(DELEGATORS) | $(VIRTUAL_ENV)

# create a delegator to the processing server for the processor
$(BIN)/ocrd-%: | $(VIRTUAL_ENV)
@sed -e "s/{{\s*OCRD_PS_PORT\s*}}/$(OCRD_PS_PORT)/" slim-containers-files/delegator_template.py > $@;
@sed -e "s|{{\s*OCRD_SLIM_ENV_PATH\s*}}|$(CURDIR)/.env|" slim-containers-files/delegator_template.py > $@;
@chmod u+x $@


Expand Down
11 changes: 10 additions & 1 deletion slim-containers-files/delegator_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
import subprocess
from http.server import BaseHTTPRequestHandler, HTTPServer
from os.path import basename
import re
from pathlib import Path

processing_server_address = "http://localhost:{{ OCRD_PS_PORT }}"
env_path = "{{ OCRD_SLIM_ENV_PATH }}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use https://github.com/theskumar/python-dotenv for that, so you don't have to parse sh variable assignments?

try:
port = re.search(r"OCRD_PS_PORT=(?P<port>[0-9]+)",
Path(f'{env_path}').read_text()).group('port')
except:
raise ValueError("Variable OCRD_PS_PORT not found in .env")

processing_server_address = f"http://localhost:{port}"
processor_name = basename(sys.argv[0])

STOP_WAITING_SERVER = False
Expand Down