Skip to content

Commit

Permalink
Merge pull request #585 from awslabs/chore/583
Browse files Browse the repository at this point in the history
chore: Make `jupyter-hub` module generic and update deps
  • Loading branch information
malachi-constant committed Sep 4, 2024
2 parents feee5ad + e530b6e commit 40f4f1b
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 28 deletions.
10 changes: 6 additions & 4 deletions modules/demo-only/jupyter-hub/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
account = os.environ["CDK_DEFAULT_ACCOUNT"]
region = os.environ["CDK_DEFAULT_REGION"]

deployment_name = os.getenv("ADDF_DEPLOYMENT_NAME", "")
module_name = os.getenv("ADDF_MODULE_NAME", "")
project_name = os.getenv("SEEDFARMER_PROJECT_NAME", "")
deployment_name = os.getenv("SEEDFARMER_DEPLOYMENT_NAME", "")
module_name = os.getenv("SEEDFARMER_MODULE_NAME", "")


def _param(name: str) -> str:
return f"ADDF_PARAMETER_{name}"
return f"SEEDFARMER_PARAMETER_{name}"


eks_cluster_name = os.getenv(_param("EKS_CLUSTER_NAME"), "")
Expand All @@ -39,11 +40,12 @@ def _param(name: str) -> str:

stack = JupyterHubStack(
scope=app,
id=f"addf-{deployment_name}-{module_name}",
id=f"{project_name}-{deployment_name}-{module_name}",
env=aws_cdk.Environment(
account=account,
region=region,
),
project=project_name,
deployment=deployment_name,
module=module_name,
eks_cluster_name=eks_cluster_name,
Expand Down
13 changes: 7 additions & 6 deletions modules/demo-only/jupyter-hub/deployspec.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
publishGenericEnvVariables: true
deploy:
phases:
install:
commands:
- npm install -g aws-cdk@2.20.0
- npm install -g aws-cdk@2.155.0
- pip install -r requirements.txt
build:
commands:
- export ECR_REPO_NAME="addf-${ADDF_DEPLOYMENT_NAME}-${ADDF_MODULE_NAME}"
- export ECR_REPO_NAME="addf-${SEEDFARMER_DEPLOYMENT_NAME}-${SEEDFARMER_MODULE_NAME}"
- export COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- export IMAGE_TAG=${COMMIT_HASH:=latest}
- export REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$ECR_REPO_NAME
- export ADDF_PARAMETER_JH_IMAGE_NAME=$REPOSITORY_URI
- export ADDF_PARAMETER_JH_IMAGE_TAG=$IMAGE_TAG
- export SEEDFARMER_PARAMETER_JH_IMAGE_NAME=$REPOSITORY_URI
- export SEEDFARMER_PARAMETER_JH_IMAGE_TAG=$IMAGE_TAG
- aws ecr describe-repositories --repository-names ${ECR_REPO_NAME} || aws ecr create-repository --repository-name ${ECR_REPO_NAME}
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
- echo Building the Docker image...
Expand All @@ -20,12 +21,12 @@ deploy:
- docker push $REPOSITORY_URI:latest && docker push $REPOSITORY_URI:$IMAGE_TAG
- cd ..
- cdk deploy --require-approval never --progress events --app "python app.py" --outputs-file ./cdk-exports.json
- export ADDF_MODULE_METADATA=$(python -c "import json; file=open('cdk-exports.json'); print(json.load(file)['addf-${ADDF_DEPLOYMENT_NAME}-${ADDF_MODULE_NAME}']['metadata'])")
- export SEEDFARMER_MODULE_METADATA=$(python -c "import json; file=open('cdk-exports.json'); print(json.load(file)['addf-${SEEDFARMER_DEPLOYMENT_NAME}-${SEEDFARMER_MODULE_NAME}']['metadata'])")
destroy:
phases:
install:
commands:
- npm install -g aws-cdk@2.20.0
- npm install -g aws-cdk@2.155.0
- pip install -r requirements.txt
build:
commands:
Expand Down
7 changes: 5 additions & 2 deletions modules/demo-only/jupyter-hub/modulestack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ AWSTemplateFormatVersion: 2010-09-09
Description: This stack deploys a Module specific IAM permissions

Parameters:
ProjectName:
Type: String
Description: The name of the project
DeploymentName:
Type: String
Description: The name of the deployment
Expand Down Expand Up @@ -35,7 +38,7 @@ Resources:
Action:
- ecr:*
Resource:
- !Sub "arn:aws:ecr:${AWS::Region}:${AWS::AccountId}:repository/addf-${DeploymentName}-${ModuleName}*"
- !Sub "arn:aws:ecr:${AWS::Region}:${AWS::AccountId}:repository/${ProjectName}-${DeploymentName}-${ModuleName}*"
Version: 2012-10-17
PolicyName: addf-modulespecific-policy
PolicyName: modulespecific-policy
Roles: [!Ref RoleName]
2 changes: 1 addition & 1 deletion modules/demo-only/jupyter-hub/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ omit = ["tests/*"]
python_version = 3.8
strict = true
ignore_missing_imports = true
allow_untyped_decorators = true
disallow_untyped_decorators = false
exclude = "codeseeder.out/|example/|tests/"

[tool.pytest.ini_options]
Expand Down
6 changes: 3 additions & 3 deletions modules/demo-only/jupyter-hub/requirements.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
aws-cdk-lib==2.20.0
aws-cdk-lib~=2.155.0
cdk-nag==2.12.29
constructs==10.0.91
boto3~=1.24.0
constructs~=10.0.91
boto3~=1.33.0
urllib3>=1.26.19
38 changes: 30 additions & 8 deletions modules/demo-only/jupyter-hub/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --output-file=requirements.txt requirements.in
# pip-compile requirements.in
#
attrs==23.2.0
# via
# cattrs
# jsii
aws-cdk-lib==2.20.0
aws-cdk-asset-awscli-v1==2.2.202
# via aws-cdk-lib
aws-cdk-asset-kubectl-v20==2.1.2
# via aws-cdk-lib
aws-cdk-asset-node-proxy-agent-v6==2.1.0
# via aws-cdk-lib
aws-cdk-cloud-assembly-schema==36.0.24
# via aws-cdk-lib
aws-cdk-lib==2.155.0
# via
# -r requirements.in
# cdk-nag
boto3==1.24.96
boto3==1.33.13
# via -r requirements.in
botocore==1.27.96
botocore==1.33.13
# via
# boto3
# s3transfer
Expand All @@ -35,13 +43,21 @@ jmespath==1.0.1
# via
# boto3
# botocore
jsii==1.100.0
jsii==1.103.1
# via
# aws-cdk-asset-awscli-v1
# aws-cdk-asset-kubectl-v20
# aws-cdk-asset-node-proxy-agent-v6
# aws-cdk-cloud-assembly-schema
# aws-cdk-lib
# cdk-nag
# constructs
publication==0.0.3
# via
# aws-cdk-asset-awscli-v1
# aws-cdk-asset-kubectl-v20
# aws-cdk-asset-node-proxy-agent-v6
# aws-cdk-cloud-assembly-schema
# aws-cdk-lib
# cdk-nag
# constructs
Expand All @@ -50,17 +66,23 @@ python-dateutil==2.9.0.post0
# via
# botocore
# jsii
s3transfer==0.6.2
s3transfer==0.8.2
# via boto3
six==1.16.0
# via python-dateutil
typeguard==2.13.3
# via jsii
# via
# aws-cdk-asset-awscli-v1
# aws-cdk-asset-kubectl-v20
# aws-cdk-asset-node-proxy-agent-v6
# aws-cdk-cloud-assembly-schema
# aws-cdk-lib
# jsii
typing-extensions==4.12.2
# via
# cattrs
# jsii
urllib3==1.26.19
# via
# -r requirements.in
# botocore
# botocore
9 changes: 5 additions & 4 deletions modules/demo-only/jupyter-hub/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(
scope: Construct,
id: str,
*,
project: str,
deployment: str,
module: str,
eks_cluster_name: str,
Expand All @@ -38,12 +39,12 @@ def __init__(
super().__init__(
scope,
id,
description="This stack deploys Self managed JupyterHub environment for ADDF",
description="This stack deploys a Self managed JupyterHub environment",
**kwargs,
)
Tags.of(scope=cast(IConstruct, self)).add(key="Deployment", value=f"addf-{deployment}")
Tags.of(scope=cast(IConstruct, self)).add(key="Deployment", value=f"{project}-{deployment}")

dep_mod = f"addf-{deployment}-{module}"
dep_mod = f"{project}-{deployment}-{module}"

# Import EKS Cluster
provider = eks.OpenIdConnectProvider.from_open_id_connect_provider_arn(
Expand Down Expand Up @@ -145,7 +146,7 @@ def __init__(
},
{ # type: ignore
"id": "AwsSolutions-IAM5",
"reason": "Resource access restriced to ADDF resources",
"reason": "Resource access restriced to explicit resources",
},
],
)

0 comments on commit 40f4f1b

Please sign in to comment.