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

Feature/pass recipe to docker #285

Merged
merged 10 commits into from
Nov 15, 2024
37 changes: 37 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Distribution / packaging
build/
develop-eggs/
eggs/
.eggs/
*.egg-info/
.installed.cfg
*.egg
__pycache__

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
*.cover
cellpack/tests/
cellpack/bin/tests/

# Documentation
docs/

# virtualenv
.venv
venv/
ENV/

# Generated data
out/
*.simularium
**/converted/*
data/
results/

# git
.github/
4 changes: 2 additions & 2 deletions cellpack/autopack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,13 @@ def read_text_file(filename, destination="", cache="collisionTrees", force=None)
return sphere_data


def load_file(filename, destination="", cache="geometries", force=None):
def load_file(filename, destination="", cache="geometries", force=None, use_docker=False):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we make this argument name more generic? Seeing as this flag decides the database to use, maybe it could be renamed to skip_database_check or something equivalent?

if is_remote_path(filename):
database_name, file_path = convert_db_shortname_to_url(filename)
# command example: `pack -r firebase:recipes/[FIREBASE-RECIPE-ID] -c [CONFIG-FILE-PATH]`
if database_name == "firebase":
db = DATABASE_IDS.handlers().get(database_name)
initialize_db = db()
initialize_db = db(default_db="staging") if use_docker else db()
if not initialize_db._initialized:
readme_url = "https://github.com/mesoscope/cellpack?tab=readme-ov-file#introduction-to-remote-databases"
sys.exit(
Expand Down
8 changes: 4 additions & 4 deletions cellpack/autopack/loaders/recipe_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ 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):
def __init__(self, input_file_path, save_converted_recipe=False, use_docker=False):
_, file_extension = os.path.splitext(input_file_path)
self.current_version = CURRENT_VERSION
self.file_path = input_file_path
Expand All @@ -36,7 +36,7 @@ def __init__(self, input_file_path, save_converted_recipe=False):
self.compartment_list = []
self.save_converted_recipe = save_converted_recipe
autopack.CURRENT_RECIPE_PATH = os.path.dirname(self.file_path)
self.recipe_data = self._read()
self.recipe_data = self._read(use_docker=use_docker)

@staticmethod
def _resolve_object(key, objects):
Expand Down Expand Up @@ -156,8 +156,8 @@ def _migrate_version(self, old_recipe):
f"{old_recipe['format_version']} is not a format version we support"
)

def _read(self, resolve_inheritance=True):
new_values, database_name = autopack.load_file(self.file_path, cache="recipes")
def _read(self, resolve_inheritance=True, use_docker=False):
new_values, database_name = autopack.load_file(self.file_path, cache="recipes", use_docker=use_docker)
if database_name == "firebase":
objects, gradients, composition = DBRecipeLoader.collect_and_sort_data(
new_values["composition"]
Expand Down
5 changes: 3 additions & 2 deletions cellpack/bin/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@
###############################################################################


def pack(recipe, config_path=None, analysis_config_path=None):
def pack(recipe, config_path=None, analysis_config_path=None, docker=False):
"""
Initializes an autopack packing from the command line
:param recipe: string argument, path to recipe
:param config_path: string argument, path to packing config file
:param analysis_config_path: string argument, path to analysis config file
:param docker: boolean argument, are we using docker

:return: void
"""
packing_config_data = ConfigLoader(config_path).config
recipe_data = RecipeLoader(
recipe, packing_config_data["save_converted_recipe"]
recipe, packing_config_data["save_converted_recipe"], docker
).recipe_data
analysis_config_data = {}
if analysis_config_path is not None:
Expand Down
27 changes: 16 additions & 11 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
#!/bin/bash -e

# if [ -z "$recipe" ]; then
# echo "Required recipe parameter is missing, please include recipe in Docker run script, ie: -e r=path/to/recipe"
# exit
# fi

# if [ -z "$config" ]; then
# echo "Required config parameter is missing, please include packing config in Docker run script, ie: -e c=path/to/config"
# exit
# fi
if [ -z "$recipe" ]; then
echo "Required recipe parameter is missing, please include recipe in Docker run script, ie: -e recipe=path/to/recipe"
exit;
else
echo "recipe passed in: '$recipe'"
fi

cd /cellpack
# pack -r ${recipe} -c ${config}
pack -r examples/recipes/v2/one_sphere.json -c examples/packing-configs/run.json

if [ -z "$config" ]; then
echo "Config parameter not included, using default value"
pack -r $recipe -d
exit;
else
echo "config passed in: '$config'"
fi

pack -r $recipe -c $config -d
Loading