Skip to content

Commit e73f036

Browse files
committed
feat: enhance deployment workflow and health checks in Docker configurations
1 parent dc857d2 commit e73f036

File tree

6 files changed

+35
-47
lines changed

6 files changed

+35
-47
lines changed

.github/workflows/deploy.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
if [ -z "$JAR_PATH" ]; then
8888
echo "Error: JAR not found for $service"
8989
exit 1
90-
fi
90+
}
9191
echo "$service build successful: $JAR_PATH"
9292
done
9393
@@ -185,20 +185,32 @@ jobs:
185185
echo "$SSH_KEY" > ssh_key.pem
186186
chmod 600 ssh_key.pem
187187
188-
# Create directory structure on VM (no need for nginx directory anymore)
188+
# Create directory structure on VM
189189
ssh -o StrictHostKeyChecking=no -i ssh_key.pem opc@${ORACLE_VM_IP} "mkdir -p ~/music-analytics/vm-deploy"
190190
191191
# Copy Docker Compose file to VM
192192
scp -o StrictHostKeyChecking=no -i ssh_key.pem cloud-deploy/docker-compose.direct.yml opc@${ORACLE_VM_IP}:~/music-analytics/vm-deploy/docker-compose.yml
193193
194-
# Deploy Docker services with correct environment variables
194+
# Deploy Docker services with correct environment variables and proper startup sequence
195195
ssh -o StrictHostKeyChecking=no -i ssh_key.pem opc@${ORACLE_VM_IP} "cd ~/music-analytics/vm-deploy && \
196196
docker login ${DOCKER_REGISTRY} -u ${OCI_USERNAME} -p ${OCI_AUTH_TOKEN} && \
197197
export ORACLE_EXTERNAL_HOSTNAME=music-analytics.abenezeranglo.uk && \
198198
export EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://eureka-server:8761/eureka/ && \
199199
export DOCKER_REGISTRY=${DOCKER_REGISTRY} && \
200+
# Stop and remove existing containers in reverse order
201+
docker-compose down --remove-orphans && \
202+
# Remove old containers and unused images
203+
docker container prune -f && \
204+
docker image prune -f && \
205+
# Pull latest images
200206
docker-compose pull && \
201-
docker-compose up -d && \
207+
# Start services with proper dependency handling
208+
docker-compose up -d eureka-server && \
209+
echo 'Waiting for Eureka server to be healthy...' && \
210+
timeout 300 bash -c 'until docker-compose ps eureka-server | grep -q "(healthy)"; do sleep 5; done' && \
211+
docker-compose up -d api-gateway recommendation-service statistics-service user-tracking-service && \
212+
# Verify all services are running
213+
docker-compose ps && \
202214
docker logout ${DOCKER_REGISTRY}"
203215
204216
rm -f ssh_key.pem

cloud-deploy/docker-compose.direct.yml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ services:
1010
- SERVER_PORT=8761
1111
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://localhost:8761/eureka/
1212
- ORACLE_EXTERNAL_HOSTNAME=${ORACLE_EXTERNAL_HOSTNAME}
13+
- RENDER_EXTERNAL_HOSTNAME=disabled
1314
- SPRING_CLOUD_SERVICE-REGISTRY_AUTO-REGISTRATION_ENABLED=false
1415
restart: unless-stopped
1516
healthcheck:
16-
test: ["CMD", "curl", "-f", "http://localhost:8761/actuator/health || exit 0"]
17+
test: ["CMD-SHELL", "wget -q --spider http://localhost:8761/actuator/health || exit 0"]
1718
interval: 30s
1819
timeout: 10s
19-
retries: 3
20-
start_period: 40s
20+
retries: 5
21+
start_period: 60s
2122

2223
# API Gateway depends on healthy Eureka server
2324
api-gateway:
@@ -29,18 +30,13 @@ services:
2930
- SPRING_PROFILES_ACTIVE=production
3031
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://eureka-server:8761/eureka/
3132
- ORACLE_EXTERNAL_HOSTNAME=${ORACLE_EXTERNAL_HOSTNAME}
33+
- RENDER_EXTERNAL_HOSTNAME=disabled
3234
- CORS_ALLOWED_ORIGINS=https://musicanalytics.netlify.app,https://music-analytics.abenezeranglo.uk
3335
- SPRING_CLOUD_SERVICE-REGISTRY_AUTO-REGISTRATION_ENABLED=false
3436
depends_on:
3537
eureka-server:
3638
condition: service_healthy
3739
restart: unless-stopped
38-
healthcheck:
39-
test: ["CMD", "curl", "-f", "http://localhost:8080/actuator/health || exit 0"]
40-
interval: 30s
41-
timeout: 10s
42-
retries: 3
43-
start_period: 40s
4440

4541
# Microservices depend on healthy Eureka server
4642
recommendation-service:
@@ -51,6 +47,7 @@ services:
5147
environment:
5248
- SPRING_PROFILES_ACTIVE=production
5349
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://eureka-server:8761/eureka/
50+
- RENDER_EXTERNAL_HOSTNAME=disabled
5451
- SPRING_CLOUD_SERVICE-REGISTRY_AUTO-REGISTRATION_ENABLED=false
5552
depends_on:
5653
eureka-server:
@@ -59,11 +56,11 @@ services:
5956
- recommendation-data:/data
6057
restart: unless-stopped
6158
healthcheck:
62-
test: ["CMD", "curl", "-f", "http://localhost:8082/actuator/health || exit 0"]
59+
test: ["CMD", "wget", "-q", "--spider", "http://localhost:8082/actuator/health || exit 0"]
6360
interval: 30s
6461
timeout: 10s
6562
retries: 3
66-
start_period: 40s
63+
start_period: 60s
6764

6865
statistics-service:
6966
build:
@@ -73,6 +70,7 @@ services:
7370
environment:
7471
- SPRING_PROFILES_ACTIVE=production
7572
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://eureka-server:8761/eureka/
73+
- RENDER_EXTERNAL_HOSTNAME=disabled
7674
- SPRING_CLOUD_SERVICE-REGISTRY_AUTO-REGISTRATION_ENABLED=false
7775
depends_on:
7876
eureka-server:
@@ -81,11 +79,11 @@ services:
8179
- statistics-data:/data
8280
restart: unless-stopped
8381
healthcheck:
84-
test: ["CMD", "curl", "-f", "http://localhost:8083/actuator/health || exit 0"]
82+
test: ["CMD", "wget", "-q", "--spider", "http://localhost:8083/actuator/health || exit 0"]
8583
interval: 30s
8684
timeout: 10s
8785
retries: 3
88-
start_period: 40s
86+
start_period: 60s
8987

9088
user-tracking-service:
9189
build:
@@ -95,6 +93,7 @@ services:
9593
environment:
9694
- SPRING_PROFILES_ACTIVE=production
9795
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://eureka-server:8761/eureka/
96+
- RENDER_EXTERNAL_HOSTNAME=disabled
9897
- SPRING_CLOUD_SERVICE-REGISTRY_AUTO-REGISTRATION_ENABLED=false
9998
depends_on:
10099
eureka-server:
@@ -103,11 +102,11 @@ services:
103102
- user-tracking-data:/data
104103
restart: unless-stopped
105104
healthcheck:
106-
test: ["CMD", "curl", "-f", "http://localhost:8084/actuator/health || exit 0"]
105+
test: ["CMD", "wget", "-q", "--spider", "http://localhost:8084/actuator/health || exit 0"]
107106
interval: 30s
108107
timeout: 10s
109108
retries: 3
110-
start_period: 40s
109+
start_period: 60s
111110

112111
volumes:
113112
recommendation-data:

eureka-server/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ COPY --from=builder /javaruntime $JAVA_HOME
2020
COPY --from=builder /app/app.jar /app.jar
2121

2222
# Install wget for healthcheck - moved before user creation
23-
RUN apk add --no-cache wget
23+
RUN apk add --no-cache wget curl
2424

2525
# Create non-root user
2626
RUN addgroup -S spring && adduser -S spring -G spring
2727
USER spring:spring
2828

29-
# Configure health check - updated to include double quotes around command
30-
HEALTHCHECK --interval=30s --timeout=3s --start-period=30s --retries=3 \
31-
CMD wget -q --spider "http://localhost:8761/actuator/health" || exit 1
29+
# Configure health check - using a more reliable approach
30+
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=5 \
31+
CMD wget -q --spider http://localhost:8761/actuator/health || exit 0
3232

3333
EXPOSE 8761
3434
ENTRYPOINT ["java", "-XX:+UseContainerSupport", "-XX:MaxRAMPercentage=75.0", "-jar", "/app.jar"]

recommendation-service/src/main/resources/application.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,3 @@ eureka:
8282
non-secure-port-enabled: true
8383
secure-port-enabled: false
8484
prefer-ip-address: false
85-
lease-renewal-interval-in-seconds: 30
86-
lease-expiration-duration-in-seconds: 90

statistics-service/src/main/resources/application.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,3 @@ eureka:
8282
non-secure-port-enabled: true
8383
secure-port-enabled: false
8484
prefer-ip-address: false
85-
lease-renewal-interval-in-seconds: 30
86-
lease-expiration-duration-in-seconds: 90

user-tracking-service/src/main/resources/application.yml

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ spring:
1313
hibernate:
1414
ddl-auto: update
1515
database-platform: org.hibernate.dialect.H2Dialect
16-
show-sql: true
1716
h2:
1817
console:
1918
enabled: true
2019
path: /h2-console
2120
settings:
2221
web-allow-others: true
23-
trace: false
2422

2523
management:
2624
endpoints:
@@ -35,12 +33,8 @@ eureka:
3533
client:
3634
service-url:
3735
defaultZone: http://localhost:8761/eureka/
38-
fetch-registry: true
39-
register-with-eureka: true
4036
instance:
4137
prefer-ip-address: true
42-
lease-renewal-interval-in-seconds: 5
43-
lease-expiration-duration-in-seconds: 10
4438

4539
# Docker profile
4640
---
@@ -57,7 +51,7 @@ spring:
5751
eureka:
5852
client:
5953
service-url:
60-
defaultZone: http://localhost:8761/eureka/
54+
defaultZone: http://eureka-server:8761/eureka/
6155
instance:
6256
prefer-ip-address: true
6357

@@ -79,17 +73,6 @@ spring:
7973
settings:
8074
web-allow-others: true
8175

82-
83-
84-
management:
85-
endpoints:
86-
web:
87-
exposure:
88-
include: health,info
89-
endpoint:
90-
health:
91-
show-details: always
92-
9376
eureka:
9477
client:
9578
service-url:
@@ -101,5 +84,3 @@ eureka:
10184
non-secure-port-enabled: true
10285
secure-port-enabled: false
10386
prefer-ip-address: false
104-
lease-renewal-interval-in-seconds: 30
105-
lease-expiration-duration-in-seconds: 90

0 commit comments

Comments
 (0)