-
Notifications
You must be signed in to change notification settings - Fork 1
68 lines (57 loc) · 1.83 KB
/
docker-image.yml
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
name: Build, Package and Push Docker Image
# 当推送到 main 分支时触发
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
# 1. 检出代码库
- name: Checkout repository
uses: actions/checkout@v3
# 2. 设置 Node.js 环境来构建前端
- name: Set up Node.js 20
uses: actions/setup-node@v3
with:
node-version: '20'
# 3. 安装前端依赖并构建
- name: Install frontend dependencies and build
working-directory: ./frontend
run: |
npm install
npm run build
# 4. 设置 Java 17 环境来构建后端
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# 5. 使用 Maven 构建后端项目
- name: Build backend with Maven
working-directory: ./backend
run: mvn clean package -DskipTests -Pprod
# 6. 设置 Docker 缓存以加速构建
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# 7. 登录 Docker Hub
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# 8. 构建并推送 Docker 镜像
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: . # 使用 Dockerfile 所在的当前目录
push: true
tags: a18863076056050/RapidDataChat:latest
# 9. 可选:将 Git 提交 SHA 作为镜像标签推送
- name: Push image with Git SHA tag
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: a18863076056050/RapidDataChat:${{ github.sha }}