Skip to content

初始化

初始化 #6

Workflow file for this run

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 }}