Skip to content
Draft
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion cellpack/autopack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,17 @@ def read_text_file(filename, destination="", cache="collisionTrees", force=None)


def load_file(
filename, destination="", cache="geometries", force=None, use_docker=False
filename,
destination="",
cache="geometries",
force=None,
use_docker=False,
json_recipe=None,
):
if json_recipe is not None:
composition = DBRecipeLoader.remove_empty(json_recipe.get("composition", {}))
json_recipe["composition"] = composition
return json_recipe, None, False
if is_remote_path(filename):
database_name, file_path = convert_db_shortname_to_url(filename)
if database_name == DATABASE_IDS.GITHUB:
Expand Down
14 changes: 12 additions & 2 deletions cellpack/autopack/loaders/recipe_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,21 @@ class RecipeLoader(object):
# TODO: add all default values here
default_values = default_recipe_values.copy()

def __init__(self, input_file_path, save_converted_recipe=False, use_docker=False):
def __init__(
self,
input_file_path,
save_converted_recipe=False,
use_docker=False,
json_recipe=None,
):
_, file_extension = os.path.splitext(input_file_path)
self.current_version = CURRENT_VERSION
self.file_path = input_file_path
self.file_extension = file_extension
self.ingredient_list = []
self.compartment_list = []
self.save_converted_recipe = save_converted_recipe
self.json_recipe = json_recipe

# set CURRENT_RECIPE_PATH appropriately for remote(firebase) vs local recipes
if autopack.is_remote_path(self.file_path):
Expand Down Expand Up @@ -169,7 +176,10 @@ def _migrate_version(self, old_recipe):

def _read(self, resolve_inheritance=True, use_docker=False):
new_values, database_name, is_unnested_firebase = autopack.load_file(
self.file_path, cache="recipes", use_docker=use_docker
self.file_path,
cache="recipes",
use_docker=use_docker,
json_recipe=self.json_recipe,
)
if database_name == "firebase":
if is_unnested_firebase:
Expand Down
9 changes: 7 additions & 2 deletions cellpack/bin/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@


def pack(
recipe, config_path=None, analysis_config_path=None, docker=False, validate=True
recipe,
config_path=None,
analysis_config_path=None,
docker=False,
validate=True,
json_recipe=None,
):
"""
Initializes an autopack packing from the command line
Expand All @@ -40,7 +45,7 @@ def pack(
packing_config_data = ConfigLoader(config_path, docker).config

recipe_loader = RecipeLoader(
recipe, packing_config_data["save_converted_recipe"], docker
recipe, packing_config_data["save_converted_recipe"], docker, json_recipe
)
recipe_data = recipe_loader.recipe_data
analysis_config_data = {}
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.ecs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WORKDIR /cellpack
COPY . /cellpack

RUN python -m pip install --upgrade pip --root-user-action=ignore
RUN python -m pip install . -r requirements/linux/requirements.txt --root-user-action=ignore
RUN python -m pip install . --root-user-action=ignore

EXPOSE 80

Expand Down
14 changes: 9 additions & 5 deletions docker/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class CellpackServer:
def __init__(self):
self.packing_tasks = set()

async def run_packing(self, recipe, config, job_id):
async def run_packing(self, recipe, config, job_id, body=None):
os.environ["AWS_BATCH_JOB_ID"] = job_id
self.update_job_status(job_id, "RUNNING")
try:
pack(recipe=recipe, config_path=config, docker=True)
pack(recipe=recipe, config_path=config, docker=True, json_recipe=body)
except Exception as e:
self.update_job_status(job_id, "FAILED", error_message=str(e))

Expand All @@ -37,16 +37,20 @@ async def health_check(self, request: web.Request) -> web.Response:
return web.Response()

async def pack_handler(self, request: web.Request) -> web.Response:
recipe = request.rel_url.query.get("recipe")
if recipe is None:
recipe = request.rel_url.query.get("recipe") or ""
if request.can_read_body:
body = await request.json()
else:
body = None
if not recipe and not body:
raise web.HTTPBadRequest(
"Pack requests must include recipe as a query param"
)
config = request.rel_url.query.get("config")
job_id = str(uuid.uuid4())

# Initiate packing task to run in background
packing_task = asyncio.create_task(self.run_packing(recipe, config, job_id))
packing_task = asyncio.create_task(self.run_packing(recipe, config, job_id, body))

# Keep track of task references to prevent them from being garbage
# collected, then discard after task completion
Expand Down
4 changes: 2 additions & 2 deletions docs/DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
## AWS ECS Docker Image
1. Build image, running `docker build -f docker/Dockerfile.ecs -t [CONTAINER-NAME] .`
2. Run packings in the container, running: `docker run -v ~/.aws:/root/.aws -p 80:80 [CONTAINER-NAME]`
3. Try hitting the test endpoint on the server, by navigating to `http://0.0.0.0:8443/hello` in your browser.
4. Try running a packing on the server, by hitting the `http://0.0.0.0:80/pack?recipe=firebase:recipes/one_sphere_v_1.0.0` in your browser.
3. Try hitting the test endpoint on the server, by navigating to `http://0.0.0.0:80/hello` in your browser.
4. Try running a packing on the server, by hitting the `http://0.0.0.0:80/start-packing?recipe=firebase:recipes/one_sphere_v_1.0.0` in your browser.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These instructions were just slightly incorrect, this has nothing to do with the other code changes, I just ran into it when testing my code and I wanted to fix it

5. Verify that the packing result path was uploaded to the firebase results table, with the job id specified in the response from the request in step 4.The result simularium file can be found at the s3 path specified there.