添加 CI/CD 自动化部署流程
Some checks failed
构建并部署 Spring Boot 应用 / build-and-deploy (push) Has been cancelled
Some checks failed
构建并部署 Spring Boot 应用 / build-and-deploy (push) Has been cancelled
This commit is contained in:
42
.gitea/workflows/deploy.yml
Normal file
42
.gitea/workflows/deploy.yml
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
name: 构建并部署 Spring Boot 应用
|
||||||
|
on: [push] # 当有任何代码推送到仓库时触发此工作流
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
# 步骤1:获取最新的代码
|
||||||
|
- name: 检出代码
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# 步骤2:设置 Java 环境
|
||||||
|
- name: 设置 JDK 17
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
java-version: '17'
|
||||||
|
distribution: 'temurin'
|
||||||
|
|
||||||
|
# 步骤3:使用 Maven 打包应用
|
||||||
|
- name: 使用 Maven 打包
|
||||||
|
run: mvn clean package -DskipTests
|
||||||
|
|
||||||
|
# 步骤4:构建 Docker 镜像
|
||||||
|
- name: 构建 Docker 镜像
|
||||||
|
run: |
|
||||||
|
docker build -t light-delivery-app:latest .
|
||||||
|
|
||||||
|
# 步骤5:部署到应用服务器
|
||||||
|
- name: 部署到服务器
|
||||||
|
run: |
|
||||||
|
# 使用 SSH 连接到您的应用服务器并执行部署命令
|
||||||
|
ssh root@115.190.121.151 '
|
||||||
|
docker stop light-delivery-container || true
|
||||||
|
docker rm light-delivery-container || true
|
||||||
|
docker run -d \
|
||||||
|
--name light-delivery-container \
|
||||||
|
-p 443:443 \
|
||||||
|
-p 80:80 \
|
||||||
|
-v /etc/ssl/certs:/etc/ssl/certs \
|
||||||
|
-e KEY_STORE_PASSWORD="$(cat /etc/ssl/certs/keyStorePass.txt)" \
|
||||||
|
light-delivery-app:latest
|
||||||
|
'
|
Reference in New Issue
Block a user