Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ main() {
login
echo "Building with DOCKER_GID=${DOCKER_GID}"

for svc in coding-service; do
for svc in search-service profile-service identity-service; do
echo "Building $svc..."
build_push_java "$svc"
done
Expand Down
7 changes: 4 additions & 3 deletions common-protos/src/main/proto/coding.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ message SubmitCodeRequest {
string studentId = 2;
string language = 3;
string sourceCode = 4;
int32 memoryMb = 5;
float cpus = 6;
int32 timeTakenSeconds = 7;
int32 timeTakenSeconds = 5;
}

message TestCaseResultDto {
Expand All @@ -74,6 +72,9 @@ message SubmitCodeResponse {
int32 totalPoints = 3;
bool passed = 4;
repeated TestCaseResultDto results = 5;
int32 memoryMb = 6;
float cpus = 7;
int32 peakMemoryKb = 8;
}

message LoadCodingRequest {
Expand Down
3 changes: 3 additions & 0 deletions common-protos/src/main/proto/submission_sync.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ message CodeSubmissionDto {
google.protobuf.Timestamp submittedAt = 8;
int32 timeTakenSeconds = 9;
repeated TestCaseResultSyncDto results = 10;
int32 peakMemoryKb = 11;
float cpus = 12;
int32 memoryMb = 13;
}

message TestCaseResultSyncDto {
Expand Down
97 changes: 97 additions & 0 deletions docker/java-service-coding.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# ===== Build stage =====
FROM maven:3.9.9-eclipse-temurin-21 AS build

ARG MODULE
WORKDIR /workspace

# Copy pom gốc và các module để cache dependency
COPY pom.xml .
COPY common-protos/pom.xml common-protos/pom.xml
COPY common-events/pom.xml common-events/pom.xml
COPY gateway-service/pom.xml gateway-service/pom.xml
COPY identity-service/pom.xml identity-service/pom.xml
COPY profile-service/pom.xml profile-service/pom.xml
COPY submission-service/pom.xml submission-service/pom.xml
COPY quiz-service/pom.xml quiz-service/pom.xml
COPY coding-service/pom.xml coding-service/pom.xml
COPY ai-service/pom.xml ai-service/pom.xml
COPY search-service/pom.xml search-service/pom.xml
COPY notification-service/pom.xml notification-service/pom.xml
COPY chat-service/pom.xml chat-service/pom.xml


# Tải dependency trước để cache (Không compile)
RUN mvn -q -DskipTests dependency:go-offline
RUN apt-get update && \
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg && \
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg && \
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian buster stable" > /etc/apt/sources.list.d/docker.list && \
apt-get update && \
apt-get install -y docker-ce-cli

## Copy toàn bộ source
COPY . .

# Build & install proto + events (tạo jar trước)
RUN mvn -q -DskipTests install -pl common-protos,common-events

# Build đúng module
RUN mvn -q -DskipTests -pl ${MODULE} -am package

# ===== Runtime stage =====
FROM eclipse-temurin:21-jre

# Build-args
ARG MODULE
ARG DOCKER_HOST_GID=999

# Cài đặt Docker CLI trong runtime image
RUN apt-get update && \
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg \
sudo && \
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg && \
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian buster stable" > /etc/apt/sources.list.d/docker.list && \
apt-get update && \
apt-get install -y docker-ce-cli

# Tạo group và user cho ứng dụng (chỉ cho coding-service)
RUN if [ "$MODULE" = "coding-service" ]; then \
groupadd -r -g ${DOCKER_HOST_GID} docker_host && \
groupadd -r -g 1001 appuser && \
useradd -r -u 1001 -g appuser -G docker_host appuser && \
echo "appuser ALL=(root) NOPASSWD: /usr/bin/docker" >> /etc/sudoers; \
fi

# TẠO THƯ MỤC /WORK VÀ CẤP QUYỀN
RUN if [ "$MODULE" = "coding-service" ]; then \
mkdir -p /work && chown -R 1001:1001 /work; \
fi

# Thiết lập thư mục làm việc
WORKDIR /app

# Copy JAR với quyền sở hữu phù hợp
COPY --from=build /workspace/${MODULE}/target/*.jar app.jar

# Đặt quyền sở hữu cho coding-service
RUN if [ "$MODULE" = "coding-service" ]; then \
chown appuser:appuser app.jar; \
fi

# Đảm bảo quyền đọc
RUN chmod +r app.jar

# Chuyển sang sử dụng user appuser (chỉ cho coding-service)
USER ${MODULE:+-}${MODULE:+appuser}

ENV JAVA_OPTS=""
EXPOSE 7777
ENTRYPOINT ["sh","-c","java $JAVA_OPTS -jar /app/app.jar"]
8 changes: 8 additions & 0 deletions docker/java-service.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ RUN mvn -q -DskipTests -pl ${MODULE} -am package
# ===== Runtime stage =====
FROM eclipse-temurin:21-jre

# Thiết lập thư mục làm việc
WORKDIR /app

# Copy JAR với quyền sở hữu phù hợp
COPY --from=build /workspace/${MODULE}/target/*.jar app.jar

# Đặt quyền sở hữu cho coding-service
FROM eclipse-temurin:21-jre
# Build-args
ARG MODULE
ARG DOCKER_HOST_GID=999
Expand Down
1 change: 0 additions & 1 deletion search-service/src/main/resources/application-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ spring:
connection-timeout: 10s
lifecycle:
timeout-per-shutdown-phase: 20s

kafka:
bootstrap-servers: http://kafka:9092

Expand Down
1 change: 0 additions & 1 deletion search-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ spring:
uris: http://localhost:9200
username: elasticsearch_search
password: dinhanst2832004

kafka:
bootstrap-servers: localhost:9094
consumer:
Expand Down