Skip to content

Commit 2485075

Browse files
committed
Fixed issue #3
1 parent 23ca614 commit 2485075

File tree

3 files changed

+37
-30
lines changed

3 files changed

+37
-30
lines changed

lucy/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ RUN apk add --update --no-cache \
1818
&& pip install \
1919
awscli
2020

21-
# copy our scripts and Task definition
22-
COPY lucy.sh cluster.sh minion.json /opt/jmeter/
23-
RUN chmod +x /opt/jmeter/*.sh
21+
# copy our entrypoint script and Task definition
22+
COPY lucy.sh minion.json /opt/jmeter/
23+
RUN chmod +x /opt/jmeter/lucy.sh
2424

2525
WORKDIR /logs
2626

lucy/cluster.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

lucy/lucy.sh

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@ if [ "$1" != '' ]; then
1818
fi
1919
if [ "$INPUT_JMX" == '' ]; then
2020
echo "Please set a INPUT_JMX or pass a JMX file on the command line"
21-
exit 3
21+
exit 1
2222
fi
2323
if [ "$KEY_NAME" == '' ]; then
2424
echo "Please specify KEY_NAME and provide the filename (without the path and extension)"
25-
exit 1
25+
exit 2
2626
fi
2727
if [ "$SECURITY_GROUP" == '' ]; then
2828
echo "Please set a SECURITY_GROUP that allows ports 22, 1099, 50000, 51000 (tcp) from all ports (e.g. sg-12345678)"
29-
exit 2
29+
exit 3
3030
fi
31-
3231
if [ "$SUBNET_ID" == '' ]; then
3332
echo "ECS requires using a VPC, so you must specify a SUBNET_ID of yor VPC"
3433
exit 4
@@ -59,8 +58,11 @@ fi
5958
if [ "$OWNER" == '' ]; then
6059
OWNER=jmeter-ecs
6160
fi
62-
if [ "$CLUSTER_NAME" == '' ]; then
63-
CLUSTER_NAME=JMeter
61+
if [ "$MINION_CLUSTER_NAME" == '' ]; then
62+
MINION_CLUSTER_NAME=JMeter
63+
fi
64+
if [ "$GRU_CLUSTER_NAME" == '' ]; then
65+
GRU_CLUSTER_NAME=JMeterGru
6466
fi
6567
if [ "$MINION_TASK_DEFINITION" == '' ]; then
6668
MINION_TASK_DEFINITION=Minion
@@ -105,32 +107,39 @@ esac
105107
echo "Using image $IMAGE_ID for $AWS_DEFAULT_REGION"
106108

107109
# Step 1 - Create an ECS Cluster
108-
echo "Creating cluster/$CLUSTER_NAME"
109-
aws ecs create-cluster --cluster-name $CLUSTER_NAME --query 'cluster.[clusterArn]' --output text
110+
echo "Creating cluster/$MINION_CLUSTER_NAME"
111+
aws ecs create-cluster --cluster-name $MINION_CLUSTER_NAME --query 'cluster.[clusterArn]' --output text
110112

111-
# replace our Cluster name in the script we pass to --user-data
112-
sed -i 's/CLUSTER_NAME/'"$CLUSTER_NAME"'/' /opt/jmeter/cluster.sh
113+
# create a setup script to configure our Cluster name that we pass to --user-data
114+
MINION_CLUSTER_SCRIPT=$'#!/bin/bash\necho ECS_CLUSTER='
115+
MINION_CLUSTER_SCRIPT="${MINION_CLUSTER_SCRIPT}$MINION_CLUSTER_NAME >> /etc/ecs/ecs.config"
116+
MINION_CLUSTER_BASE64=$(echo "$MINION_CLUSTER_SCRIPT" | base64 | tr -d '\n')
113117

114118
# Step 2 - Create all instances and register them with the Cluster
115-
echo "Creating $MINION_COUNT Minion instances and register them to cluster/$CLUSTER_NAME"
119+
echo "Creating $MINION_COUNT Minion instances and register them to cluster/$MINION_CLUSTER_NAME"
116120
MINION_INSTANCE_IDS=$(aws ec2 run-instances --image-id $IMAGE_ID --count $MINION_COUNT --instance-type $INSTANCE_TYPE \
117121
--iam-instance-profile Name="ecsInstanceRole" --key-name $KEY_NAME \
118-
--security-group-ids $SECURITY_GROUP --subnet-id $SUBNET_ID --user-data file:///opt/jmeter/cluster.sh \
122+
--security-group-ids $SECURITY_GROUP --subnet-id $SUBNET_ID --user-data $MINION_CLUSTER_BASE64 \
119123
--tag-specifications "$MINION_TAGS" \
120124
--query 'Instances[*].[InstanceId]' --output text |
121125
tr '\n' ' ')
122126
if [ "$MINION_INSTANCE_IDS" == '' ]; then
123127
echo "Creating Minions failed"
124-
echo "Deleting cluster/$CLUSTER_NAME"
125-
aws ecs delete-cluster --cluster $CLUSTER_NAME --query 'cluster.[clusterArn]' --output text
128+
echo "Deleting cluster/$MINION_CLUSTER_NAME"
129+
aws ecs delete-cluster --cluster $MINION_CLUSTER_NAME --query 'cluster.[clusterArn]' --output text
126130
exit 6
127131
fi
128132
echo "Minion instances started: $MINION_INSTANCE_IDS"
129133

134+
# create a setup script to configure our Gru Cluster name that we pass to --user-data
135+
GRU_CLUSTER_SCRIPT=$'#!/bin/bash\necho ECS_CLUSTER='
136+
GRU_CLUSTER_SCRIPT="${GRU_CLUSTER_SCRIPT}$GRU_CLUSTER_NAME >> /etc/ecs/ecs.config"
137+
GRU_CLUSTER_BASE64=$(echo "$GRU_CLUSTER_SCRIPT" | base64 | tr -d '\n')
138+
130139
echo "Creating Gru instance"
131140
GRU_INSTANCE_ID=$(aws ec2 run-instances --image-id $IMAGE_ID --count 1 --instance-type $INSTANCE_TYPE \
132141
--iam-instance-profile Name="ecsInstanceRole" --key-name $KEY_NAME \
133-
--security-group-ids $SECURITY_GROUP --subnet-id $SUBNET_ID \
142+
--security-group-ids $SECURITY_GROUP --subnet-id $SUBNET_ID --user-data $GRU_CLUSTER_BASE64 \
134143
--tag-specifications "$GRU_TAGS" \
135144
--query 'Instances[*].[InstanceId]' --output text |
136145
tr '\n' ' ')
@@ -142,8 +151,8 @@ if [ "$GRU_INSTANCE_ID" == '' ]; then
142151
echo "Waiting for instances to terminate..."
143152
aws ec2 wait instance-terminated --instance-ids $MINION_INSTANCE_IDS --output text
144153

145-
echo "Deleting cluster/$CLUSTER_NAME"
146-
aws ecs delete-cluster --cluster $CLUSTER_NAME --query 'cluster.[clusterArn]' --output text
154+
echo "Deleting cluster/$MINION_CLUSTER_NAME"
155+
aws ecs delete-cluster --cluster $MINION_CLUSTER_NAME --query 'cluster.[clusterArn]' --output text
147156
exit 7
148157
fi
149158
echo "Gru instance started: $GRU_INSTANCE_ID"
@@ -164,7 +173,7 @@ aws ec2 wait instance-running --instance-ids $MINION_INSTANCE_IDS $GRU_INSTANCE_
164173
echo "All instances running - return code $?"
165174

166175
while true; do
167-
CONTAINER_INSTANCE_COUNT=$(aws ecs list-container-instances --cluster $CLUSTER_NAME --output text | grep -c container-instance)
176+
CONTAINER_INSTANCE_COUNT=$(aws ecs list-container-instances --cluster $MINION_CLUSTER_NAME --output text | grep -c container-instance)
168177
if [[ $CONTAINER_INSTANCE_COUNT == $MINION_COUNT ]]; then
169178
echo "Container instances started: $CONTAINER_INSTANCE_COUNT"
170179
break
@@ -174,17 +183,17 @@ while true; do
174183
done
175184

176185
# Step 5 - Fetch our Contatiner Instance IDs
177-
CONTAINER_INSTANCE_IDS=$(aws ecs list-container-instances --cluster $CLUSTER_NAME --output text |
186+
CONTAINER_INSTANCE_IDS=$(aws ecs list-container-instances --cluster $MINION_CLUSTER_NAME --output text |
178187
awk '{print $2}' | tr '\n' ' ')
179188
echo "Container instances IDs: $CONTAINER_INSTANCE_IDS"
180189

181190
# Step 6 - Run the Minion task with the requested count
182191
echo "Running task: $MINION_TASK_DEFINITION, instance count: $MINION_COUNT"
183-
MINION_TASK_IDS=$(aws ecs run-task --cluster $CLUSTER_NAME --task-definition $MINION_TASK_DEFINITION --count $MINION_COUNT \
192+
MINION_TASK_IDS=$(aws ecs run-task --cluster $MINION_CLUSTER_NAME --task-definition $MINION_TASK_DEFINITION --count $MINION_COUNT \
184193
--query 'tasks[*].[taskArn]' --output text | tr '\n' ' ')
185194

186195
echo "Waiting for tasks to run: $MINION_TASK_IDS"
187-
aws ecs wait tasks-running --cluster $CLUSTER_NAME --tasks $MINION_TASK_IDS
196+
aws ecs wait tasks-running --cluster $MINION_CLUSTER_NAME --tasks $MINION_TASK_IDS
188197
if [ "$?" = '0' ]; then
189198
echo "Minion tasks running"
190199
else
@@ -217,10 +226,10 @@ scp -i $PEM_PATH/$KEY_NAME.pem -o UserKnownHostsFile=/dev/null -o StrictHostKeyC
217226

218227
# Step 9 - Stop all tesks
219228
echo "Stopping tasks"
220-
aws ecs list-tasks --cluster $CLUSTER_NAME --output text |
229+
aws ecs list-tasks --cluster $MINION_CLUSTER_NAME --output text |
221230
awk '{print $2}' |
222231
while read line; do
223-
aws ecs stop-task --cluster $CLUSTER_NAME --task $line --query 'task.[taskArn]' --output text;
232+
aws ecs stop-task --cluster $MINION_CLUSTER_NAME --task $line --query 'task.[taskArn]' --output text;
224233
done
225234

226235
# Step 10 - Terminate all instances
@@ -235,7 +244,7 @@ aws ec2 wait instance-terminated --instance-ids $MINION_INSTANCE_IDS $GRU_INSTAN
235244
echo "Deregister task $MINION_TASK_ARN"
236245
aws ecs deregister-task-definition --task-definition $MINION_TASK_ARN --query 'taskDefinition.[taskDefinitionArn]' --output text
237246

238-
echo "Deleting cluster/$CLUSTER_NAME"
239-
aws ecs delete-cluster --cluster $CLUSTER_NAME --query 'cluster.[clusterArn]' --output text
247+
echo "Deleting cluster/$MINION_CLUSTER_NAME"
248+
aws ecs delete-cluster --cluster $MINION_CLUSTER_NAME --query 'cluster.[clusterArn]' --output text
240249

241250
echo "Complete"

0 commit comments

Comments
 (0)