Skip to content

Commit 7a7d1c0

Browse files
committed
Updated example to use frontend/backend structure
1 parent b83385c commit 7a7d1c0

File tree

15 files changed

+80
-82
lines changed

15 files changed

+80
-82
lines changed

examples/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Prerequisites
44
* Install latest [aws-cli](https://docs.aws.amazon.com/cli/latest/userguide/installing.html).
55

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

99
```
@@ -20,7 +20,7 @@ export KEY_PAIR_NAME=<key-pair to access ec2 instances where apps are running>
2020
export ENVOY_IMAGE=<the latest recommended envoy image, see https://docs.aws.amazon.com/app-mesh/latest/userguide/envoy.html>
2121
export CLUSTER_SIZE=<number of ec2 instances to spin up to join cluster
2222
export SERVICES_DOMAIN=<domain under which services will be discovered, e.g. "default.svc.cluster.local">
23-
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>
23+
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>
2424
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>
2525
```
2626

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

5858
In Elastic Container Registry, created two new repositories:
5959
- colorteller
60-
- gateway
60+
- frontend
6161

6262
Build the docker images as follow:
6363
```
6464
cd apps/colorapp/src/colorteller/
6565
./deploy.sh
6666
cd -
67-
cd apps/colorapp/src/gateway
67+
cd apps/colorapp/src/frontend
6868
./deploy.sh
6969
cd -
7070
```

examples/apps/colorapp/README.md

Lines changed: 31 additions & 31 deletions
Large diffs are not rendered by default.

examples/apps/colorapp/ecs/create-task-defs.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ if [ -z "${ENVOY_IMAGE}" ]; then
99
exit 1
1010
fi
1111

12-
if [ -z "${COLOR_GATEWAY_IMAGE}" ]; then
13-
echo "COLOR_GATEWAY_IMAGE environment is not defined"
12+
if [ -z "${FRONTEND_IMAGE}" ]; then
13+
echo "FRONTEND_IMAGE environment is not defined"
1414
exit 1
1515
fi
1616

@@ -82,26 +82,26 @@ generate_color_teller_task_def() {
8282
--cli-input-json "$task_def_json")
8383
}
8484

85-
# Color Gateway Task Definition
86-
generate_sidecars "colorgateway"
85+
# Color Frontend Task Definition
86+
generate_sidecars "frontend"
8787
task_def_json=$(jq -n \
88-
--arg NAME "$ENVIRONMENT_NAME-ColorGateway" \
88+
--arg NAME "$ENVIRONMENT_NAME-Frontend" \
8989
--arg STAGE "$APPMESH_STAGE" \
9090
--arg COLOR_TELLER_ENDPOINT "colorteller.$SERVICES_DOMAIN:9080" \
9191
--arg TCP_ECHO_ENDPOINT "tcpecho.$SERVICES_DOMAIN:2701" \
92-
--arg APP_IMAGE $COLOR_GATEWAY_IMAGE \
92+
--arg APP_IMAGE $FRONTEND_IMAGE \
9393
--arg AWS_REGION $AWS_DEFAULT_REGION \
9494
--arg ECS_SERVICE_LOG_GROUP $ecs_service_log_group \
95-
--arg AWS_LOG_STREAM_PREFIX_APP "colorgateway-app" \
95+
--arg AWS_LOG_STREAM_PREFIX_APP "frontend-app" \
9696
--arg TASK_ROLE_ARN $task_role_arn \
9797
--arg EXECUTION_ROLE_ARN $execution_role_arn \
9898
--argjson ENVOY_CONTAINER_JSON "${envoy_container_json}" \
9999
--argjson XRAY_CONTAINER_JSON "${xray_container_json}" \
100-
-f "${DIR}/colorgateway-base-task-def.json")
100+
-f "${DIR}/frontend-base-task-def.json")
101101
task_def=$(aws --profile "${AWS_PROFILE}" --region "${AWS_DEFAULT_REGION}" \
102102
ecs register-task-definition \
103103
--cli-input-json "$task_def_json")
104-
colorgateway_task_def_arn=($(echo $task_def \
104+
frontend_task_def_arn=($(echo $task_def \
105105
| jq -r '.taskDefinition | .taskDefinitionArn'))
106106

107107
# Color Teller White Task Definition

examples/apps/colorapp/ecs/ecs-colorapp.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ aws --profile "${AWS_PROFILE}" --region "${AWS_DEFAULT_REGION}" \
2020
EnvironmentName="${ENVIRONMENT_NAME}" \
2121
ECSServicesDomain="${SERVICES_DOMAIN}" \
2222
AppMeshMeshName="${MESH_NAME}" \
23-
ColorGatewayTaskDefinition="${colorgateway_task_def_arn}" \
23+
FrontendTaskDefinition="${frontend_task_def_arn}" \
2424
ColorTellerWhiteTaskDefinition="${colorteller_white_task_def_arn}" \
2525
ColorTellerRedTaskDefinition="${colorteller_red_task_def_arn}" \
2626
ColorTellerBlueTaskDefinition="${colorteller_blue_task_def_arn}" \

examples/apps/colorapp/ecs/ecs-colorapp.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Parameters:
1212
Type: String
1313
Description: DNS namespace used by services e.g. default.svc.cluster.local
1414

15-
ColorGatewayTaskDefinition:
15+
FrontendTaskDefinition:
1616
Type: String
17-
Description: Task definition for ColorGateway Service
17+
Description: Task definition for Frontend Service
1818

1919
ColorTellerWhiteTaskDefinition:
2020
Type: String
@@ -201,11 +201,11 @@ Resources:
201201
- 'Fn::ImportValue': !Sub "${EnvironmentName}:PrivateSubnet2"
202202
TaskDefinition: { Ref: ColorTellerBlackTaskDefinition }
203203

204-
### colorgateway.default.svc.cluster.local
205-
ColorGatewayServiceDiscoveryRecord:
204+
### frontend.default.svc.cluster.local
205+
FrontendServiceDiscoveryRecord:
206206
Type: 'AWS::ServiceDiscovery::Service'
207207
Properties:
208-
Name: "colorgateway"
208+
Name: "frontend"
209209
DnsConfig:
210210
NamespaceId:
211211
'Fn::ImportValue': !Sub "${EnvironmentName}:ECSServiceDiscoveryNamespace"
@@ -215,7 +215,7 @@ Resources:
215215
HealthCheckCustomConfig:
216216
FailureThreshold: 1
217217

218-
ColorGatewayService:
218+
FrontendService:
219219
Type: 'AWS::ECS::Service'
220220
DependsOn:
221221
- WebLoadBalancerRule
@@ -229,7 +229,7 @@ Resources:
229229
LaunchType: EC2
230230
ServiceRegistries:
231231
- RegistryArn:
232-
'Fn::GetAtt': ColorGatewayServiceDiscoveryRecord.Arn
232+
'Fn::GetAtt': FrontendServiceDiscoveryRecord.Arn
233233
NetworkConfiguration:
234234
AwsvpcConfiguration:
235235
AssignPublicIp: DISABLED
@@ -238,7 +238,7 @@ Resources:
238238
Subnets:
239239
- 'Fn::ImportValue': !Sub "${EnvironmentName}:PrivateSubnet1"
240240
- 'Fn::ImportValue': !Sub "${EnvironmentName}:PrivateSubnet2"
241-
TaskDefinition: { Ref: ColorGatewayTaskDefinition }
241+
TaskDefinition: { Ref: FrontendTaskDefinition }
242242
LoadBalancers:
243243
- ContainerName: app
244244
ContainerPort: 9080
@@ -275,7 +275,7 @@ Resources:
275275
Image: "tstrohmeier/alpine-infinite-curl"
276276
Essential: true
277277
Command:
278-
- !Sub "-h http://colorgateway.${ECSServicesDomain}:9080/color"
278+
- !Sub "-h http://frontend.${ECSServicesDomain}:9080/color"
279279
LogConfiguration:
280280
LogDriver: "awslogs"
281281
Options:
@@ -367,7 +367,7 @@ Resources:
367367
- CidrIp: 0.0.0.0/0
368368
IpProtocol: -1
369369

370-
# public ALB for color gateway
370+
# public ALB for color frontend
371371
PublicLoadBalancer:
372372
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
373373
Properties:

examples/apps/colorapp/kubernetes/generate-templates.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,35 @@ cat << CONFIG_EOF > "${DIR}/colorapp.yaml"
88
apiVersion: v1
99
kind: Service
1010
metadata:
11-
name: colorgateway
11+
name: frontend
1212
labels:
13-
app: colorgateway
13+
app: frontend
1414
spec:
1515
ports:
1616
- port: 9080
1717
name: http
1818
selector:
19-
app: colorgateway
19+
app: frontend
2020
---
2121
apiVersion: apps/v1
2222
kind: Deployment
2323
metadata:
24-
name: colorgateway
24+
name: frontend
2525
spec:
2626
replicas: 1
2727
selector:
2828
matchLabels:
29-
app: colorgateway
29+
app: frontend
3030
version: v1
3131
template:
3232
metadata:
3333
labels:
34-
app: colorgateway
34+
app: frontend
3535
version: v1
3636
spec:
3737
containers:
38-
- name: colorgateway
39-
image: "${COLOR_GATEWAY_IMAGE}"
38+
- name: frontend
39+
image: "${FRONTEND_IMAGE}"
4040
ports:
4141
- containerPort: 9080
4242
env:
@@ -52,7 +52,7 @@ spec:
5252
runAsUser: 1337
5353
env:
5454
- name: "APPMESH_VIRTUAL_NODE_NAME"
55-
value: "mesh/${MESH_NAME}/virtualNode/colorgateway-vn"
55+
value: "mesh/${MESH_NAME}/virtualNode/frontend-vn"
5656
- name: "ENVOY_LOG_LEVEL"
5757
value: "debug"
5858
- name: "AWS_REGION"
@@ -400,7 +400,7 @@ spec:
400400
image: "tstrohmeier/alpine-infinite-curl"
401401
env:
402402
- name: "HOST"
403-
value: "http://colorgateway.${SERVICES_DOMAIN}:9080/color"
403+
value: "http://frontend.${SERVICES_DOMAIN}:9080/color"
404404
---
405405
406406
# tcpecho

examples/apps/colorapp/servicemesh/appmesh-colorapp.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,10 @@ Resources:
124124
HttpRoute:
125125
Action:
126126
WeightedTargets:
127-
- VirtualNode: colorteller-white-vn
127+
- VirtualNode: colorteller-red-vn
128128
Weight: 1
129129
- VirtualNode: colorteller-blue-vn
130130
Weight: 1
131-
- VirtualNode: colorteller-red-vn
132-
Weight: 1
133131
Match:
134132
Prefix: "/"
135133

@@ -177,22 +175,22 @@ Resources:
177175
VirtualNode:
178176
VirtualNodeName: tcpecho-vn
179177

180-
ColorGatewayVirtualNode:
178+
FrontendVirtualNode:
181179
Type: AWS::AppMesh::VirtualNode
182180
DependsOn:
183181
- ColorTellerVirtualService
184182
- TcpEchoVirtualService
185183
Properties:
186184
MeshName: !Ref AppMeshMeshName
187-
VirtualNodeName: colorgateway-vn
185+
VirtualNodeName: frontend-vn
188186
Spec:
189187
Listeners:
190188
- PortMapping:
191189
Port: 9080
192190
Protocol: http
193191
ServiceDiscovery:
194192
DNS:
195-
Hostname: !Sub "colorgateway.${ServicesDomain}"
193+
Hostname: !Sub "frontend.${ServicesDomain}"
196194
Backends:
197195
- VirtualService:
198196
VirtualServiceName: !Sub "colorteller.${ServicesDomain}"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
frontend

examples/apps/colorapp/src/gateway/Dockerfile renamed to examples/apps/colorapp/src/frontend/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM golang:1-stretch as builder
22
ARG GO_PROXY=https://proxy.golang.org
3-
WORKDIR /go/src/github.com/aws/aws-app-mesh-examples/colorapp/gateway
3+
WORKDIR /go/src/github.com/aws/aws-app-mesh-examples/colorapp/frontend
44

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

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

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

24-
ENTRYPOINT ["/bin/aws-app-mesh-examples-colorapp-gateway"]
24+
ENTRYPOINT ["/bin/aws-app-mesh-examples-colorapp-frontend"]

0 commit comments

Comments
 (0)