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

Added method pull_docker_image in evaluation_script_starter.py #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
48 changes: 48 additions & 0 deletions remote_challenge_evaluation/evaluation_script_starter.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,50 @@ def get_submission_by_pk(self, submission_pk):
response = self.make_request(url, "GET")
return response

def pull_docker_image(self, image_uri, phase_pk):
import base64
import boto3
import docker

# Note: Amazon AWS does not reccomend to hard code credentials in source
# code, so alternatively you can create a credential file as shown in
# https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html#shared-credentials-file
# You will be then able to create the boto3.client without explicitly
# supplying the credentials as they will be automatically retrieved
# from the file.

AWS_ACCESS_KEY_ID = '<insert access key here>'
AWS_SECRET_ACCESS_KEY = '<insert secret access key here>'
AWS_DEFAULT_REGION = 'us-east-1'
AWS_ACCOUNT_ID = '<insert account id here>'

ecr_client = boto3.client(
"ecr",
region_name=AWS_DEFAULT_REGION,
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY
)

token = ecr_client.get_authorization_token(
registryIds=[AWS_ACCOUNT_ID]
)
ecr_client = boto3.client("ecr", region_name=AWS_DEFAULT_REGION)
username, password = (
base64.b64decode(
token["authorizationData"][0]["authorizationToken"]
)
.decode()
.split(":")
)
registry = token["authorizationData"][0]["proxyEndpoint"]
docker_client = docker.from_env()
docker_client.login(
username, password, registry=registry
)

docker_client.login(username, password, registry=registry)
docker_client.images.pull(image_uri)


if __name__ == "__main__":

Expand Down Expand Up @@ -180,6 +224,10 @@ def get_submission_by_pk(self, submission_pk):
else:
# Download the input file
# Run the submission with the input file using your own code and data.
#
# If the submission is a docker image, you can pull the image
# by using evalai.pull_docker_image. This will require installing
# boto3 and docker libraries.
pass

# Poll challenge queue for new submissions
Expand Down