-
Notifications
You must be signed in to change notification settings - Fork 90
/
start
executable file
·39 lines (35 loc) · 1.5 KB
/
start
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
#!/usr/bin/env python
"""
Entrypoint script to dispatch to apache beam if beam is executing
the container, or act like a regular contact when executed in
any other context (like a binder or jupyterhub).
Beam *requires* entrypoint to point to a 'boot' program written
in go. In this container, it is installed in /usr/local/bin/boot.
We detect if beam is calling us and expecting the boot program
to run by checking if the commandline params *required* by the
boot program are present, and calling the boot program if so.
If these arguments are not present, we assume we are not being
called by apache beam, and provide the same behavior as if no
entrypoint is defined.
"""
import os
import sys
# List is provided by running /usr/local/bin/boot, and finding
# the ones marked as 'required'.
REQUIRED_BEAM_BOOT_PARAMS = [
'id', 'control_endpoint', 'logging_endpoint',
'artifact_endpoint', 'provision_endpoint'
]
# Can't just use a simple existence check, as args can be passed in as
# ["-id", "some-id"], ["-id=<some-id>"] or ["--id=<some-id>"]. So we
# strip all preceeding -s, and check that *all* the required parameters
# are passed in at least once
if all(any(arg.lstrip('-').startswith(x) for arg in sys.argv) for x in REQUIRED_BEAM_BOOT_PARAMS):
command = '/opt/apache/beam/boot'
# exec's args need the command to be repeated, or most languages'
# commandline parsers (including go's) will break
args = [command] + sys.argv[1:]
else:
command = sys.argv[1]
args = sys.argv[1:]
os.execvp(command, args)