chb2024 commited on
Commit
2882d92
·
verified ·
1 Parent(s): 4a01dd0

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +43 -0
Dockerfile ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 使用 Node.js 和 Java 多阶段构建
2
+ FROM node:20.15.0-alpine AS frontend
3
+ WORKDIR /app
4
+ # 安装必要工具
5
+ RUN apk add --no-cache git
6
+
7
+ # 克隆项目并构建前端
8
+ RUN git clone --branch docker https://github.com/isinvon/gold-foil-font-api.git .
9
+ WORKDIR /app/gui
10
+ RUN npm install -g pnpm@9.14.2
11
+ RUN pnpm install
12
+ RUN pnpm build
13
+
14
+ # 后端构建阶段
15
+ FROM maven:3.9.8-eclipse-temurin-21-alpine AS backend
16
+ WORKDIR /app
17
+ COPY --from=frontend /app .
18
+ RUN mvn clean package -DskipTests
19
+
20
+ # Nginx 配置
21
+ FROM nginx:alpine AS nginx
22
+ COPY --from=frontend /app/gui/dist /usr/share/nginx/html
23
+ COPY nginx.conf /etc/nginx/nginx.conf
24
+
25
+ # 最终运行阶段
26
+ FROM eclipse-temurin:21-jre-alpine
27
+ WORKDIR /app
28
+ # 安装 nginx
29
+ RUN apk add --no-cache nginx
30
+ # 复制构建产物和配置
31
+ COPY --from=backend /app/target/*.jar app.jar
32
+ COPY --from=nginx /usr/share/nginx/html /usr/share/nginx/html
33
+ COPY --from=nginx /etc/nginx/nginx.conf /etc/nginx/nginx.conf
34
+
35
+ # 创建启动脚本
36
+ RUN echo '#!/bin/sh\nnginx\njava -jar app.jar' > /start.sh && chmod +x /start.sh
37
+
38
+ # 只暴露一个端口
39
+ EXPOSE 7860
40
+
41
+ # 启动服务
42
+ CMD ["/start.sh"]
43
+