-
Notifications
You must be signed in to change notification settings - Fork 7
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 #62 from ghrcdaac/mlh0079-6188-6025-besd-lambda
Mlh0079 6188 6025 besd lambda
- Loading branch information
Showing
14 changed files
with
249 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,41 @@ | ||
FROM opendap/besd:3.21.0-272 | ||
FROM opendap/besd:3.21.0-272 AS base | ||
HEALTHCHECK NONE | ||
|
||
RUN yum -y update && \ | ||
yum -y upgrade | ||
HEALTHCHECK NONE | ||
|
||
RUN yum install -y nano && \ | ||
yum install -y wget | ||
# Adding a user | ||
RUN adduser worker | ||
USER worker | ||
WORKDIR /home/worker | ||
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-py310_23.10.0-1-Linux-x86_64.sh && \ | ||
bash Miniconda3-py310_23.10.0-1-Linux-x86_64.sh -b && \ | ||
rm Miniconda3-py310_23.10.0-1-Linux-x86_64.sh | ||
ENV HOME="/home/worker" PATH="/home/worker/miniconda3/bin:${PATH}" | ||
RUN pip install ipython &&\ | ||
pip install pytest &&\ | ||
|
||
ARG HOME='/home/worker' | ||
WORKDIR ${HOME} | ||
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-py310_23.10.0-1-Linux-x86_64.sh -O miniconda.sh && \ | ||
bash miniconda.sh -b -p ${HOME}/miniconda && \ | ||
rm miniconda.sh | ||
|
||
ENV PATH="${HOME}/miniconda/bin:${PATH}" | ||
ARG BUILD=${HOME}/build | ||
WORKDIR ${BUILD} | ||
|
||
RUN pip install ipython && \ | ||
pip install pytest && \ | ||
pip install coverage | ||
RUN mkdir $HOME/build | ||
ENV BUILD=$HOME/build | ||
COPY --chown=worker setup.py requirements*txt $BUILD/ | ||
RUN pip install -r $BUILD/requirements.txt | ||
COPY --chown=worker dmrpp_generator $BUILD/dmrpp_generator | ||
COPY --chown=worker generate_dmrpp.py $BUILD/generate_dmrpp.py | ||
COPY --chown=worker tests $BUILD/tests | ||
RUN \ | ||
cd $BUILD; \ | ||
python setup.py install | ||
WORKDIR $BUILD | ||
RUN coverage run -m pytest | ||
RUN coverage report | ||
RUN coverage lcov -o ./coverage/lcov.info | ||
RUN rm -rf tests .coverage .pytest_cache | ||
|
||
COPY setup.py requirements*txt generate_dmrpp.py ./ | ||
COPY dmrpp_generator ./dmrpp_generator/ | ||
COPY tests ./tests/ | ||
RUN pip install -r requirements.txt && \ | ||
python setup.py install | ||
|
||
RUN coverage run -m pytest && \ | ||
coverage report && \ | ||
coverage lcov -o ./coverage/lcov.info && \ | ||
rm -rf tests .coverage .pytest_cache && \ | ||
pip uninstall pytest -y && \ | ||
pip uninstall coverage -y | ||
|
||
RUN pip install --target $BUILD awslambdaric | ||
COPY site.conf /etc/bes/ | ||
|
||
CMD ["python", "generate_dmrpp.py"] | ||
ENTRYPOINT [] |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from run_cumulus_task import run_cumulus_task | ||
|
||
from dmrpp_generator.main import main | ||
|
||
|
||
def handler(event, context): | ||
# print(f'CMA Event: {event}') | ||
if 'cma' in event: | ||
print(f'Running cumulus task...') | ||
ret = run_cumulus_task(main, event, context) | ||
else: | ||
print(f'Calling main()...') | ||
ret = main(event, context) | ||
|
||
return ret |
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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "v4.4.1" | ||
__version__ = "v5.0.0" |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
locals { | ||
image_version = regex("v\\d+.\\d+.\\d+", var.docker_image) | ||
deploy_lambda = length(var.cumulus_lambda_role_arn) > 0 ? true : false | ||
} | ||
|
||
resource "aws_lambda_function" "ghrc_dmrpp" { | ||
count = local.deploy_lambda ? 1 : 0 | ||
depends_on = [terraform_data.build_image, aws_ecr_repository.ghrc_dmrpp_lambda] | ||
|
||
function_name = "${var.prefix}-ghrc-dmrpp" | ||
package_type = "Image" | ||
image_uri = "${aws_ecr_repository.ghrc_dmrpp_lambda[0].repository_url}:${local.image_version}" | ||
role = var.cumulus_lambda_role_arn | ||
timeout = var.timeout | ||
memory_size = var.memory_size | ||
|
||
image_config { | ||
entry_point = ["/home/worker/miniconda/bin/python", "-m", "awslambdaric"] | ||
command = ["dmrpp_generator.lambda_handler.handler"] | ||
} | ||
|
||
ephemeral_storage { | ||
size = var.ephemeral_storage | ||
} | ||
|
||
environment { | ||
variables = { | ||
region = var.region | ||
ENABLE_CW_LOGGING = var.enable_cw_logging | ||
GET_DMRPP_TIMEOUT = var.get_dmrpp_timeout | ||
} | ||
} | ||
} | ||
|
||
resource "aws_ecr_repository" "ghrc_dmrpp_lambda" { | ||
count = local.deploy_lambda ? 1 : 0 | ||
name = "${var.prefix}_ghrc_dmrpp_lambda" | ||
image_tag_mutability = "MUTABLE" | ||
force_delete = true | ||
|
||
image_scanning_configuration { | ||
scan_on_push = true | ||
} | ||
} | ||
|
||
resource "terraform_data" "build_image" { | ||
count = local.deploy_lambda ? 1 : 0 | ||
depends_on = [aws_ecr_repository.ghrc_dmrpp_lambda] | ||
triggers_replace = [var.docker_image] | ||
|
||
provisioner "local-exec" { | ||
command = <<-EOT | ||
docker pull ${var.docker_image} | ||
aws ecr get-login-password --region ${var.region} | docker login --username AWS --password-stdin ${var.account_id}.dkr.ecr.${var.region}.amazonaws.com | ||
docker tag ${var.docker_image} ${aws_ecr_repository.ghrc_dmrpp_lambda[0].repository_url}:${local.image_version} | ||
docker push ${aws_ecr_repository.ghrc_dmrpp_lambda[0].repository_url}:${local.image_version} | ||
EOT | ||
} | ||
} |
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,3 @@ | ||
output "dmrpp_lambda_arn" { | ||
value = join("", aws_lambda_function.ghrc_dmrpp.*.arn) | ||
} |
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,51 @@ | ||
variable "region" { | ||
type = string | ||
default = "us-west-2" | ||
} | ||
|
||
variable "account_id" { | ||
type = string | ||
} | ||
|
||
variable "prefix" { | ||
type = string | ||
description = "Cumulus stack prefix" | ||
} | ||
|
||
variable "cumulus_lambda_role_arn" { | ||
type = string | ||
nullable = true | ||
} | ||
|
||
variable "timeout" { | ||
description = "Lambda function time-out" | ||
default = 900 | ||
} | ||
|
||
variable "memory_size" { | ||
description = "Lambda RAM limit" | ||
default = 256 | ||
} | ||
|
||
variable "ephemeral_storage" { | ||
description = "Lambda /tmp storage limit" | ||
default = 512 | ||
} | ||
|
||
variable "enable_cw_logging" { | ||
description = "Enable logging to cloud watch" | ||
type = bool | ||
default = true | ||
} | ||
|
||
variable "get_dmrpp_timeout" { | ||
description = "Duration to wait on the get_dmrpp subprocess call." | ||
type = number | ||
default = 60 | ||
} | ||
|
||
variable "docker_image" { | ||
description = "ECR Lambda docker image" | ||
type = string | ||
default = "ghrcdaac/dmrpp-generator:VERSION_SUB" | ||
} |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
output "dmrpp_task_id" { | ||
value = module.dmrpp_service.dmrpp_task_id | ||
} | ||
} | ||
|
||
output "dmrpp_lambda_arn" { | ||
value = module.dmrpp_lambda.dmrpp_lambda_arn | ||
} |
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 @@ | ||
BES.LogName=/tmp/bes.log |
Oops, something went wrong.