Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Prerequisites
* Install latest [aws-cli](https://docs.aws.amazon.com/cli/latest/userguide/installing.html).

* Build and push the colorteller and gateway images using deploy.sh from within /examples/apps/colorapp/src/
* Build and push the colorteller and frontend images using deploy.sh from within /examples/apps/colorapp/src/
* Configure aws-cli to support Appmesh APIs

```
Expand All @@ -20,7 +20,7 @@ export KEY_PAIR_NAME=<key-pair to access ec2 instances where apps are running>
export ENVOY_IMAGE=<the latest recommended envoy image, see https://docs.aws.amazon.com/app-mesh/latest/userguide/envoy.html>
export CLUSTER_SIZE=<number of ec2 instances to spin up to join cluster
export SERVICES_DOMAIN=<domain under which services will be discovered, e.g. "default.svc.cluster.local">
export COLOR_GATEWAY_IMAGE=<image location for colorapp's gateway, e.g. "<youraccountnumber>.dkr.ecr.amazonaws.com/gateway:latest" - you need to build this image and use your own ECR repository, see below>
export FRONTEND_IMAGE=<image location for colorapp's frontend, e.g. "<youraccountnumber>.dkr.ecr.amazonaws.com/frontend:latest" - you need to build this image and use your own ECR repository, see below>
export COLOR_TELLER_IMAGE=<image location for colorapp's teller, e.g. "<youraccountnumber>.dkr.ecr.amazonaws.com/colorteller:latest" - you need to build this image and use your own ECR repository, see below>
```

Expand Down Expand Up @@ -57,14 +57,14 @@ To add new app, create a directory under apps and follow the setup as in colorap

In Elastic Container Registry, created two new repositories:
- colorteller
- gateway
- frontend

Build the docker images as follow:
```
cd apps/colorapp/src/colorteller/
./deploy.sh
cd -
cd apps/colorapp/src/gateway
cd apps/colorapp/src/frontend
./deploy.sh
cd -
```
Expand Down
62 changes: 31 additions & 31 deletions examples/apps/colorapp/README.md

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions examples/apps/colorapp/ecs/create-task-defs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ if [ -z "${ENVOY_IMAGE}" ]; then
exit 1
fi

if [ -z "${COLOR_GATEWAY_IMAGE}" ]; then
echo "COLOR_GATEWAY_IMAGE environment is not defined"
if [ -z "${FRONTEND_IMAGE}" ]; then
echo "FRONTEND_IMAGE environment is not defined"
exit 1
fi

Expand Down Expand Up @@ -82,26 +82,26 @@ generate_color_teller_task_def() {
--cli-input-json "$task_def_json")
}

# Color Gateway Task Definition
generate_sidecars "colorgateway"
# Color Frontend Task Definition
generate_sidecars "frontend"
task_def_json=$(jq -n \
--arg NAME "$ENVIRONMENT_NAME-ColorGateway" \
--arg NAME "$ENVIRONMENT_NAME-Frontend" \
--arg STAGE "$APPMESH_STAGE" \
--arg COLOR_TELLER_ENDPOINT "colorteller.$SERVICES_DOMAIN:9080" \
--arg TCP_ECHO_ENDPOINT "tcpecho.$SERVICES_DOMAIN:2701" \
--arg APP_IMAGE $COLOR_GATEWAY_IMAGE \
--arg APP_IMAGE $FRONTEND_IMAGE \
--arg AWS_REGION $AWS_DEFAULT_REGION \
--arg ECS_SERVICE_LOG_GROUP $ecs_service_log_group \
--arg AWS_LOG_STREAM_PREFIX_APP "colorgateway-app" \
--arg AWS_LOG_STREAM_PREFIX_APP "frontend-app" \
--arg TASK_ROLE_ARN $task_role_arn \
--arg EXECUTION_ROLE_ARN $execution_role_arn \
--argjson ENVOY_CONTAINER_JSON "${envoy_container_json}" \
--argjson XRAY_CONTAINER_JSON "${xray_container_json}" \
-f "${DIR}/colorgateway-base-task-def.json")
-f "${DIR}/frontend-base-task-def.json")
task_def=$(aws --profile "${AWS_PROFILE}" --region "${AWS_DEFAULT_REGION}" \
ecs register-task-definition \
--cli-input-json "$task_def_json")
colorgateway_task_def_arn=($(echo $task_def \
frontend_task_def_arn=($(echo $task_def \
| jq -r '.taskDefinition | .taskDefinitionArn'))

# Color Teller White Task Definition
Expand Down
2 changes: 1 addition & 1 deletion examples/apps/colorapp/ecs/ecs-colorapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ aws --profile "${AWS_PROFILE}" --region "${AWS_DEFAULT_REGION}" \
EnvironmentName="${ENVIRONMENT_NAME}" \
ECSServicesDomain="${SERVICES_DOMAIN}" \
AppMeshMeshName="${MESH_NAME}" \
ColorGatewayTaskDefinition="${colorgateway_task_def_arn}" \
FrontendTaskDefinition="${frontend_task_def_arn}" \
ColorTellerWhiteTaskDefinition="${colorteller_white_task_def_arn}" \
ColorTellerRedTaskDefinition="${colorteller_red_task_def_arn}" \
ColorTellerBlueTaskDefinition="${colorteller_blue_task_def_arn}" \
Expand Down
20 changes: 10 additions & 10 deletions examples/apps/colorapp/ecs/ecs-colorapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Parameters:
Type: String
Description: DNS namespace used by services e.g. default.svc.cluster.local

ColorGatewayTaskDefinition:
FrontendTaskDefinition:
Type: String
Description: Task definition for ColorGateway Service
Description: Task definition for Frontend Service

ColorTellerWhiteTaskDefinition:
Type: String
Expand Down Expand Up @@ -201,11 +201,11 @@ Resources:
- 'Fn::ImportValue': !Sub "${EnvironmentName}:PrivateSubnet2"
TaskDefinition: { Ref: ColorTellerBlackTaskDefinition }

### colorgateway.default.svc.cluster.local
ColorGatewayServiceDiscoveryRecord:
### frontend.default.svc.cluster.local
FrontendServiceDiscoveryRecord:
Type: 'AWS::ServiceDiscovery::Service'
Properties:
Name: "colorgateway"
Name: "frontend"
DnsConfig:
NamespaceId:
'Fn::ImportValue': !Sub "${EnvironmentName}:ECSServiceDiscoveryNamespace"
Expand All @@ -215,7 +215,7 @@ Resources:
HealthCheckCustomConfig:
FailureThreshold: 1

ColorGatewayService:
FrontendService:
Type: 'AWS::ECS::Service'
DependsOn:
- WebLoadBalancerRule
Expand All @@ -229,7 +229,7 @@ Resources:
LaunchType: EC2
ServiceRegistries:
- RegistryArn:
'Fn::GetAtt': ColorGatewayServiceDiscoveryRecord.Arn
'Fn::GetAtt': FrontendServiceDiscoveryRecord.Arn
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: DISABLED
Expand All @@ -238,7 +238,7 @@ Resources:
Subnets:
- 'Fn::ImportValue': !Sub "${EnvironmentName}:PrivateSubnet1"
- 'Fn::ImportValue': !Sub "${EnvironmentName}:PrivateSubnet2"
TaskDefinition: { Ref: ColorGatewayTaskDefinition }
TaskDefinition: { Ref: FrontendTaskDefinition }
LoadBalancers:
- ContainerName: app
ContainerPort: 9080
Expand Down Expand Up @@ -275,7 +275,7 @@ Resources:
Image: "tstrohmeier/alpine-infinite-curl"
Essential: true
Command:
- !Sub "-h http://colorgateway.${ECSServicesDomain}:9080/color"
- !Sub "-h http://frontend.${ECSServicesDomain}:9080/color"
LogConfiguration:
LogDriver: "awslogs"
Options:
Expand Down Expand Up @@ -367,7 +367,7 @@ Resources:
- CidrIp: 0.0.0.0/0
IpProtocol: -1

# public ALB for color gateway
# public ALB for color frontend
PublicLoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Expand Down
20 changes: 10 additions & 10 deletions examples/apps/colorapp/kubernetes/generate-templates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@ cat << CONFIG_EOF > "${DIR}/colorapp.yaml"
apiVersion: v1
kind: Service
metadata:
name: colorgateway
name: frontend
labels:
app: colorgateway
app: frontend
spec:
ports:
- port: 9080
name: http
selector:
app: colorgateway
app: frontend
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: colorgateway
name: frontend
spec:
replicas: 1
selector:
matchLabels:
app: colorgateway
app: frontend
version: v1
template:
metadata:
labels:
app: colorgateway
app: frontend
version: v1
spec:
containers:
- name: colorgateway
image: "${COLOR_GATEWAY_IMAGE}"
- name: frontend
image: "${FRONTEND_IMAGE}"
ports:
- containerPort: 9080
env:
Expand All @@ -52,7 +52,7 @@ spec:
runAsUser: 1337
env:
- name: "APPMESH_VIRTUAL_NODE_NAME"
value: "mesh/${MESH_NAME}/virtualNode/colorgateway-vn"
value: "mesh/${MESH_NAME}/virtualNode/frontend-vn"
- name: "ENVOY_LOG_LEVEL"
value: "debug"
- name: "AWS_REGION"
Expand Down Expand Up @@ -400,7 +400,7 @@ spec:
image: "tstrohmeier/alpine-infinite-curl"
env:
- name: "HOST"
value: "http://colorgateway.${SERVICES_DOMAIN}:9080/color"
value: "http://frontend.${SERVICES_DOMAIN}:9080/color"
---

# tcpecho
Expand Down
6 changes: 3 additions & 3 deletions examples/apps/colorapp/servicemesh/appmesh-colorapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,22 @@ Resources:
VirtualNode:
VirtualNodeName: tcpecho-vn

ColorGatewayVirtualNode:
FrontendVirtualNode:
Type: AWS::AppMesh::VirtualNode
DependsOn:
- ColorTellerVirtualService
- TcpEchoVirtualService
Properties:
MeshName: !Ref AppMeshMeshName
VirtualNodeName: colorgateway-vn
VirtualNodeName: frontend-vn
Spec:
Listeners:
- PortMapping:
Port: 9080
Protocol: http
ServiceDiscovery:
DNS:
Hostname: !Sub "colorgateway.${ServicesDomain}"
Hostname: !Sub "frontend.${ServicesDomain}"
Backends:
- VirtualService:
VirtualServiceName: !Sub "colorteller.${ServicesDomain}"
Expand Down
1 change: 1 addition & 0 deletions examples/apps/colorapp/src/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
frontend
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM golang:1-stretch as builder
ARG GO_PROXY=https://proxy.golang.org
WORKDIR /go/src/github.com/aws/aws-app-mesh-examples/colorapp/gateway
WORKDIR /go/src/github.com/aws/aws-app-mesh-examples/colorapp/frontend

# Force the go compiler to use modules.
ENV GO111MODULE=on
Expand All @@ -15,10 +15,10 @@ RUN go env -w GOPROXY=${GO_PROXY}
RUN go mod download

COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o /aws-app-mesh-examples-colorapp-gateway .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o /aws-app-mesh-examples-colorapp-frontend .

FROM amazonlinux:2
RUN yum install -y ca-certificates
COPY --from=builder /aws-app-mesh-examples-colorapp-gateway /bin/aws-app-mesh-examples-colorapp-gateway
COPY --from=builder /aws-app-mesh-examples-colorapp-frontend /bin/aws-app-mesh-examples-colorapp-frontend

ENTRYPOINT ["/bin/aws-app-mesh-examples-colorapp-gateway"]
ENTRYPOINT ["/bin/aws-app-mesh-examples-colorapp-frontend"]
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fi

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
ECR_URL="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"
COLOR_GATEWAY_IMAGE=${COLOR_GATEWAY_IMAGE:-"${ECR_URL}/gateway"}
FRONTEND_IMAGE=${FRONTEND_IMAGE:-"${ECR_URL}/frontend"}
GO_PROXY=${GO_PROXY:-"https://proxy.golang.org"}
AWS_CLI_VERSION=$(aws --version 2>&1 | cut -d/ -f2 | cut -d. -f1)

Expand All @@ -29,8 +29,8 @@ ecr_login() {
}

# build
docker build --build-arg GO_PROXY=$GO_PROXY -t $COLOR_GATEWAY_IMAGE ${DIR}
docker build --build-arg GO_PROXY=$GO_PROXY -t $FRONTEND_IMAGE ${DIR}

# push
ecr_login
docker push $COLOR_GATEWAY_IMAGE
docker push $FRONTEND_IMAGE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/aws/aws-app-mesh-examples/colorapp/gateway
module github.com/aws/aws-app-mesh-examples/colorapp/frontend

go 1.12

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (h *tcpEchoHandler) ServeHTTP(writer http.ResponseWriter, request *http.Req
}
defer conn.Close()

strEcho := "Hello from gateway"
strEcho := "Hello from frontend"
log.Printf("Writing '%s'", strEcho)
_, err = fmt.Fprintf(conn, strEcho)
if err != nil {
Expand Down Expand Up @@ -215,7 +215,7 @@ func main() {
log.Println("Using color-teller at " + colorTellerEndpoint)
log.Println("Using tcp-echo at " + tcpEchoEndpoint)

xraySegmentNamer := xray.NewFixedSegmentNamer(fmt.Sprintf("%s-gateway", getStage()))
xraySegmentNamer := xray.NewFixedSegmentNamer(fmt.Sprintf("%s-frontend", getStage()))

http.Handle("/color", xray.Handler(xraySegmentNamer, &colorHandler{}))
http.Handle("/color/clear", xray.Handler(xraySegmentNamer, &clearColorStatsHandler{}))
Expand Down
1 change: 0 additions & 1 deletion examples/apps/colorapp/src/gateway/.gitignore

This file was deleted.