Skip to content

Commit 4d79a70

Browse files
committed
feat: enhance Docker deployment process and improve user feedback in run.bat
1 parent 1af0eae commit 4d79a70

File tree

4 files changed

+40
-49
lines changed

4 files changed

+40
-49
lines changed

.github/workflows/deploy.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ jobs:
176176
ssh -o StrictHostKeyChecking=no -i ${{ env.SSH_KEY_PATH }} opc@${{ secrets.VM_IP_ADDRESS }} "cd ~/music-analytics/vm-deploy && \
177177
echo 'Logging in to Docker registry...' && \
178178
docker login ${{ env.DOCKER_REGISTRY }} -u ${{ env.OCI_USERNAME }} -p ${{ env.OCI_AUTH_TOKEN }} && \
179-
echo 'Stopping existing containers...' && \
180-
docker-compose down --remove-orphans || true && \
179+
echo 'Stopping ALL existing containers...' && \
180+
docker stop $(docker ps -q) || true && \
181+
docker rm $(docker ps -aq) || true && \
181182
echo 'Starting new containers...' && \
182183
docker-compose up -d && \
183184
echo 'Container status:' && \

eureka-server/Dockerfile

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,20 @@
1-
# Build stage
2-
FROM maven:3.8.5-openjdk-8-slim AS build
1+
# First stage: Build the application
2+
FROM maven:3.8.5-openjdk-8-slim AS builder
33
WORKDIR /app
4-
COPY eureka-server.jar app.jar
5-
RUN apk add --no-cache binutils \
6-
&& jlink \
7-
--add-modules java.base,java.logging,java.xml,java.sql,java.naming,java.desktop,java.security.jgss,java.instrument,jdk.unsupported \
8-
--strip-debug \
9-
--no-man-pages \
10-
--no-header-files \
11-
--compress=2 \
12-
--output /javaruntime
4+
COPY pom.xml .
5+
RUN mvn dependency:go-offline
6+
COPY src ./src
7+
RUN mvn package -DskipTests
8+
# Set up Java runtime (if needed)
9+
RUN mkdir -p /javaruntime && \
10+
cp -R $JAVA_HOME/* /javaruntime/
1311

14-
# Runtime stage
12+
# Second stage: Create the runtime image
1513
FROM alpine:3.18
16-
ENV JAVA_HOME=/javaruntime
14+
RUN apk add --no-cache openjdk8-jre-base
15+
WORKDIR /app
16+
ENV JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk
1717
ENV PATH="${JAVA_HOME}/bin:${PATH}"
18-
COPY --from=builder /javaruntime $JAVA_HOME
19-
COPY --from=builder /app/app.jar /app.jar
20-
21-
# Install wget and curl for health check
22-
RUN apk add --no-cache wget curl
23-
24-
# Create non-root user
25-
RUN addgroup -S spring && adduser -S spring -G spring
26-
RUN chown -R spring:spring /app.jar
27-
28-
# Set proper permissions
29-
USER spring:spring
30-
31-
# Expose port
18+
COPY --from=builder /app/target/eureka-server-*.jar /app/app.jar
3219
EXPOSE 8761
33-
34-
# Configure health check - with longer start time and using 0.0.0.0 instead of localhost
35-
HEALTHCHECK --interval=30s --timeout=10s --start-period=120s --retries=5 \
36-
CMD wget -q --spider http://127.0.0.1:8761/actuator/health || exit 1
37-
38-
# Use more memory and enable debug options
39-
ENTRYPOINT ["java", "-Xms256m", "-Xmx512m", "-XX:+UseContainerSupport", "-XX:MaxRAMPercentage=75.0", "-Dspring.profiles.active=docker", "-jar", "/app.jar"]
20+
ENTRYPOINT ["java", "-jar", "/app/app.jar"]

run.bat

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
@echo off
2+
setlocal enabledelayedexpansion
3+
24
echo ===== Music Analytics Platform - Run Options =====
35
echo.
46
echo 1) Run with Docker (requires Docker Desktop running)
@@ -8,16 +10,16 @@ echo.
810

911
set /p choice="Choose option (1-3): "
1012

11-
if "%choice%"=="1" (
12-
call :RunDocker
13-
) else if "%choice%"=="2" (
14-
call :RunDirect
15-
) else if "%choice%"=="3" (
16-
exit /b 0
17-
) else (
18-
echo Invalid option. Please try again.
19-
exit /b 1
20-
)
13+
if "%choice%"=="1" goto RunDocker
14+
if "%choice%"=="2" goto RunDirect
15+
if "%choice%"=="3" exit /b 0
16+
echo Invalid option. Please try again.
17+
exit /b 1
18+
19+
:docker_not_running
20+
echo Please install Docker Desktop from https://www.docker.com/products/docker-desktop/
21+
echo After installing, restart your terminal and try again.
22+
exit /b 1
2123

2224
:RunDocker
2325
echo ===== Building and Running with Docker =====
@@ -26,7 +28,7 @@ REM Check if Docker is running
2628
docker ps >nul 2>&1
2729
if %ERRORLEVEL% neq 0 (
2830
echo Docker is not running. Please start Docker Desktop and try again.
29-
goto :docker_not_running
31+
goto docker_not_running
3032
) else (
3133
echo Docker is running...
3234
)

user-tracking-service/src/main/java/com/example/usertracking/controller/UserTrackingController.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.springframework.web.bind.annotation.*;
99
import java.util.Map;
1010
import java.util.List;
11+
import java.util.HashMap;
1112

1213
@RestController
1314
@RequestMapping("/user-tracking")
@@ -24,15 +25,21 @@ public Map<String, String> logPlayback(@RequestBody Map<String, String> payload)
2425
String playback = payload.get("playback");
2526
PlaybackEvent event = new PlaybackEvent(playback);
2627
playbackRepository.save(event);
27-
return Map.of("status", "success", "message", "Playback logged successfully");
28+
Map<String, String> response = new HashMap<>();
29+
response.put("status", "success");
30+
response.put("message", "Playback logged successfully");
31+
return response;
2832
}
2933

3034
@PostMapping("/logSearch")
3135
public Map<String, String> logSearch(@RequestBody Map<String, String> payload) {
3236
String search = payload.get("search");
3337
SearchEvent event = new SearchEvent(search);
3438
searchRepository.save(event);
35-
return Map.of("status", "success", "message", "Search logged successfully");
39+
Map<String, String> response = new HashMap<>();
40+
response.put("status", "success");
41+
response.put("message", "Search logged successfully");
42+
return response;
3643
}
3744

3845
@GetMapping("/playbacks")

0 commit comments

Comments
 (0)