From 9766e3b13b63fbaa6350580d74c505f7c64d805d Mon Sep 17 00:00:00 2001 From: Howard Butler Date: Tue, 25 Jun 2024 10:21:48 -0500 Subject: [PATCH] emit container and use for run-local and test-local --- docker/run-local.sh | 34 ++++------------------------------ docker/test-local.sh | 13 +++++++++++++ docker/test-remote.sh | 11 +++++++++++ terraform/main.tf | 5 +++++ terraform/resources/ecr.tf | 4 ++++ 5 files changed, 37 insertions(+), 30 deletions(-) diff --git a/docker/run-local.sh b/docker/run-local.sh index 3713752..256ce7f 100755 --- a/docker/run-local.sh +++ b/docker/run-local.sh @@ -5,30 +5,7 @@ entrypoint="$1" command="$2" - -PREFIX=$(cat ../terraform/terraform.tfstate | jq '.outputs.environment.value // empty' -r) -STAGE=$(cat ../terraform/terraform.tfstate | jq '.outputs.stage.value // empty' -r) -ARCH=$(cat ../terraform/terraform.tfstate | jq '.outputs.arch.value // empty' -r) - -if [ -z "$STAGE" ] -then - echo "STAGE must be set!" - exit 1; -fi - -if [ -z "$PREFIX" ] -then - echo "PREFIX must be set!" - exit 1; -fi - -if [ -z "$ARCH" ] -then - echo "ARCH must be set!" - exit 1; -fi - -CONTAINER="$PREFIX-$STAGE-pdal_runner" +CONTAINER=$(cat ../terraform/terraform.tfstate | jq '.outputs.container.value // empty' -r) REGION=$AWS_DEFAULT_REGION if [ -z "$REGION" ] @@ -40,13 +17,11 @@ fi LOCALPORT=9000 REMOTEPORT=8080 -identity=$(aws sts get-caller-identity --query 'Account' --output text) - KEY_ID=$(aws --profile $AWS_DEFAULT_PROFILE configure get aws_access_key_id) SECRET_ID=$(aws --profile $AWS_DEFAULT_PROFILE configure get aws_secret_access_key) -echo "running $identity.dkr.ecr.$region.amazonaws.com/$container:$ARCH" +echo "Starting container $CONTAINER" if [ -z "$entrypoint" ] then @@ -55,7 +30,7 @@ then -e AWS_DEFAULT_REGION=$REGION \ -e AWS_ACCESS_KEY_ID=${KEY_ID} \ -e AWS_SECRET_ACCESS_KEY=${SECRET_ID} \ - $identity.dkr.ecr.$REGION.amazonaws.com/$CONTAINER:$ARCH "$command" + $CONTAINER "$command" else echo "executing with $entrypoint and command '$command'" docker run -p $LOCALPORT:$REMOTEPORT \ @@ -65,7 +40,6 @@ else -t -i \ -v $(pwd):/data \ --entrypoint=$entrypoint \ - $identity.dkr.ecr.$REGION.amazonaws.com/$CONTAINER:$ARCH \ - "$command" + $CONTAINER "$command" fi diff --git a/docker/test-local.sh b/docker/test-local.sh index b5a557e..c1b31e0 100755 --- a/docker/test-local.sh +++ b/docker/test-local.sh @@ -2,6 +2,19 @@ eventfilename=$1 +if [ -z "$AWS_ACCESS_KEY_ID" ] +then + echo "AWS_ACCESS_KEY_ID must be set in environment!" + exit 1; +fi + +if [ -z "$AWS_SECRET_ACCESS_KEY" ] +then + echo "AWS_SECRET_ACCESS_KEY must be set in environment!" + exit 1; +fi + + event=$(<$eventfilename) echo $event curl -POST -v "http://localhost:9000/2015-03-31/functions/function/invocations" -d @$eventfilename diff --git a/docker/test-remote.sh b/docker/test-remote.sh index d74488b..751c7fd 100755 --- a/docker/test-remote.sh +++ b/docker/test-remote.sh @@ -4,6 +4,17 @@ eventfilename=$1 FUNCTION_NAME=$(cat ../terraform/terraform.tfstate | jq '.outputs.info_lambda_name.value // empty' -r) +if [ -z "$AWS_ACCESS_KEY_ID" ] +then + echo "AWS_ACCESS_KEY_ID must be set in environment!" + exit 1; +fi + +if [ -z "$AWS_SECRET_ACCESS_KEY" ] +then + echo "AWS_SECRET_ACCESS_KEY must be set in environment!" + exit 1; +fi aws lambda invoke \ --function-name "$FUNCTION_NAME" \ diff --git a/terraform/main.tf b/terraform/main.tf index d8ce910..9b792ed 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -52,3 +52,8 @@ output "bucket" { description = "Storage bucket" value = module.resources.bucket } + +output "container" { + description = "Container ARN" + value = module.resources.container +} diff --git a/terraform/resources/ecr.tf b/terraform/resources/ecr.tf index cfa57ab..1003c5d 100644 --- a/terraform/resources/ecr.tf +++ b/terraform/resources/ecr.tf @@ -47,3 +47,7 @@ data aws_ecr_image runner_image { image_tag = var.arch depends_on = [ null_resource.ecr_image, aws_ecr_repository.runner_ecr_repo ] } + +output "container" { + value = "${aws_ecr_repository.runner_ecr_repo.repository_url}:${var.arch}" +} \ No newline at end of file