更新 .gitea/workflows/deploy.yml
Some checks failed
构建并部署 Spring Boot 应用 / build-and-deploy (push) Failing after 0s
Some checks failed
构建并部署 Spring Boot 应用 / build-and-deploy (push) Failing after 0s
This commit is contained in:
@@ -1,51 +1,54 @@
|
|||||||
build-and-deploy:
|
name: 构建并部署 Spring Boot 应用
|
||||||
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04
|
on: [push]
|
||||||
steps: steps:
|
|
||||||
# 1. 设置 Node.js(禁用缓存) # 使用本地离线 Action - setup-node
|
jobs:
|
||||||
- name: 为 Gitea Actions 设置 Node.js 环境 - name: 为 Gitea Actions 设置 Node.js 环境 (离线版)
|
build-and-deploy:
|
||||||
uses: actions/setup-node@v4 uses: /opt/gitea-actions/setup-node/v4.0.2/
|
runs-on: ubuntu-24.04
|
||||||
with: with:
|
steps:
|
||||||
node-version: '20' node-version: '20'
|
# 使用本地离线 Action - setup-node
|
||||||
cache: 'none' # 关键修改:禁用缓存 cache: 'none'
|
- name: 为 Gitea Actions 设置 Node.js 环境 (离线版)
|
||||||
# 2. 检出代码 # 使用本地离线 Action - checkout
|
uses: /opt/gitea-actions/setup-node/v4.0.2/
|
||||||
- name: 检出代码 - name: 检出代码 (离线版)
|
with:
|
||||||
uses: actions/checkout@v4 uses: /opt/gitea-actions/checkout/v4.1.1/
|
node-version: '20'
|
||||||
|
cache: 'none'
|
||||||
|
|
||||||
|
# 使用本地离线 Action - checkout
|
||||||
|
- name: 检出代码 (离线版)
|
||||||
|
uses: /opt/gitea-actions/checkout/v4.1.1/
|
||||||
with:
|
with:
|
||||||
fetch-depth: 1
|
fetch-depth: 1
|
||||||
# 3. 设置 Java 环境 # 使用本地离线 Action - setup-java
|
|
||||||
- name: 设置 JDK 17 - name: 设置 JDK 17 (离线版)
|
# 使用本地离线 Action - setup-java
|
||||||
uses: actions/setup-java@v4 uses: /opt/gitea-actions/setup-java/v4.2.1/
|
- name: 设置 JDK 17 (离线版)
|
||||||
with: with:
|
uses: /opt/gitea-actions/setup-java/v4.2.1/
|
||||||
java-version: '17' java-version: '17'
|
with:
|
||||||
distribution: 'temurin' distribution: 'temurin'
|
java-version: '17'
|
||||||
# 4. 使用 Maven 打包 # 后续步骤保持不变...
|
distribution: 'temurin'
|
||||||
- name: 使用 Maven 打包 - name: 使用 Maven 打包
|
|
||||||
run: mvn clean package -DskipTests run: mvn clean package -DskipTests
|
# 后续步骤保持不变...
|
||||||
# 5. 构建 Docker 镜像
|
- name: 使用 Maven 打包
|
||||||
- name: 构建 Docker 镜像 - name: 构建 Docker 镜像
|
run: mvn clean package -DskipTests
|
||||||
run: | run: docker build -t light-delivery-app:latest .
|
|
||||||
docker build -t light-delivery-app:latest .
|
- name: 构建 Docker 镜像
|
||||||
# 6. 部署到服务器
|
run: docker build -t light-delivery-app:latest .
|
||||||
- name: 部署到服务器 - name: 部署到服务器
|
|
||||||
env: env:
|
- name: 部署到服务器
|
||||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
env:
|
||||||
run: | run: |
|
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
# 配置SSH环境
|
run: |
|
||||||
mkdir -p ~/.ssh mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "$SSH_PRIVATE_KEY" > ~/.ssh/deploy_key echo "$SSH_PRIVATE_KEY" > ~/.ssh/deploy_key
|
echo "$SSH_PRIVATE_KEY" > ~/.ssh/deploy_key
|
||||||
chmod 600 ~/.ssh/deploy_key chmod 600 ~/.ssh/deploy_key
|
chmod 600 ~/.ssh/deploy_key
|
||||||
echo -e "Host *\n\tStrictHostKeyChecking no\n" > ~/.ssh/config echo -e "Host *\n\tStrictHostKeyChecking no\n" > ~/.ssh/config
|
echo -e "Host *\n\tStrictHostKeyChecking no\n" > ~/.ssh/config
|
||||||
|
|
||||||
# 部署到服务器
|
ssh -i ~/.ssh/deploy_key root@115.190.121.151 '
|
||||||
ssh -i ~/.ssh/deploy_key root@115.190.121.151 ' ssh -i ~/.ssh/deploy_key root@115.190.121.151 '
|
docker stop light-delivery-container || true
|
||||||
echo "🚀 开始部署应用..." docker stop light-delivery-container || true
|
docker rm light-delivery-container || true
|
||||||
docker rm -f light-delivery-container || true docker rm light-delivery-container || true
|
docker run -d \
|
||||||
docker run -d \ docker run -d \
|
--name light-delivery-container \
|
||||||
--name light-delivery-container \ --name light-delivery-container \
|
-p 443:443 \
|
||||||
-p 443:443 \ -p 443:443 \
|
-p 80:80 \
|
||||||
@@ -54,5 +51,4 @@ jobs:
|
-v /etc/ssl/certs:/etc/ssl/certs \
|
||||||
-v /etc/ssl/certs:/etc/ssl/certs \ -v /etc/ssl/certs:/etc/ssl/certs \
|
-e KEY_STORE_PASSWORD="$(cat /etc/ssl/certs/keyStorePass.txt)" \
|
||||||
-e KEY_STORE_PASSWORD="$(cat /etc/ssl/certs/keyStorePass.txt)" \ -e KEY_STORE_PASSWORD="$(cat /etc/ssl/certs/keyStorePass.txt)" \
|
light-delivery-app:latest
|
||||||
light-delivery-app:latest light-delivery-app:latest
|
'
|
||||||
echo "✅ 部署完成!"
|
|
||||||
' '
|
|
Reference in New Issue
Block a user