Skip to content

Commit 2c82ac1

Browse files
committed
add secrets for the names and values
1 parent 1d6ed05 commit 2c82ac1

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

.github/workflows/front-end.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,40 +78,40 @@ jobs:
7878
with:
7979
registry-type: public
8080

81-
- name: Tag and push to ECR Public
81+
- name: Tag and push to ECR Public (frontend)
8282
run: |
8383
IMAGE_TAG=v1.0.${{ github.run_number }}
8484
ECR_URI=public.ecr.aws/d9h7a7q0/saadsabahuddin/front-end
8585
docker tag ${{ secrets.DOCKER_HUB_USERNAME }}/frontend-aws-integration:$IMAGE_TAG $ECR_URI:$IMAGE_TAG
8686
docker push $ECR_URI:$IMAGE_TAG
8787
88-
- name: Register new task definition with updated image
88+
- name: Register new task definition with updated image (frontend)
8989
run: |
9090
IMAGE_TAG=v1.0.${GITHUB_RUN_NUMBER}
9191
ECR_URI=public.ecr.aws/d9h7a7q0/saadsabahuddin/front-end
9292
9393
# Get current task definition JSON
9494
TASK_DEF_JSON=$(aws ecs describe-task-definition \
95-
--task-definition front-end-td \
95+
--task-definition ${{ secrets.FRONTEND_TASK_DEF }} \
9696
--query 'taskDefinition' \
9797
--output json)
9898
9999
# Update the container image
100100
NEW_TASK_DEF=$(echo $TASK_DEF_JSON | jq --arg IMAGE "$ECR_URI:$IMAGE_TAG" \
101-
'.containerDefinitions[0].image=$IMAGE | del(.status,.revision,.taskDefinitionArn,.requiresAttributes,.compatibilities,.registeredAt,.registeredBy)')
101+
".containerDefinitions[] | select(.name==\"${{ secrets.FRONTEND_CONTAINER }}\") | .image=\$IMAGE | del(.status,.revision,.taskDefinitionArn,.requiresAttributes,.compatibilities,.registeredAt,.registeredBy)" | jq -s '.[0]')
102102
103103
# Register new task definition revision
104104
aws ecs register-task-definition \
105105
--cli-input-json "$NEW_TASK_DEF"
106106
107-
- name: Update ECS service
107+
- name: Update ECS service (frontend)
108108
run: |
109109
# Get the new revision number
110-
NEW_REV=$(aws ecs describe-task-definition --task-definition front-end-td | jq '.taskDefinition.revision')
110+
NEW_REV=$(aws ecs describe-task-definition --task-definition ${{ secrets.FRONTEND_TASK_DEF }} | jq '.taskDefinition.revision')
111111
112112
# Force ECS service to use the new task definition
113113
aws ecs update-service \
114-
--cluster spring-boot-react-aws-integration \
115-
--service front-end-service \
116-
--task-definition front-end-td:$NEW_REV \
114+
--cluster ${{ secrets.CLUSTER_NAME }} \
115+
--service ${{ secrets.FRONTEND_SERVICE }} \
116+
--task-definition ${{ secrets.FRONTEND_TASK_DEF }}:$NEW_REV \
117117
--force-new-deployment

.github/workflows/main.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,41 +99,40 @@ jobs:
9999
with:
100100
registry-type: public
101101

102-
- name: Tag and push to ECR Public
102+
- name: Tag and push to ECR Public (backend)
103103
run: |
104104
IMAGE_TAG=v1.0.${{ github.run_number }}
105105
ECR_URI=public.ecr.aws/d9h7a7q0/saadsabahuddin/back-end
106106
docker tag ${{ secrets.DOCKER_HUB_USERNAME }}/aws-integration:$IMAGE_TAG $ECR_URI:$IMAGE_TAG
107107
docker push $ECR_URI:$IMAGE_TAG
108-
# --- Register new task definition for backend ---
108+
109109
- name: Register new task definition with updated image (backend)
110110
run: |
111111
IMAGE_TAG=v1.0.${GITHUB_RUN_NUMBER}
112112
ECR_URI=public.ecr.aws/d9h7a7q0/saadsabahuddin/back-end
113113
114114
# Get current task definition JSON
115115
TASK_DEF_JSON=$(aws ecs describe-task-definition \
116-
--task-definition spring-boot-td \
116+
--task-definition ${{ secrets.BACKEND_TASK_DEF }} \
117117
--query 'taskDefinition' \
118118
--output json)
119119
120120
# Update the container image
121121
NEW_TASK_DEF=$(echo $TASK_DEF_JSON | jq --arg IMAGE "$ECR_URI:$IMAGE_TAG" \
122-
'.containerDefinitions[0].image=$IMAGE | del(.status,.revision,.taskDefinitionArn,.requiresAttributes,.compatibilities,.registeredAt,.registeredBy)')
122+
".containerDefinitions[] | select(.name==\"${{ secrets.BACKEND_CONTAINER }}\") | .image=\$IMAGE | del(.status,.revision,.taskDefinitionArn,.requiresAttributes,.compatibilities,.registeredAt,.registeredBy)" | jq -s '.[0]')
123123
124124
# Register new task definition revision
125125
aws ecs register-task-definition \
126126
--cli-input-json "$NEW_TASK_DEF"
127127
128-
# --- Update ECS service to use new task definition ---
129128
- name: Update ECS service (backend)
130129
run: |
131130
# Get the new revision number
132-
NEW_REV=$(aws ecs describe-task-definition --task-definition spring-boot-td | jq '.taskDefinition.revision')
131+
NEW_REV=$(aws ecs describe-task-definition --task-definition ${{ secrets.BACKEND_TASK_DEF }} | jq '.taskDefinition.revision')
133132
134133
# Force ECS service to use the new task definition
135134
aws ecs update-service \
136-
--cluster spring-boot-react-aws-integration \
137-
--service spring-boot-service \
138-
--task-definition spring-boot-td:$NEW_REV \
135+
--cluster ${{ secrets.CLUSTER_NAME }} \
136+
--service ${{ secrets.BACKEND_SERVICE }} \
137+
--task-definition ${{ secrets.BACKEND_TASK_DEF }}:$NEW_REV \
139138
--force-new-deployment

0 commit comments

Comments
 (0)