Skip to content

Commit 4a6b314

Browse files
πŸ”§ Fix gitops branch configuration
βœ… Restored .github/workflows/deploy.yml (removed by merge) βœ… Updated services to use private ECR (workflow will update these) βœ… Fixed infrastructure components to use proper public images: - MySQL: public.ecr.aws/docker/library/mysql:8.0 - Redis: public.ecr.aws/docker/library/redis:6.0-alpine - PostgreSQL: public.ecr.aws/docker/library/postgres:13 - RabbitMQ: public.ecr.aws/docker/library/rabbitmq:3.8-management GitOps branch ready for automated deployments.
1 parent 432e3e4 commit 4a6b314

6 files changed

Lines changed: 212 additions & 10 deletions

File tree

β€Ž.github/workflows/deploy.ymlβ€Ž

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches: [gitops]
6+
paths: ['src/**']
7+
workflow_dispatch:
8+
9+
env:
10+
AWS_REGION: ${{ secrets.AWS_REGION }}
11+
12+
jobs:
13+
detect-changes:
14+
name: Detect Changed Services
15+
runs-on: ubuntu-latest
16+
outputs:
17+
changed-services: ${{ steps.changes.outputs.changed-services }}
18+
matrix: ${{ steps.changes.outputs.matrix }}
19+
has-changes: ${{ steps.changes.outputs.has-changes }}
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 2
24+
25+
- name: Detect changed services
26+
id: changes
27+
run: |
28+
SERVICES=("ui" "catalog" "cart" "checkout" "orders")
29+
CHANGED_SERVICES=()
30+
31+
echo "πŸ” Checking for changes in services..."
32+
33+
# Check for changes in each service
34+
for service in "${SERVICES[@]}"; do
35+
if git diff --name-only HEAD~1 HEAD | grep -q "^src/$service/" || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
36+
CHANGED_SERVICES+=("$service")
37+
echo "βœ… Changes detected in: $service"
38+
else
39+
echo "⏭️ No changes in: $service"
40+
fi
41+
done
42+
43+
# If manual trigger, build all services
44+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
45+
echo "πŸ”„ Manual trigger - building all services"
46+
CHANGED_SERVICES=("ui" "catalog" "cart" "checkout" "orders")
47+
fi
48+
49+
# Check if we have any changes
50+
if [ ${#CHANGED_SERVICES[@]} -eq 0 ]; then
51+
echo "❌ No services changed"
52+
echo "has-changes=false" >> $GITHUB_OUTPUT
53+
exit 0
54+
fi
55+
56+
# Create matrix for changed services only
57+
MATRIX_JSON="["
58+
for i in "${!CHANGED_SERVICES[@]}"; do
59+
if [ $i -gt 0 ]; then
60+
MATRIX_JSON+=","
61+
fi
62+
MATRIX_JSON+="\"${CHANGED_SERVICES[$i]}\""
63+
done
64+
MATRIX_JSON+="]"
65+
66+
echo "changed-services=${CHANGED_SERVICES[*]}" >> $GITHUB_OUTPUT
67+
echo "matrix={\"service\":$MATRIX_JSON}" >> $GITHUB_OUTPUT
68+
echo "has-changes=true" >> $GITHUB_OUTPUT
69+
70+
echo "πŸ“Š Services to build: ${CHANGED_SERVICES[*]}"
71+
echo "πŸ“Š Generated matrix: {\"service\":$MATRIX_JSON}"
72+
73+
deploy:
74+
name: Deploy ${{ matrix.service }}
75+
runs-on: ubuntu-latest
76+
needs: detect-changes
77+
if: needs.detect-changes.outputs.has-changes == 'true'
78+
permissions:
79+
contents: write
80+
strategy:
81+
matrix: ${{ fromJson(needs.detect-changes.outputs.matrix) }}
82+
fail-fast: false
83+
steps:
84+
- uses: actions/checkout@v4
85+
86+
- name: Configure AWS credentials
87+
uses: aws-actions/configure-aws-credentials@v4
88+
with:
89+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
90+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
91+
aws-region: ${{ env.AWS_REGION }}
92+
93+
- name: Login to ECR
94+
id: login-ecr
95+
uses: aws-actions/amazon-ecr-login@v2
96+
97+
- name: Build and push ${{ matrix.service }}
98+
run: |
99+
SERVICE="${{ matrix.service }}"
100+
TAG="$(echo ${{ github.sha }} | cut -c1-7)"
101+
AWS_ACCOUNT_ID="${{ secrets.AWS_ACCOUNT_ID }}"
102+
ECR_REPO="${AWS_ACCOUNT_ID}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/retail-store-${SERVICE}"
103+
104+
echo "πŸ”¨ Building ${SERVICE}:${TAG}"
105+
106+
# Create ECR repo if it doesn't exist
107+
aws ecr describe-repositories --repository-names "retail-store-${SERVICE}" 2>/dev/null || \
108+
aws ecr create-repository --repository-name "retail-store-${SERVICE}" \
109+
--image-scanning-configuration scanOnPush=true \
110+
--encryption-configuration encryptionType=AES256
111+
112+
# Build and push
113+
docker build -t "${ECR_REPO}:${TAG}" -t "${ECR_REPO}:latest" "src/${SERVICE}/"
114+
docker push "${ECR_REPO}:${TAG}"
115+
docker push "${ECR_REPO}:latest"
116+
117+
echo "βœ… Pushed ${ECR_REPO}:${TAG}"
118+
echo "ECR_REPO=${ECR_REPO}" >> $GITHUB_ENV
119+
120+
- name: Update Helm values for ${{ matrix.service }}
121+
run: |
122+
SERVICE="${{ matrix.service }}"
123+
TAG="$(echo ${{ github.sha }} | cut -c1-7)"
124+
ECR_REPO="${{ env.ECR_REPO }}"
125+
VALUES_FILE="src/${SERVICE}/chart/values.yaml"
126+
127+
echo "πŸ“ Updating Helm values for ${SERVICE}"
128+
echo " Repository: ${ECR_REPO}"
129+
echo " Tag: ${TAG}"
130+
131+
# Update image repository and tag
132+
sed -i "s|repository:.*|repository: ${ECR_REPO}|g" "${VALUES_FILE}"
133+
sed -i "s|tag:.*|tag: \"${TAG}\"|g" "${VALUES_FILE}"
134+
135+
echo "βœ… Updated ${VALUES_FILE}"
136+
137+
- name: Commit Helm changes for ${{ matrix.service }}
138+
run: |
139+
SERVICE="${{ matrix.service }}"
140+
TAG="$(echo ${{ github.sha }} | cut -c1-7)"
141+
142+
git config --local user.email "gitops@github.com"
143+
git config --local user.name "GitOps Bot"
144+
145+
if ! git diff --quiet "src/${SERVICE}/chart/values.yaml"; then
146+
git add "src/${SERVICE}/chart/values.yaml"
147+
git commit -m "πŸš€ Update ${SERVICE} Helm chart to ${TAG} - ECR: retail-store-${SERVICE} - Commit: ${{ github.sha }}"
148+
149+
# Push with retry logic
150+
for i in {1..3}; do
151+
if git push origin gitops; then
152+
echo "βœ… Successfully pushed Helm update for ${SERVICE}"
153+
break
154+
else
155+
echo "⚠️ Push failed for ${SERVICE}, attempt $i/3. Retrying..."
156+
git pull --rebase origin gitops
157+
sleep 2
158+
fi
159+
160+
if [ $i -eq 3 ]; then
161+
echo "❌ Failed to push ${SERVICE} after 3 attempts"
162+
exit 1
163+
fi
164+
done
165+
else
166+
echo "πŸ“ No Helm changes to commit for ${SERVICE}"
167+
fi
168+
169+
summary:
170+
name: Deployment Summary
171+
runs-on: ubuntu-latest
172+
needs: [detect-changes, deploy]
173+
if: always()
174+
steps:
175+
- name: Create deployment summary
176+
run: |
177+
echo "## πŸš€ Deployment Summary" >> $GITHUB_STEP_SUMMARY
178+
echo "" >> $GITHUB_STEP_SUMMARY
179+
echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
180+
echo "**Branch:** gitops" >> $GITHUB_STEP_SUMMARY
181+
echo "**Triggered by:** ${{ github.actor }}" >> $GITHUB_STEP_SUMMARY
182+
echo "" >> $GITHUB_STEP_SUMMARY
183+
184+
if [ "${{ needs.detect-changes.outputs.has-changes }}" == "true" ]; then
185+
echo "**Changed Services:** ${{ needs.detect-changes.outputs.changed-services }}" >> $GITHUB_STEP_SUMMARY
186+
echo "" >> $GITHUB_STEP_SUMMARY
187+
188+
if [ "${{ needs.deploy.result }}" == "success" ]; then
189+
echo "βœ… **Status:** Deployment successful" >> $GITHUB_STEP_SUMMARY
190+
echo "" >> $GITHUB_STEP_SUMMARY
191+
echo "**Actions completed:**" >> $GITHUB_STEP_SUMMARY
192+
echo "- πŸ”¨ Built and pushed Docker images to ECR" >> $GITHUB_STEP_SUMMARY
193+
echo "- πŸ“ Updated Helm chart values" >> $GITHUB_STEP_SUMMARY
194+
echo "- πŸ’Ύ Committed changes to repository" >> $GITHUB_STEP_SUMMARY
195+
echo "- πŸ”„ ArgoCD will sync automatically" >> $GITHUB_STEP_SUMMARY
196+
else
197+
echo "❌ **Status:** Deployment failed" >> $GITHUB_STEP_SUMMARY
198+
echo "Check the workflow logs for details" >> $GITHUB_STEP_SUMMARY
199+
fi
200+
else
201+
echo "ℹ️ **Status:** No services changed - no deployment needed" >> $GITHUB_STEP_SUMMARY
202+
fi

β€Žsrc/cart/chart/values.yamlβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
replicaCount: 1
66
image:
7-
repository: public.ecr.aws/aws-containers/retail-store-sample-cart
7+
repository: 220755213644.dkr.ecr.us-west-2.amazonaws.com/retail-store-cart
88
pullPolicy: Always
9-
tag: "1.2.2"
9+
tag: "c8ce6bf"
1010
imagePullSecrets:
1111
- name: regcred
1212
nameOverride: ""

β€Žsrc/catalog/chart/values.yamlβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
replicaCount: 1
66
image:
7-
repository: public.ecr.aws/aws-containers/retail-store-sample-catalog
7+
repository: 220755213644.dkr.ecr.us-west-2.amazonaws.com/retail-store-catalog
88
pullPolicy: Always
9-
tag: "1.2.2"
9+
tag: "c8ce6bf"
1010
imagePullSecrets:
1111
- name: regcred
1212
nameOverride: ""

β€Žsrc/checkout/chart/values.yamlβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
replicaCount: 1
66
image:
7-
repository: public.ecr.aws/aws-containers/retail-store-sample-checkout
7+
repository: 220755213644.dkr.ecr.us-west-2.amazonaws.com/retail-store-checkout
88
pullPolicy: Always
9-
tag: "1.2.2"
9+
tag: "c8ce6bf"
1010
imagePullSecrets:
1111
- name: regcred
1212
nameOverride: ''

β€Žsrc/orders/chart/values.yamlβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
replicaCount: 1
66
image:
7-
repository: public.ecr.aws/aws-containers/retail-store-sample-orders
7+
repository: 220755213644.dkr.ecr.us-west-2.amazonaws.com/retail-store-orders
88
pullPolicy: Always
9-
tag: "1.2.2"
9+
tag: "c8ce6bf"
1010
imagePullSecrets:
1111
- name: regcred
1212
nameOverride: ""

β€Žsrc/ui/chart/values.yamlβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
replicaCount: 1
66
image:
7-
repository: public.ecr.aws/aws-containers/retail-store-sample-ui
7+
repository: 220755213644.dkr.ecr.us-west-2.amazonaws.com/retail-store-ui
88
pullPolicy: Always
9-
tag: "1.2.2"
9+
tag: "c8ce6bf"
1010
imagePullSecrets:
1111
- name: regcred
1212
nameOverride: ""

0 commit comments

Comments
Β (0)