Skip to content

Commit

Permalink
Add Mesh gtws
Browse files Browse the repository at this point in the history
  • Loading branch information
Ganeshrockz committed Dec 6, 2023
1 parent c896886 commit 8d4cec8
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/nightly-ecs-examples-validator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ jobs:
region: us-east-2
working-directory: ./examples/dev-server-ec2
variables: '{\"lb_ingress_ip\": \"eval curl -s ifconfig.me\", \"name\": \"ecs-rtya\"}'

- name: Mesh gateways on Consul ECS
region: us-west-1
working-directory: ./examples/mesh-gateways
variables: '{\"lb_ingress_ip\": \"eval curl -s ifconfig.me\", \"name\": \"ecs-oprb\"}'
fail-fast: false
uses: ./.github/workflows/reusable-ecs-example-validator.yml
with:
Expand Down
6 changes: 3 additions & 3 deletions examples/dev-server-ec2/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ while [[ $count -le 20 ]]; do
done
echo ""

if [ "$success" ]; then
echo "e2e setup for Consul on ECS Fargate failed!!"
if [ ! "$success" ]; then
echo "e2e setup for Consul on ECS EC2 failed!!"
exit 1
fi

echo "e2e setup for Consul on ECS Fargate is successful!!"
echo "e2e setup for Consul on ECS EC2 is successful!!"
16 changes: 16 additions & 0 deletions examples/mesh-gateways/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,19 @@ output "dc1_server_url" {
output "dc2_server_url" {
value = "http://${module.dc2.dev_consul_server.lb_dns_name}:8500"
}

output "client_app_consul_service_name" {
value = local.example_client_app_name
}

output "server_app_consul_service_name" {
value = local.example_server_app_name
}

output "dc1_mesh_gateway_name" {
value = local.mgw_name_1
}

output "dc2_mesh_gateway_name" {
value = local.mgw_name_2
}
78 changes: 78 additions & 0 deletions examples/mesh-gateways/validate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

# Script that validates if the setup works E2E on ECS.

waitfor() {
echo -n "waiting for ${2} to be registered in Consul"
local count=0
while [[ $count -le 30 ]]; do
echo -n "."
response=$(curl -sS -X GET "${1}/v1/catalog/services")
if [ $? -ne 0 ]; then
echo "Error: curl command failed"
((count++))
continue
fi
echo $response | grep -q "${2}" && return
sleep 10
((count++))
done
echo ""
echo "timeout waiting for ${2}"
exit 1
}

# get Terraform outputs and initialize required variables.
echo "loading Terraform outputs"
tfOutputs=$(terraform output -json)
DC1_CONSUL_SERVER_ADDR=$(echo "$tfOutputs" | jq -rc '.dc1_server_url.value')
DC2_CONSUL_SERVER_ADDR=$(echo "$tfOutputs" | jq -rc '.dc2_server_url.value')

MESH_CLIENT_APP_LB_ADDR=$(echo "$tfOutputs" | jq -rc '.client_lb_address.value')
MESH_CLIENT_APP_LB_ADDR="${MESH_CLIENT_APP_LB_ADDR%/ui}"

CLIENT_APP_NAME=$(echo "$tfOutputs" | jq -rc '.client_app_consul_service_name.value')
SERVER_APP_NAME=$(echo "$tfOutputs" | jq -rc '.server_app_consul_service_name.value')

DC1_MESH_GW_NAME=$(echo "$tfOutputs" | jq -rc '.dc1_mesh_gateway_name.value')
DC2_MESH_GW_NAME=$(echo "$tfOutputs" | jq -rc '.dc2_mesh_gateway_name.value')

# wait for services to be registered in Consul
waitfor ${DC1_CONSUL_SERVER_ADDR} ${CLIENT_APP_NAME}
echo ""

waitfor ${DC2_CONSUL_SERVER_ADDR} ${SERVER_APP_NAME}
echo ""

waitfor ${DC1_CONSUL_SERVER_ADDR} ${DC1_MESH_GW_NAME}
echo ""

waitfor ${DC2_CONSUL_SERVER_ADDR} ${DC2_MESH_GW_NAME}
echo ""

# hit the client app's LB to check if the server app is reachable
echo -n "calling client app's load balancer"

# make the call to the upstream in a loop because it may take some time for the
# exported-service config and service intention to propagate.
count=0
success=false
while [[ $count -le 20 ]]; do
echo -n "."
response=$(curl -s ${MESH_CLIENT_APP_LB_ADDR} 2> /dev/null)
if echo "$response" | grep -q 'Hello World'; then
echo "$response"
success=true
break
fi
sleep 20
((count++))
done
echo ""

if [ ! "$success" ]; then
echo "e2e setup for Mesh gateways on ECS failed!!"
exit 1
fi

echo "e2e setup for Mesh gateways on ECS is successful!!"

0 comments on commit 8d4cec8

Please sign in to comment.