Skip to content

Commit 45dce53

Browse files
committed
fix: add build-and-push script, fix K8s manifests for image pull
- Add build-and-push.sh to build and push all images to DockerHub - Update all K8s manifests: :amd64 -> :latest + imagePullPolicy: Always - Improve deploy.sh with graceful timeout handling and diagnostics - Add k8s path detection to develop and prod CI/CD workflows
1 parent 0a8a55e commit 45dce53

File tree

13 files changed

+115
-16
lines changed

13 files changed

+115
-16
lines changed

.github/workflows/develop-ci-cd.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
uploader-service: ${{ steps.changes.outputs.uploader-service }}
1919
config-server: ${{ steps.changes.outputs.config-server }}
2020
discovery-server: ${{ steps.changes.outputs.discovery-server }}
21+
k8s: ${{ steps.changes.outputs.k8s }}
2122
steps:
2223
- uses: actions/checkout@v4
2324
- uses: dorny/paths-filter@v3
@@ -40,6 +41,8 @@ jobs:
4041
- 'config-server/**'
4142
discovery-server:
4243
- 'discovery-server/**'
44+
k8s:
45+
- 'k8s/**'
4346
4447
build-and-push:
4548
name: Build and Push Images

.github/workflows/prod-ci-cd.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
uploader-service: ${{ steps.changes.outputs.uploader-service }}
1919
config-server: ${{ steps.changes.outputs.config-server }}
2020
discovery-server: ${{ steps.changes.outputs.discovery-server }}
21+
k8s: ${{ steps.changes.outputs.k8s }}
2122
steps:
2223
- uses: actions/checkout@v4
2324
- uses: dorny/paths-filter@v3
@@ -40,6 +41,8 @@ jobs:
4041
- 'config-server/**'
4142
discovery-server:
4243
- 'discovery-server/**'
44+
k8s:
45+
- 'k8s/**'
4346
4447
build-and-push:
4548
name: Build and Push Production Images

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ prem-portfolio/
4949
*.ps1
5050
*.sh
5151
!k8s/deploy.sh
52+
!build-and-push.sh
5253

5354
# -------------------------
5455
# Node.js & Angular (if any)

build-and-push.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
set -e
3+
4+
DOCKER_USERNAME="premtsd18"
5+
PLATFORM="linux/amd64"
6+
7+
echo "Logging into DockerHub..."
8+
docker login -u $DOCKER_USERNAME
9+
10+
SERVICES=(
11+
"config-server"
12+
"discovery-server"
13+
"api-gateway"
14+
"user-service"
15+
"post-service"
16+
"connections-service"
17+
"notification-service"
18+
"uploader-service"
19+
)
20+
21+
echo "Building and pushing all services..."
22+
23+
for service in "${SERVICES[@]}"; do
24+
echo ""
25+
echo "Building $service..."
26+
27+
docker build \
28+
--platform $PLATFORM \
29+
-t $DOCKER_USERNAME/$service:amd64 \
30+
-t $DOCKER_USERNAME/$service:latest \
31+
./$service
32+
33+
echo "Pushing $service..."
34+
docker push $DOCKER_USERNAME/$service:amd64
35+
docker push $DOCKER_USERNAME/$service:latest
36+
37+
echo "$service done!"
38+
done
39+
40+
echo ""
41+
echo "All images built and pushed!"
42+
echo ""
43+
echo "Verify on DockerHub:"
44+
for service in "${SERVICES[@]}"; do
45+
echo " https://hub.docker.com/r/$DOCKER_USERNAME/$service"
46+
done

k8s/deploy.sh

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,32 @@ set -e
33

44
echo "Deploying LinkedIn to K3s Production..."
55

6+
# Function to wait for deployment
7+
wait_for_deployment() {
8+
local name=$1
9+
local namespace=$2
10+
local timeout=${3:-5m}
11+
echo "Waiting for $name..."
12+
kubectl rollout status deployment/$name \
13+
-n $namespace --timeout=$timeout || {
14+
echo "WARNING: $name timed out, continuing..."
15+
kubectl describe deployment/$name -n $namespace | tail -10
16+
kubectl logs -l app=$name -n $namespace --tail=20 || true
17+
}
18+
}
19+
20+
# Function to wait for statefulset
21+
wait_for_statefulset() {
22+
local name=$1
23+
local namespace=$2
24+
local timeout=${3:-5m}
25+
echo "Waiting for $name..."
26+
kubectl rollout status statefulset/$name \
27+
-n $namespace --timeout=$timeout || {
28+
echo "WARNING: $name timed out, continuing..."
29+
}
30+
}
31+
632
echo "Creating namespaces..."
733
kubectl apply -f k8s/namespace.yaml
834

@@ -15,27 +41,32 @@ kubectl apply -f k8s/databases/postgres.yaml
1541
kubectl apply -f k8s/databases/neo4j.yaml
1642
kubectl apply -f k8s/databases/redis.yaml
1743

18-
echo "Waiting for databases..."
19-
kubectl rollout status statefulset/postgres -n linkedin-prod --timeout=3m
20-
kubectl rollout status statefulset/redis -n linkedin-prod --timeout=3m
44+
echo "Waiting for databases (up to 5 min each)..."
45+
wait_for_statefulset postgres linkedin-prod 5m
46+
wait_for_statefulset redis linkedin-prod 5m
2147

2248
echo "Deploying messaging..."
2349
kubectl apply -f k8s/messaging/kafka.yaml
50+
echo "Waiting 30s for Kafka to initialize..."
2451
sleep 30
2552
kubectl apply -f k8s/messaging/kafbat-ui.yaml
2653

2754
echo "Deploying infrastructure..."
2855
kubectl apply -f k8s/infrastructure/config-server.yaml
29-
kubectl rollout status deployment/config-server -n linkedin-prod --timeout=3m
56+
wait_for_deployment config-server linkedin-prod 5m
3057

3158
kubectl apply -f k8s/infrastructure/discovery-server.yaml
32-
kubectl rollout status deployment/discovery-server -n linkedin-prod --timeout=3m
59+
wait_for_deployment discovery-server linkedin-prod 5m
3360

3461
echo "Deploying microservices..."
3562
kubectl apply -f k8s/microservices/
36-
kubectl rollout status deployment/api-gateway -n linkedin-prod --timeout=5m
37-
kubectl rollout status deployment/user-service -n linkedin-prod --timeout=5m
38-
kubectl rollout status deployment/post-service -n linkedin-prod --timeout=5m
63+
echo "Waiting for microservices (up to 5 min)..."
64+
wait_for_deployment api-gateway linkedin-prod 5m
65+
wait_for_deployment user-service linkedin-prod 5m
66+
wait_for_deployment post-service linkedin-prod 5m
67+
wait_for_deployment connections-service linkedin-prod 5m
68+
wait_for_deployment notification-service linkedin-prod 5m
69+
wait_for_deployment uploader-service linkedin-prod 5m
3970

4071
echo "Deploying observability..."
4172
kubectl apply -f k8s/observability/
@@ -46,6 +77,13 @@ kubectl apply -f k8s/network-policy.yaml
4677
echo ""
4778
echo "Deployment complete!"
4879
echo ""
80+
echo "Pod status:"
4981
kubectl get pods -n linkedin-prod
82+
5083
echo ""
84+
echo "Service ports:"
5185
kubectl get services -n linkedin-prod
86+
87+
echo ""
88+
echo "Health check:"
89+
echo "API Gateway: http://195.201.195.25:32000/actuator/health"

k8s/infrastructure/config-server.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ spec:
2020
spec:
2121
containers:
2222
- name: config-server
23-
image: premtsd18/config-server:amd64
23+
image: premtsd18/config-server:latest
24+
imagePullPolicy: Always
2425
ports:
2526
- containerPort: 8888
2627
envFrom:

k8s/infrastructure/discovery-server.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ spec:
2020
spec:
2121
containers:
2222
- name: discovery-server
23-
image: premtsd18/discovery-server:amd64
23+
image: premtsd18/discovery-server:latest
24+
imagePullPolicy: Always
2425
ports:
2526
- containerPort: 8761
2627
envFrom:

k8s/microservices/api-gateway.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ spec:
2020
spec:
2121
containers:
2222
- name: api-gateway
23-
image: premtsd18/api-gateway:amd64
23+
image: premtsd18/api-gateway:latest
24+
imagePullPolicy: Always
2425
ports:
2526
- containerPort: 8080
2627
envFrom:

k8s/microservices/connections-service.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ spec:
2020
spec:
2121
containers:
2222
- name: connections-service
23-
image: premtsd18/connections-service:amd64
23+
image: premtsd18/connections-service:latest
24+
imagePullPolicy: Always
2425
ports:
2526
- containerPort: 8080
2627
envFrom:

k8s/microservices/notification-service.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ spec:
2020
spec:
2121
containers:
2222
- name: notification-service
23-
image: premtsd18/notification-service:amd64
23+
image: premtsd18/notification-service:latest
24+
imagePullPolicy: Always
2425
ports:
2526
- containerPort: 8080
2627
envFrom:

0 commit comments

Comments
 (0)