Skip to content

Commit 4760dad

Browse files
author
Yuriy Bezsonov
committed
WIP: refactoring
1 parent 45abf7e commit 4760dad

4 files changed

Lines changed: 362 additions & 100 deletions

File tree

infrastructure/scripts/deploy/containerize.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,5 @@ ECR_URI=$(aws ecr describe-repositories --repository-names $APP_NAME | jq --raw-
99
echo $ECR_URI
1010
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_URI
1111

12-
IMAGE_TAG=i$(date +%Y%m%d%H%M%S)
13-
echo $IMAGE_TAG
14-
docker tag $APP_NAME:latest $ECR_URI:$IMAGE_TAG
1512
docker tag $APP_NAME:latest $ECR_URI:latest
16-
docker images
17-
18-
docker push $ECR_URI:$IMAGE_TAG
1913
docker push $ECR_URI:latest

infrastructure/scripts/deploy/ecs.sh

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ SUBNET_PUBLIC_2=$(aws ec2 describe-subnets \
8080
--filters "Name=vpc-id,Values=$VPC_ID" "Name=tag:Name,Values=*PublicSubnet2" \
8181
--query 'Subnets[0].SubnetId' --output text) && echo $SUBNET_PUBLIC_2
8282
SECURITY_GROUP_ALB_ID=$(aws ec2 describe-security-groups --filters "Name=vpc-id,Values='$VPC_ID'" \
83-
--query 'SecurityGroups[?GroupName==`'unicorn-store-spring-ecs-sg-alb'`].GroupId' --output text) echo $SECURITY_GROUP_ALB_ID
83+
--query 'SecurityGroups[?GroupName==`'unicorn-store-spring-ecs-sg-alb'`].GroupId' --output text) && echo $SECURITY_GROUP_ALB_ID
8484

8585
aws elbv2 create-load-balancer --no-cli-pager \
8686
--name unicorn-store-spring \
@@ -97,6 +97,19 @@ aws elbv2 create-target-group --no-cli-pager \
9797
--vpc-id $VPC_ID \
9898
--target-type ip
9999

100+
TARGET_GROUP_ARN=$(aws elbv2 describe-target-groups --name unicorn-store-spring \
101+
--query 'TargetGroups[0].TargetGroupArn' --output text)
102+
103+
aws elbv2 modify-target-group \
104+
--target-group-arn $TARGET_GROUP_ARN \
105+
--health-check-path "/actuator/health" \
106+
--health-check-port "traffic-port" \
107+
--health-check-protocol HTTP \
108+
--health-check-interval-seconds 30 \
109+
--health-check-timeout-seconds 5 \
110+
--healthy-threshold-count 2 \
111+
--unhealthy-threshold-count 3
112+
100113
ALB_ARN=$(aws elbv2 describe-load-balancers --name unicorn-store-spring \
101114
--query 'LoadBalancers[0].LoadBalancerArn' --output text) && echo $ALB_ARN
102115
TARGET_GROUP_ARN=$(aws elbv2 describe-target-groups --name unicorn-store-spring \
@@ -111,6 +124,16 @@ aws elbv2 create-listener --no-cli-pager \
111124
VPC_ID=$(aws ec2 describe-vpcs --filters "Name=tag:Name,Values=unicornstore-vpc" \
112125
--query 'Vpcs[0].VpcId' --output text) && echo $VPC_ID
113126

127+
EKS_VPC_CIDR=$(aws ec2 describe-vpcs \
128+
--vpc-ids "$VPC_ID" \
129+
--query "Vpcs[0].CidrBlock" --output text)
130+
131+
LAMBDA_SG_ID=$(aws cloudformation describe-stacks --stack-name unicornstore-stack --query "Stacks[0].Outputs[?ExportName=='LambdaSecurityGroupId'].OutputValue" --output text)
132+
133+
ECS_SG_ID=$(aws ec2 describe-security-groups --filters "Name=group-name,Values=unicorn-store-spring-ecs-sg" --query "SecurityGroups[0].GroupId" --output text)
134+
135+
sleep 1
136+
114137
aws ec2 create-security-group \
115138
--group-name unicorn-store-spring-ecs-sg \
116139
--description "Security group for unicorn-store-spring ECS Service" \
@@ -122,6 +145,21 @@ aws ec2 authorize-security-group-ingress \
122145
--protocol tcp \
123146
--port 8080 \
124147
--source-group $SECURITY_GROUP_ALB_ID
148+
aws ec2 authorize-security-group-ingress \
149+
--group-id "$SECURITY_GROUP_ECS_ID" \
150+
--protocol tcp \
151+
--port 9090 \
152+
--cidr "$EKS_VPC_CIDR"
153+
aws ec2 authorize-security-group-ingress \
154+
--group-id "$SECURITY_GROUP_ECS_ID" \
155+
--protocol tcp \
156+
--port 9404 \
157+
--cidr "$EKS_VPC_CIDR"
158+
aws ec2 authorize-security-group-ingress \
159+
--group-id $ECS_SG_ID \
160+
--protocol tcp \
161+
--port 8080 \
162+
--source-group $LAMBDA_SG_ID
125163

126164
TASK_DEFINITION_ARN=$(aws ecs describe-task-definition --task-definition unicorn-store-spring \
127165
--query 'taskDefinition.taskDefinitionArn' --output text) && echo $TASK_DEFINITION_ARN
@@ -140,6 +178,7 @@ aws ecs create-service --no-cli-pager \
140178
--cluster unicorn-store-spring \
141179
--service-name unicorn-store-spring \
142180
--task-definition $TASK_DEFINITION_ARN \
181+
--enable-execute-command \
143182
--desired-count 1 \
144183
--launch-type FARGATE \
145184
--network-configuration "awsvpcConfiguration={subnets=[$SUBNET_PRIVATE_1,$SUBNET_PRIVATE_2],securityGroups=[$SECURITY_GROUP_ECS_ID],assignPublicIp="DISABLED"}" \

infrastructure/scripts/deploy/eks.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,26 @@ spec:
5151
value: ${SPRING_DATASOURCE_URL}
5252
ports:
5353
- containerPort: 8080
54+
livenessProbe:
55+
httpGet:
56+
path: /actuator/health/liveness
57+
port: 8080
58+
failureThreshold: 6
59+
periodSeconds: 5
5460
readinessProbe:
5561
httpGet:
5662
path: /actuator/health/readiness
5763
port: 8080
5864
failureThreshold: 6
5965
periodSeconds: 5
6066
initialDelaySeconds: 10
61-
timeoutSeconds: 5
6267
startupProbe:
6368
httpGet:
64-
path: /
69+
path: /actuator/health/liveness
6570
port: 8080
66-
failureThreshold: 6
71+
failureThreshold: 10
6772
periodSeconds: 5
68-
initialDelaySeconds: 10
69-
timeoutSeconds: 5
73+
initialDelaySeconds: 20
7074
lifecycle:
7175
preStop:
7276
exec:
@@ -87,7 +91,7 @@ metadata:
8791
project: unicorn-store
8892
app: unicorn-store-spring
8993
spec:
90-
type: NodePort
94+
type: ClusterIP
9195
ports:
9296
- port: 80
9397
targetPort: 8080

0 commit comments

Comments
 (0)