()
Server endpoint for requests to pull and then start containers.
Server endpoint for requests to pull and then start containers.
Server endpoint for requests to pull and then start containers .
def start_container():
    """Server endpoint for requests to pull and then start containers."""
    game_manager_url = os.getenv("PLAYGROUND_GAME_MANAGER_SERVER") + ":8000"

    try:
        incoming = request.get_json()

        # The battle's unique identifier, my url (server:port), and the docker
        # image. I'm going to send these back when I report we're good to go.
        agent_id = incoming["agent_id"]
        battle_info = incoming["battle_info"]
        docker_image = incoming["docker_image"]
        url = incoming["url"]

        client = docker.from_env()
        client.login(
            os.getenv("PLAYGROUND_DOCKER_LOGIN"),
            os.getenv("PLAYGROUND_DOCKER_PASSWORD"))
        logging.warn("Pulling the image %s..." % docker_image)
        img = client.images.pull(docker_image, tag="latest")

        if img:
            request_url = game_manager_url + "/container_is_ready"
            request_json = {
                'aid': incoming['aid'],
                'battle_info': battle_info,
                'docker_image': docker_image,
                'agent_id': agent_id
            }
            requests.post(request_url, json=request_json)
        else:
            pass
    except Exception as e:
        print("Failed to pull container: %s" % e)
def start_container ( ) : game_manager_url = os . getenv ( "PLAYGROUND_GAME_MANAGER_SERVER" ) + ":8000" try : incoming = request . get_json ( ) # The battle's unique identifier, my url (server:port), and the docker # image. I'm going to send these back when I report we're good to go. agent_id = incoming [ "agent_id" ] battle_info = incoming [ "battle_info" ] docker_image = incoming [ "docker_image" ] url = incoming [ "url" ] client = docker . from_env ( ) client . login ( os . getenv ( "PLAYGROUND_DOCKER_LOGIN" ) , os . getenv ( "PLAYGROUND_DOCKER_PASSWORD" ) ) logging . warn ( "Pulling the image %s..." % docker_image ) img = client . images . pull ( docker_image , tag = "latest" ) if img : request_url = game_manager_url + "/container_is_ready" request_json = { 'aid' : incoming [ 'aid' ] , 'battle_info' : battle_info , 'docker_image' : docker_image , 'agent_id' : agent_id } requests . post ( request_url , json = request_json ) else : pass except Exception as e : print ( "Failed to pull container: %s" % e )