Skip to content

Commit 0ae45e3

Browse files
authored
emit container and use for run-local and test-local (#14)
1 parent 705c51f commit 0ae45e3

File tree

5 files changed

+37
-30
lines changed

5 files changed

+37
-30
lines changed

docker/run-local.sh

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,7 @@
55
entrypoint="$1"
66
command="$2"
77

8-
9-
PREFIX=$(cat ../terraform/terraform.tfstate | jq '.outputs.environment.value // empty' -r)
10-
STAGE=$(cat ../terraform/terraform.tfstate | jq '.outputs.stage.value // empty' -r)
11-
ARCH=$(cat ../terraform/terraform.tfstate | jq '.outputs.arch.value // empty' -r)
12-
13-
if [ -z "$STAGE" ]
14-
then
15-
echo "STAGE must be set!"
16-
exit 1;
17-
fi
18-
19-
if [ -z "$PREFIX" ]
20-
then
21-
echo "PREFIX must be set!"
22-
exit 1;
23-
fi
24-
25-
if [ -z "$ARCH" ]
26-
then
27-
echo "ARCH must be set!"
28-
exit 1;
29-
fi
30-
31-
CONTAINER="$PREFIX-$STAGE-pdal_runner"
8+
CONTAINER=$(cat ../terraform/terraform.tfstate | jq '.outputs.container.value // empty' -r)
329

3310
REGION=$AWS_DEFAULT_REGION
3411
if [ -z "$REGION" ]
@@ -40,13 +17,11 @@ fi
4017
LOCALPORT=9000
4118
REMOTEPORT=8080
4219

43-
identity=$(aws sts get-caller-identity --query 'Account' --output text)
44-
4520
KEY_ID=$(aws --profile $AWS_DEFAULT_PROFILE configure get aws_access_key_id)
4621
SECRET_ID=$(aws --profile $AWS_DEFAULT_PROFILE configure get aws_secret_access_key)
4722

4823

49-
echo "running $identity.dkr.ecr.$region.amazonaws.com/$container:$ARCH"
24+
echo "Starting container $CONTAINER"
5025

5126
if [ -z "$entrypoint" ]
5227
then
@@ -55,7 +30,7 @@ then
5530
-e AWS_DEFAULT_REGION=$REGION \
5631
-e AWS_ACCESS_KEY_ID=${KEY_ID} \
5732
-e AWS_SECRET_ACCESS_KEY=${SECRET_ID} \
58-
$identity.dkr.ecr.$REGION.amazonaws.com/$CONTAINER:$ARCH "$command"
33+
$CONTAINER "$command"
5934
else
6035
echo "executing with $entrypoint and command '$command'"
6136
docker run -p $LOCALPORT:$REMOTEPORT \
@@ -65,7 +40,6 @@ else
6540
-t -i \
6641
-v $(pwd):/data \
6742
--entrypoint=$entrypoint \
68-
$identity.dkr.ecr.$REGION.amazonaws.com/$CONTAINER:$ARCH \
69-
"$command"
43+
$CONTAINER "$command"
7044
fi
7145

docker/test-local.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
eventfilename=$1
44

5+
if [ -z "$AWS_ACCESS_KEY_ID" ]
6+
then
7+
echo "AWS_ACCESS_KEY_ID must be set in environment!"
8+
exit 1;
9+
fi
10+
11+
if [ -z "$AWS_SECRET_ACCESS_KEY" ]
12+
then
13+
echo "AWS_SECRET_ACCESS_KEY must be set in environment!"
14+
exit 1;
15+
fi
16+
17+
518
event=$(<$eventfilename)
619
echo $event
720
curl -POST -v "http://localhost:9000/2015-03-31/functions/function/invocations" -d @$eventfilename

docker/test-remote.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ eventfilename=$1
44

55
FUNCTION_NAME=$(cat ../terraform/terraform.tfstate | jq '.outputs.info_lambda_name.value // empty' -r)
66

7+
if [ -z "$AWS_ACCESS_KEY_ID" ]
8+
then
9+
echo "AWS_ACCESS_KEY_ID must be set in environment!"
10+
exit 1;
11+
fi
12+
13+
if [ -z "$AWS_SECRET_ACCESS_KEY" ]
14+
then
15+
echo "AWS_SECRET_ACCESS_KEY must be set in environment!"
16+
exit 1;
17+
fi
718

819
aws lambda invoke \
920
--function-name "$FUNCTION_NAME" \

terraform/main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,8 @@ output "bucket" {
5252
description = "Storage bucket"
5353
value = module.resources.bucket
5454
}
55+
56+
output "container" {
57+
description = "Container ARN"
58+
value = module.resources.container
59+
}

terraform/resources/ecr.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ data aws_ecr_image runner_image {
4747
image_tag = var.arch
4848
depends_on = [ null_resource.ecr_image, aws_ecr_repository.runner_ecr_repo ]
4949
}
50+
51+
output "container" {
52+
value = "${aws_ecr_repository.runner_ecr_repo.repository_url}:${var.arch}"
53+
}

0 commit comments

Comments
 (0)