-
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 branch 'main' into feat/srm-runs-detail-and-librarylinking
- Loading branch information
Showing
12 changed files
with
216 additions
and
51 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 was deleted.
Oops, something went wrong.
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
34 changes: 34 additions & 0 deletions
34
...d/stateless/stacks/metadata-manager/app/management/commands/clean_duplicated_libraries.py
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import json | ||
|
||
from django.core.management import BaseCommand | ||
|
||
from django.db.models import Q | ||
|
||
from app.models import Library | ||
|
||
|
||
# https://docs.djangoproject.com/en/5.0/howto/custom-management-commands/ | ||
class Command(BaseCommand): | ||
help = "Delete all DB data" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
"--dry-run", | ||
action="store_true", | ||
help="List all libraries that will be deleted without actually deleting them", | ||
) | ||
|
||
def handle(self, *args, **options): | ||
all_libraries = Library.objects.all().filter( | ||
Q(library_id__icontains="_rerun") | Q(library_id__icontains="_topup")) | ||
|
||
print("Libraries contain matching pattern:") | ||
print(json.dumps([library.library_id for library in all_libraries], indent=4)) | ||
|
||
if not options["dry_run"]: | ||
print("Deleting all libraries") | ||
all_libraries.delete() | ||
else: | ||
print("Dry run: not deleting libraries") | ||
|
||
print('Completed') |
46 changes: 46 additions & 0 deletions
46
...orkload/stateless/stacks/metadata-manager/deploy/construct/lambda-django-command/index.ts
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import path from 'path'; | ||
import { Construct } from 'constructs'; | ||
import { Duration } from 'aws-cdk-lib'; | ||
import { PythonFunction } from '@aws-cdk/aws-lambda-python-alpha'; | ||
import { ISecret } from 'aws-cdk-lib/aws-secretsmanager'; | ||
import { | ||
DockerImageFunction, | ||
DockerImageFunctionProps, | ||
DockerImageCode, | ||
} from 'aws-cdk-lib/aws-lambda'; | ||
|
||
type LambdaProps = { | ||
/** | ||
* The basic common lambda properties that it should inherit from | ||
*/ | ||
basicLambdaConfig: Partial<DockerImageFunctionProps>; | ||
/** | ||
* The secret for the db connection where the lambda will need access to | ||
*/ | ||
dbConnectionSecret: ISecret; | ||
}; | ||
|
||
export class LambdaDjangoCommandConstruct extends Construct { | ||
readonly lambda: PythonFunction; | ||
|
||
constructor(scope: Construct, id: string, lambdaProps: LambdaProps) { | ||
super(scope, id); | ||
|
||
this.lambda = new DockerImageFunction(this, 'DjangoCommandLambda', { | ||
environment: { | ||
...lambdaProps.basicLambdaConfig.environment, | ||
}, | ||
securityGroups: lambdaProps.basicLambdaConfig.securityGroups, | ||
vpc: lambdaProps.basicLambdaConfig.vpc, | ||
vpcSubnets: lambdaProps.basicLambdaConfig.vpcSubnets, | ||
architecture: lambdaProps.basicLambdaConfig.architecture, | ||
code: DockerImageCode.fromImageAsset(path.join(__dirname, '../../../'), { | ||
file: 'deploy/construct/lambda-django-command/lambda.Dockerfile', | ||
}), | ||
timeout: Duration.minutes(15), | ||
memorySize: 4096, | ||
}); | ||
|
||
lambdaProps.dbConnectionSecret.grantRead(this.lambda); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...tateless/stacks/metadata-manager/deploy/construct/lambda-django-command/lambda.Dockerfile
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM public.ecr.aws/lambda/python:3.12 | ||
|
||
WORKDIR ${LAMBDA_TASK_ROOT} | ||
|
||
# COPY all files | ||
COPY . . | ||
|
||
# Install the specified packages | ||
RUN pip install -r deps/requirements-full.txt | ||
|
||
# Specify handler | ||
CMD [ "handler.django_command.handler" ] |
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
28 changes: 28 additions & 0 deletions
28
lib/workload/stateless/stacks/metadata-manager/handler/django_command.py
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# -*- coding: utf-8 -*- | ||
"""migrate lambda module | ||
Convenience AWS lambda handler for Django database migration command hook | ||
""" | ||
import json | ||
import logging | ||
from django.core.management import execute_from_command_line | ||
|
||
logger = logging.getLogger() | ||
logger.setLevel(logging.INFO) | ||
|
||
|
||
def handler(event, context) -> dict[str, str]: | ||
logger.info(f"Processing event: {json.dumps(event, indent=4)}") | ||
|
||
command = event.get("command", None) | ||
args = event.get("args", []) | ||
|
||
whitelist_command = ["clean_duplicated_libraries"] | ||
|
||
if command not in whitelist_command: | ||
raise ValueError(f"Command {command} not accepted") | ||
|
||
|
||
res = execute_from_command_line(["./manage.py", command, *args]) | ||
|
||
return res |
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.