-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
79 lines (55 loc) · 2.02 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# # Stage 1: Build the Spring Boot application
# FROM maven:3.8.1-openjdk-17 as builder
# # Set the working directory for the build
# WORKDIR /build
# # Copy the Maven project files
# COPY ../pom.xml .
# COPY ../src ./src
# # Build the project
# RUN mvn clean package
# # Stage 2: Build the React application
# FROM node:18 as react-builder
# # Set the working directory for the React build
# WORKDIR /react-app
# # Copy the React project files
# COPY ../url_exct_frontend/package*.json ./
# RUN npm install
# COPY ../url_exct_frontend/ ./
# RUN npm run build
# # Stage 3: Setup Nginx and the Spring Boot application
# FROM nginx:alpine
# # Update package repository and install required packages
# RUN apk update && \
# apk add --no-cache openjdk17 supervisor
# # Set the working directory for the application
# WORKDIR /app
# # Copy the build files from React build stage
# COPY --from=react-builder /react-app/build /usr/share/nginx/html
# # Copy the JAR file from the Spring Boot builder stage
# COPY --from=builder /build/target/*.jar app.jar
# # Allow executable permissions to the JAR file
# RUN chmod +x app.jar
# # Copy supervisord configuration file
# COPY supervisord.conf /etc/supervisord.conf
# # Expose the required ports
# EXPOSE 80 8080
# # Start supervisord to manage Java application and Nginx server
# CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
#Stage 2 Use a base image with JDK and Maven
FROM maven:3.8.4-openjdk-17 AS build
# Set the working directory in the container
WORKDIR /app
# Copy only the necessary files to leverage Docker layer caching
COPY pom.xml .
COPY src ./src
# Build the application
RUN mvn clean package -DskipTests
# Create a minimal runtime image
FROM openjdk:17-jdk-alpine
WORKDIR /app
# Copy the JAR file from the build stage to the current directory
COPY --from=build /app/target/*.jar app.jar
# Expose the application port
EXPOSE 8080
# Command to run the application
CMD ["java", "-jar", "app.jar"]