Skip to content

Commit c66c571

Browse files
ObadaSObada HaddadDidayolo
authored
HTTP(S) and Network mode options in Compute worker (#2137)
* add http(s) proxy and network mode for the compute worker as options in the .env * fix error from previous commit * add documentation about the new compute worker features * Make test more robust * Rename variable for clarity * Slight syntax re-writing --------- Co-authored-by: Obada Haddad <obada.haddad@lisn.fr> Co-authored-by: didayolo <adrien.pavao@gmail.com>
1 parent 871bc4a commit c66c571

4 files changed

Lines changed: 82 additions & 6 deletions

File tree

compute_worker/compute_worker.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,16 @@
5555
+ os.environ.get("CONTAINER_ENGINE_EXECUTABLE", "docker").upper()
5656
+ "with GPU capabilites : "
5757
+ os.environ.get("GPU_DEVICE", "nvidia.com/gpu=all")
58+
+ " network_disabled for the competition container is set to "
59+
+ os.environ.get("COMPETITION_CONTAINER_NETWORK_DISABLED", "False")
5860
)
5961
else:
6062
logger.info(
6163
"Using "
6264
+ os.environ.get("CONTAINER_ENGINE_EXECUTABLE", "docker").upper()
63-
+ " without GPU capabilities"
65+
+ " without GPU capabilities. "
66+
+ "network_disabled for the competition container is set to "
67+
+ os.environ.get("COMPETITION_CONTAINER_NETWORK_DISABLED", "False")
6468
)
6569

6670
if os.environ.get("CONTAINER_ENGINE_EXECUTABLE", "docker").lower() == "docker":
@@ -1007,6 +1011,26 @@ async def _run_program_directory(self, program_dir, kind):
10071011
if kind == "ingestion"
10081012
else self.program_container_name
10091013
)
1014+
# Disable or not the competition container access to Internet (False by default)
1015+
container_network_disabled = os.environ.get(
1016+
"COMPETITION_CONTAINER_NETWORK_DISABLED", ""
1017+
)
1018+
1019+
# HTTP and HTTPS proxy for the competition container if needed
1020+
competition_container_proxy_http = os.environ.get(
1021+
"COMPETITION_CONTAINER_HTTP_PROXY", ""
1022+
)
1023+
competition_container_proxy_http = (
1024+
"http_proxy=" + competition_container_proxy_http
1025+
)
1026+
1027+
competition_container_proxy_https = os.environ.get(
1028+
"COMPETITION_CONTAINER_HTTPS_PROXY", ""
1029+
)
1030+
competition_container_proxy_https = (
1031+
"https_proxy=" + competition_container_proxy_https
1032+
)
1033+
10101034
container = client.create_container(
10111035
self.container_image,
10121036
name=container_name,
@@ -1015,7 +1039,12 @@ async def _run_program_directory(self, program_dir, kind):
10151039
volumes=volumes_host,
10161040
command=command,
10171041
working_dir="/app/program",
1018-
environment=["PYTHONUNBUFFERED=1"],
1042+
environment=[
1043+
"PYTHONUNBUFFERED=1",
1044+
competition_container_proxy_http,
1045+
competition_container_proxy_https,
1046+
],
1047+
network_disabled=container_network_disabled.lower() == "true",
10191048
)
10201049
logger.debug("Created container : " + str(container))
10211050
logger.info("Volume configuration of the container: ")

documentation/docs/Organizers/Running_a_benchmark/Compute-Worker-Management---Setup.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,37 @@ You will get your Broker URL from the instance. More information about Queues [h
4040

4141
Make a file `.env` and put this in it:
4242
```ini title=".env"
43+
#######################################################################
44+
# Connection URL #
45+
#######################################################################
4346
BROKER_URL=pyamqp://<login>:<password>@www.codabench.org:5672/
44-
HOST_DIRECTORY=/codabench
4547
# If SSL isn't enabled, then comment or remove the following line
4648
BROKER_USE_SSL=True
49+
50+
#######################################################################
51+
# Temporary Storage #
52+
#######################################################################
53+
HOST_DIRECTORY=/codabench
54+
55+
56+
#######################################################################
57+
# Runtime #
58+
#######################################################################
59+
CONTAINER_ENGINE_EXECUTABLE=docker
4760
#USE_GPU=True
4861
#GPU_DEVICE=nvidia.com/gpu=all
62+
63+
#######################################################################
64+
# Network #
65+
#######################################################################
66+
#COMPETITION_CONTAINER_NETWORK_DISABLED=False
67+
68+
#COMPETITION_CONTAINER_HTTP_PROXY=https://example_proxy:123
69+
#COMPETITION_CONTAINER_HTTPS_PROXY=http://example_proxy:1233
4970
```
71+
By default, the competition container created by the compute worker has access to internet. If you want to remove this access, you can uncomment `COMPETITION_CONTAINER_NETWORK_DISABLED` and set it to `True`
72+
73+
If the VM hosting the compute worker is behind a proxy, and you want to allow the competition container to access internet, you will also need to set the proxy for the competition container to use, in which case you can use `COMPETITION_CONTAINER_HTTP_PROXY`
5074

5175
!!! note
5276
- The broker URL is a unique identifier of the job queue that the worker should listen to. To create a queue or obtain the broker URL of an existing queue, you can refer to [Queue Management](Queue-Management.md) docs page.

documentation/docs/Organizers/Running_a_benchmark/Compute-worker-installation-with-Podman.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,38 @@ unqualified-search-registries = ["docker.io"]
1818
Create the `.env` file in order to add the compute worker into a queue (here, the default queue is used. If you use a particular queue, then, fill in your BROKER_URL generated when creating this particular queue) :
1919

2020
```ini title=".env"
21+
#######################################################################
22+
# Connection URL #
23+
#######################################################################
2124
BROKER_URL=pyamqp://<login>:<password>@www.codabench.org:5672/
22-
HOST_DIRECTORY=/codabench
2325
# If SSL isn't enabled, then comment or remove the following line
2426
BROKER_USE_SSL=True
27+
28+
#######################################################################
29+
# Temporary Storage #
30+
#######################################################################
31+
HOST_DIRECTORY=/codabench
32+
33+
34+
#######################################################################
35+
# Runtime #
36+
#######################################################################
2537
CONTAINER_ENGINE_EXECUTABLE=podman
2638
#USE_GPU=True
2739
#GPU_DEVICE=nvidia.com/gpu=all
40+
41+
#######################################################################
42+
# Network #
43+
#######################################################################
44+
#COMPETITION_CONTAINER_NETWORK_DISABLED=False
45+
46+
#COMPETITION_CONTAINER_HTTP_PROXY=https://example_proxy:123
47+
#COMPETITION_CONTAINER_HTTPS_PROXY=http://example_proxy:1233
2848
```
2949

50+
By default, the competition container created by the compute worker has access to internet. If you want to remove this access, you can uncomment `COMPETITION_CONTAINER_NETWORK_DISABLED` and set it to `True`
51+
52+
If the VM hosting the compute worker is behind a proxy, and you want to allow the competition container to access internet, you will also need to set the proxy for the competition container to use, in which case you can use `COMPETITION_CONTAINER_HTTP_PROXY`
3053

3154
You will also need to create the `codabench` folder defined in the `.env` file, as well as change its permissions to the user that is running the compute worker.
3255

src/factories.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ class ColumnFactory(DjangoModelFactory):
195195
class Meta:
196196
model = Column
197197

198-
title = factory.Faker('word')
199-
key = factory.Faker('word')
200198
index = factory.Sequence(lambda n: n)
199+
title = factory.LazyAttribute(lambda n: f"Col_{n.index}")
200+
key = factory.LazyAttribute(lambda n: f"col_{n.index}")
201201
leaderboard = factory.SubFactory(LeaderboardFactory)
202202
sorting = factory.LazyAttribute(lambda n: random.choice(['asc', 'desc']))
203203

0 commit comments

Comments
 (0)