-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from AllenInstitute/feature/asset-and-sfn-changes
Base changes, updates to Core stacks, Sfn SM utils
- Loading branch information
Showing
19 changed files
with
1,021 additions
and
455 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,6 +165,7 @@ def create_py_code_asset( | |
cls, | ||
path: Path, | ||
context_path: Optional[Path], | ||
requirements_file: Optional[Path] = None, | ||
includes: Optional[Sequence[str]] = None, | ||
excludes: Optional[Sequence[str]] = None, | ||
runtime: lambda_.Runtime = lambda_.Runtime.PYTHON_3_11, | ||
|
@@ -219,7 +220,7 @@ def create_py_code_asset( | |
"ssh -vT [email protected] || true", | ||
# Must make sure that the package is not installing using --editable mode | ||
"python3 -m pip install --upgrade pip --no-cache", | ||
"pip3 install . --no-cache -t /asset-output", | ||
f"pip3 install {'-r ' + requirements_file.as_posix() if requirements_file else '.'} --no-cache -t /asset-output", | ||
# TODO: remove botocore and boto3 from asset output | ||
# Must make asset output permissions accessible to lambda | ||
"find /asset-output -type d -print0 | xargs -0 chmod 755", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,13 @@ | |
from aibs_informatics_core.env import EnvBase | ||
from aibs_informatics_core.utils.decorators import cached_property | ||
from aibs_informatics_core.utils.hashing import generate_path_hash | ||
from aws_cdk import aws_ecr_assets | ||
from aws_cdk import aws_lambda as lambda_ | ||
from aws_cdk import aws_s3_assets | ||
|
||
from aibs_informatics_cdk_lib.common.git import clone_repo, is_local_repo | ||
from aibs_informatics_cdk_lib.constructs_.assets.code_asset import ( | ||
GLOBAL_GLOB_EXCLUDES, | ||
PYTHON_GLOB_EXCLUDES, | ||
PYTHON_REGEX_EXCLUDES, | ||
CodeAsset, | ||
|
@@ -24,6 +26,36 @@ | |
logger = logging.getLogger(__name__) | ||
|
||
|
||
class AssetsMixin: | ||
@classmethod | ||
def resolve_repo_path(cls, repo_url: str, repo_path_env_var: Optional[str]) -> Path: | ||
"""Resolves the repo path from the environment or clones the repo from the url | ||
This method is useful to quickly swapping between locally modified changes and the remote repo. | ||
This should typically be used in the context of defining a code asset for a static name | ||
(e.g. AIBS_INFORMATICS_AWS_LAMBDA). You can then use the env var option to point to a local | ||
repo path for development. | ||
Args: | ||
repo_url (str): The git repo url. This is required. | ||
If the repo path is not in the environment, the repo will be cloned from this url. | ||
repo_path_env_var (Optional[str]): The environment variable that contains the repo path. | ||
This is optional. This is useful for local development. | ||
Returns: | ||
Path: The path to the repo | ||
""" | ||
if repo_path_env_var and (repo_path := os.getenv(repo_path_env_var)) is not None: | ||
logger.info(f"Using {repo_path_env_var} from environment") | ||
if not is_local_repo(repo_path): | ||
raise ValueError(f"Env variable {repo_path_env_var} is not a valid git repo") | ||
repo_path = Path(repo_path) | ||
else: | ||
repo_path = clone_repo(repo_url, skip_if_exists=True) | ||
return repo_path | ||
|
||
|
||
class AIBSInformaticsCodeAssets(constructs.Construct): | ||
def __init__( | ||
self, | ||
|
@@ -92,7 +124,7 @@ def AIBS_INFORMATICS_AWS_LAMBDA(self) -> CodeAsset: | |
"ssh -vT [email protected] || true", | ||
# Must make sure that the package is not installing using --editable mode | ||
"python3 -m pip install --upgrade pip --no-cache", | ||
"pip3 install --no-cache -r requirements-lambda.txt -t /asset-output", | ||
"pip3 install . --no-cache -t /asset-output", | ||
# TODO: remove botocore and boto3 from asset output | ||
# Must make asset output permissions accessible to lambda | ||
"find /asset-output -type d -print0 | xargs -0 chmod 755", | ||
|
@@ -117,3 +149,38 @@ def AIBS_INFORMATICS_AWS_LAMBDA(self) -> CodeAsset: | |
self.env_base.ENV_BASE_KEY: self.env_base, | ||
}, | ||
) | ||
|
||
|
||
class AIBSInformaticsDockerAssets(constructs.Construct, AssetsMixin): | ||
def __init__( | ||
self, | ||
scope: constructs.Construct, | ||
construct_id: str, | ||
env_base: EnvBase, | ||
) -> None: | ||
super().__init__(scope, construct_id) | ||
self.env_base = env_base | ||
|
||
@cached_property | ||
def AIBS_INFORMATICS_AWS_LAMBDA(self) -> aws_ecr_assets.DockerImageAsset: | ||
"""Returns a NEW docker asset for aibs-informatics-aws-lambda | ||
Returns: | ||
aws_ecr_assets.DockerImageAsset: The docker asset | ||
""" | ||
repo_path = self.resolve_repo_path( | ||
AIBS_INFORMATICS_AWS_LAMBDA_REPO, AIBS_INFORMATICS_AWS_LAMBDA_REPO_ENV_VAR | ||
) | ||
return aws_ecr_assets.DockerImageAsset( | ||
self, | ||
"aibs-informatics-aws-lambda", | ||
directory=repo_path.as_posix(), | ||
build_ssh="default", | ||
platform=aws_ecr_assets.Platform.LINUX_AMD64, | ||
asset_name="aibs-informatics-aws-lambda", | ||
file="docker/Dockerfile", | ||
exclude=[ | ||
*PYTHON_GLOB_EXCLUDES, | ||
*GLOBAL_GLOB_EXCLUDES, | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.