Skip to content

Commit

Permalink
[Deployment] Add worker image url support for ec2 worker (#4119)
Browse files Browse the repository at this point in the history
* add worker image url support for ec2 worker

* Remove white line and add a if

* Improve if condition
  • Loading branch information
Suryansh5545 authored Aug 11, 2023
1 parent ffc61b4 commit 40e1f37
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
3 changes: 3 additions & 0 deletions apps/challenges/aws_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,8 @@ def setup_ec2(challenge):
with open('/code/scripts/deployment/deploy_ec2_worker.sh') as f:
ec2_worker_script = f.read()

challenge_obj.worker_image_url = "" if challenge_obj.worker_image_url is None else challenge_obj.worker_image_url

variables = {
"AWS_ACCOUNT_ID": aws_keys["AWS_ACCOUNT_ID"],
"AWS_ACCESS_KEY_ID": aws_keys["AWS_ACCESS_KEY_ID"],
Expand All @@ -1645,6 +1647,7 @@ def setup_ec2(challenge):
"PK": str(challenge_obj.pk),
"QUEUE": challenge_obj.queue,
"ENVIRONMENT": settings.ENVIRONMENT,
"CUSTOM_WORKER_IMAGE": challenge_obj.worker_image_url,
}

for key, value in variables.items():
Expand Down
23 changes: 18 additions & 5 deletions scripts/deployment/deploy_ec2_worker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,27 @@ eval $(aws ecr get-login --no-include-email)
echo "Step 7/10: Copying Docker environment file"
aws s3 cp s3://cloudcv-secrets/evalai/${ENVIRONMENT}/docker_${ENVIRONMENT}.env ./docker/prod/docker_${ENVIRONMENT}.env

# Step 8: Pulling worker Docker image
echo "Step 8/10: Pulling worker Docker image"
docker-compose -f docker-compose-${ENVIRONMENT}.yml pull worker
if [ -z "$CUSTOM_WORKER_IMAGE" ];
then
# Step 8: Pulling worker Docker image
echo "Step 8/10: Pulling worker Docker image"
docker-compose -f docker-compose-${ENVIRONMENT}.yml pull worker
else
# if using custom image from worker_image_url
echo "Using custom worker image: $CUSTOM_WORKER_IMAGE"
docker pull $CUSTOM_WORKER_IMAGE
fi

# Step 9: Running worker Docker container
echo "Step 9/10: Running worker Docker container"
docker-compose -f docker-compose-${ENVIRONMENT}.yml run --name=worker_${QUEUE} -e CHALLENGE_QUEUE=${QUEUE} -e CHALLENGE_PK=${PK} -d worker
echo "Deployed worker docker container for queue: " ${QUEUE}
if [ -z "$CUSTOM_WORKER_IMAGE" ];
then
# If using default image from Step 8
docker-compose -f docker-compose-${ENVIRONMENT}.yml run --name=worker_${QUEUE} -e CHALLENGE_QUEUE=${QUEUE} -e CHALLENGE_PK=${PK} -d worker
else
# If using custom image from worker_image_url
docker run --name=worker_${QUEUE} -e CHALLENGE_QUEUE=${QUEUE} -e CHALLENGE_PK=${PK} -d $CUSTOM_WORKER_IMAGE
fi

# Step 10: Setting up crontab
echo "Step 10/10: Setting up crontab"
Expand Down

0 comments on commit 40e1f37

Please sign in to comment.