Skip to content

Commit ec81e76

Browse files
committed
初始化
1 parent cc3c766 commit ec81e76

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

.github/workflows/docker-image.yml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Build, Package and Push Docker Image
2+
3+
# 当推送到 main 分支时触发
4+
on:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
# 1. 检出代码库
15+
- name: Checkout repository
16+
uses: actions/checkout@v3
17+
18+
# 2. 设置 Node.js 环境来构建前端
19+
- name: Set up Node.js 20
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: '20'
23+
24+
# 3. 安装前端依赖并构建
25+
- name: Install frontend dependencies and build
26+
working-directory: ./frontend
27+
run: |
28+
npm install
29+
npm run build
30+
31+
# 4. 设置 Java 17 环境来构建后端
32+
- name: Set up JDK 17
33+
uses: actions/setup-java@v3
34+
with:
35+
java-version: '17'
36+
distribution: 'temurin'
37+
38+
# 5. 使用 Maven 构建后端项目
39+
- name: Build backend with Maven
40+
working-directory: ./backend
41+
run: mvn clean package -DskipTests -Pprod
42+
43+
# 6. 设置 Docker 缓存以加速构建
44+
- name: Set up Docker Buildx
45+
uses: docker/setup-buildx-action@v2
46+
47+
# 7. 登录 Docker Hub
48+
- name: Log in to Docker Hub
49+
uses: docker/login-action@v2
50+
with:
51+
username: ${{ secrets.DOCKER_USERNAME }}
52+
password: ${{ secrets.DOCKER_PASSWORD }}
53+
54+
# 8. 构建并推送 Docker 镜像
55+
- name: Build and push Docker image
56+
uses: docker/build-push-action@v5
57+
with:
58+
context: . # 使用 Dockerfile 所在的当前目录
59+
push: true
60+
tags: a18863076056050/RapidDataChat:latest
61+
62+
# 9. 可选:将 Git 提交 SHA 作为镜像标签推送
63+
- name: Push image with Git SHA tag
64+
uses: docker/build-push-action@v5
65+
with:
66+
context: .
67+
push: true
68+
tags: a18863076056050/RapidDataChat:${{ github.sha }}

Dockerfile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# 使用 Eclipse Temurin OpenJDK 17 作为基础镜像
2+
FROM eclipse-temurin:17-jdk-alpine
3+
4+
# 创建应用程序工作目录
5+
WORKDIR /app
6+
7+
# 复制后端构建好的 JAR 文件到容器中
8+
COPY backend/target/backend-0.0.1.jar app.jar
9+
10+
# 复制前端构建好的静态文件到后端的静态资源目录
11+
COPY frontend/build /app/public
12+
13+
# 设置环境变量
14+
ENV JAVA_OPTS=""
15+
16+
# 容器启动时执行的命令
17+
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar /app/app.jar"]
18+
19+
# 暴露应用端口
20+
EXPOSE 8080

0 commit comments

Comments
 (0)