Skip to content

Commit

Permalink
[Backend] Add custom worker image for challenges (#4077)
Browse files Browse the repository at this point in the history
* Add support for defining custom worker

Signed-off-by: AyushR1 <ayushrathore12501@gmail.com>

* Fix global dict change and only modify worker image

Signed-off-by: AyushR1 <ayushrathore12501@gmail.com>

* Revert "Fix global dict change and only modify worker image"

This reverts commit 1fa5795.

* Update according to review

Signed-off-by: AyushR1 <ayushrathore12501@gmail.com>

---------

Signed-off-by: AyushR1 <ayushrathore12501@gmail.com>
Co-authored-by: Gunjan Chhablani <chhablani.gunjan@gmail.com>
  • Loading branch information
AyushR1 and gchhablani authored Aug 9, 2023
1 parent e3f83d7 commit 3cf4204
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
22 changes: 16 additions & 6 deletions apps/challenges/aws_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ def register_task_def_by_challenge_pk(client, queue_name, challenge):
AWS_SES_REGION_NAME = settings.AWS_SES_REGION_NAME
AWS_SES_REGION_ENDPOINT = settings.AWS_SES_REGION_ENDPOINT

if challenge.worker_image_url:
updated_settings = {**COMMON_SETTINGS_DICT, "WORKER_IMAGE": challenge.worker_image_url}
else:
updated_settings = COMMON_SETTINGS_DICT

if execution_role_arn:
from .utils import get_aws_credentials_for_challenge

Expand Down Expand Up @@ -208,7 +213,7 @@ def register_task_def_by_challenge_pk(client, queue_name, challenge):
log_group_name=log_group_name,
EVALAI_DNS=EVALAI_DNS,
EFS_ID=efs_id,
**COMMON_SETTINGS_DICT,
**updated_settings,
**challenge_aws_keys,
)
)
Expand All @@ -221,7 +226,7 @@ def register_task_def_by_challenge_pk(client, queue_name, challenge):
log_group_name=log_group_name,
AWS_SES_REGION_NAME=AWS_SES_REGION_NAME,
AWS_SES_REGION_ENDPOINT=AWS_SES_REGION_ENDPOINT,
**COMMON_SETTINGS_DICT,
**updated_settings,
**aws_keys,
)
)
Expand All @@ -231,7 +236,7 @@ def register_task_def_by_challenge_pk(client, queue_name, challenge):
submission_container=submission_container,
CPU=worker_cpu_cores,
MEMORY=worker_memory,
**COMMON_SETTINGS_DICT,
**updated_settings,
)
else:
definition = task_definition_code_upload_worker.format(
Expand All @@ -248,7 +253,7 @@ def register_task_def_by_challenge_pk(client, queue_name, challenge):
log_group_name=log_group_name,
EVALAI_DNS=EVALAI_DNS,
EFS_ID=efs_id,
**COMMON_SETTINGS_DICT,
**updated_settings,
**challenge_aws_keys,
)
else:
Expand All @@ -262,7 +267,7 @@ def register_task_def_by_challenge_pk(client, queue_name, challenge):
log_group_name=log_group_name,
AWS_SES_REGION_NAME=AWS_SES_REGION_NAME,
AWS_SES_REGION_ENDPOINT=AWS_SES_REGION_ENDPOINT,
**COMMON_SETTINGS_DICT,
**updated_settings,
**challenge_aws_keys,
)
definition = eval(definition)
Expand Down Expand Up @@ -669,6 +674,11 @@ def scale_resources(challenge, worker_cpu_cores, worker_memory):
logger.exception(e)
return e.response

if challenge.worker_image_url:
updated_settings = {**COMMON_SETTINGS_DICT, "WORKER_IMAGE": challenge.worker_image_url}
else:
updated_settings = COMMON_SETTINGS_DICT

queue_name = challenge.queue
container_name = "worker_{}".format(queue_name)
log_group_name = get_log_group_name(challenge.pk)
Expand All @@ -683,7 +693,7 @@ def scale_resources(challenge, worker_cpu_cores, worker_memory):
log_group_name=log_group_name,
AWS_SES_REGION_NAME=settings.AWS_SES_REGION_NAME,
AWS_SES_REGION_ENDPOINT=settings.AWS_SES_REGION_ENDPOINT,
**COMMON_SETTINGS_DICT,
**updated_settings,
**challenge_aws_keys,
)
task_def = eval(task_def)
Expand Down
18 changes: 18 additions & 0 deletions apps/challenges/migrations/0099_challenge_worker_image_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.20 on 2023-07-31 22:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('challenges', '0098_challenge_tags_domains'),
]

operations = [
migrations.AddField(
model_name='challenge',
name='worker_image_url',
field=models.URLField(blank=True, default=None, null=True),
),
]
1 change: 1 addition & 0 deletions apps/challenges/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ def __init__(self, *args, **kwargs):
job_memory = models.CharField(
max_length=256, null=True, blank=True, default="8Gi"
)
worker_image_url = models.URLField(max_length=200, blank=True, null=True, default=None)

class Meta:
app_label = "challenges"
Expand Down

0 comments on commit 3cf4204

Please sign in to comment.