diff --git a/.github/workflows/nightly-ecs-examples-validator.yml b/.github/workflows/nightly-ecs-examples-validator.yml index cb9d530e..d09a9b8a 100644 --- a/.github/workflows/nightly-ecs-examples-validator.yml +++ b/.github/workflows/nightly-ecs-examples-validator.yml @@ -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: diff --git a/examples/dev-server-ec2/validate.sh b/examples/dev-server-ec2/validate.sh index 46d502a4..a5804e17 100755 --- a/examples/dev-server-ec2/validate.sh +++ b/examples/dev-server-ec2/validate.sh @@ -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!!" \ No newline at end of file +echo "e2e setup for Consul on ECS EC2 is successful!!" \ No newline at end of file diff --git a/examples/mesh-gateways/outputs.tf b/examples/mesh-gateways/outputs.tf index 9ba71a6d..b35335e1 100644 --- a/examples/mesh-gateways/outputs.tf +++ b/examples/mesh-gateways/outputs.tf @@ -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 +} \ No newline at end of file diff --git a/examples/mesh-gateways/validate.sh b/examples/mesh-gateways/validate.sh new file mode 100755 index 00000000..c8cb6c23 --- /dev/null +++ b/examples/mesh-gateways/validate.sh @@ -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!!" \ No newline at end of file