feat: 打包镜像 #50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Compose Management | |
on: | |
push: | |
branches: [ "master" ] # 触发条件:推送到 master 分支 | |
workflow_dispatch: # 手动触发工作流 | |
jobs: | |
back_java: | |
runs-on: ubuntu-latest | |
outputs: | |
backup_zip: ${{ steps.backup.outputs.zip-path }} # 提供 ZIP 文件路径作为输出 | |
steps: | |
- name: 打印信息 🎉 | |
run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." | |
- name: 打印操作系统信息 🐧 | |
run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" | |
- name: 打印分支和仓库信息 🔎 | |
run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." | |
- name: 检查仓库代码 👁︎ | |
uses: actions/checkout@v4 | |
- name: 打印仓库文件列表 📦 | |
run: ls ${{ github.workspace }} | |
- name: 打包代码成 ZIP 文件 📦 | |
id: backup | |
run: | | |
zip -r code.zip . -x "*.git*" | |
echo "::set-output name=zip-path::code.zip" | |
- name: 查看 zip 文件 📦 | |
run: ls | |
- name: 推送到备份服务器 | |
uses: cross-the-world/ssh-scp-ssh-pipelines@latest | |
env: | |
LASTSSH: "Doing something after copying" | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
user: ${{ secrets.SERVER_USER }} | |
pass: ${{ secrets.SERVER_PASSWORD }} | |
scp: | | |
./code.zip => /opt/app/zip/code.zip | |
last_ssh: | | |
ls | |
- name: 打印作业状态 🍏 | |
run: echo "🍏 This job's status is ${{ job.status }}." | |
publish_dev_code: | |
runs-on: ubuntu-latest | |
# needs: back_java # 确保在备份代码作业成功后才执行 | |
steps: | |
- name: 打印信息 🎉 | |
run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." | |
- name: 打印操作系统信息 🐧 | |
run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" | |
- name: 打印分支和仓库信息 🔎 | |
run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." | |
- name: 检查仓库代码 👁︎ | |
uses: actions/checkout@v4 | |
- name: 打印仓库文件列表 📦 | |
run: ls ${{ github.workspace }} | |
- name: 查看 zip 文件 📦 | |
run: ls | |
# - name: 清空之前的旧文件夹 | |
# uses: easingthemes/[email protected] | |
# with: | |
# SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
# REMOTE_USER: ${{ secrets.DEV_SERVER_USER }} | |
# REMOTE_HOST: ${{ secrets.DEV_SERVER_HOST }} | |
# REMOTE_PORT: 22 | |
# SCRIPT_AFTER: | | |
# cd /opt/app/test | |
# rm -rf * # 删除目录下所有文件和子目录 | |
- name: 删除之前的文件 | |
uses: cross-the-world/ssh-scp-ssh-pipelines@latest | |
env: | |
LASTSSH: "Doing something after copying" | |
with: | |
host: ${{ secrets.DEV_SERVER_HOST }} | |
user: ${{ secrets.DEV_SERVER_USER }} | |
pass: ${{ secrets.DEV_SERVER_PASSWORD }} | |
last_ssh: | | |
cd /opt/app/test | |
rm -rf * # 删除目录下所有文件和子目录 | |
- name: 打包代码成 ZIP 文件 📦 | |
id: deploy | |
run: | | |
zip -r publish.zip . -x "*.git*" | |
echo "::set-output name=zip-path::publish.zip" | |
- name: 推送到测试服务器备份 zip 文件夹 | |
uses: cross-the-world/ssh-scp-ssh-pipelines@latest | |
env: | |
LASTSSH: "Doing something after copying" | |
with: | |
host: ${{ secrets.DEV_SERVER_HOST }} | |
user: ${{ secrets.DEV_SERVER_USER }} | |
pass: ${{ secrets.DEV_SERVER_PASSWORD }} | |
scp: | | |
./publish.zip => /opt/app/zip | |
last_ssh: | | |
ls | |
- name: 推送到测试服务器备份 zip 文件夹 | |
uses: cross-the-world/ssh-scp-ssh-pipelines@latest | |
env: | |
LASTSSH: "Doing something after copying" | |
with: | |
host: ${{ secrets.DEV_SERVER_HOST }} | |
user: ${{ secrets.DEV_SERVER_USER }} | |
pass: ${{ secrets.DEV_SERVER_PASSWORD }} | |
scp: | | |
./publish.zip => /opt/app/test | |
last_ssh: | | |
ls | |
- name: 解压文件并运行 Docker Compose | |
uses: easingthemes/[email protected] | |
with: | |
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
REMOTE_USER: ${{ secrets.DEV_SERVER_USER }} | |
REMOTE_HOST: ${{ secrets.DEV_SERVER_HOST }} | |
REMOTE_PORT: 22 | |
SCRIPT_AFTER: | | |
cd /opt/app/test | |
unzip publish.zip | |
mvn clean install | |
docker-compose -f docker-compose.env.yml up -d | |
docker-compose -f docker-compose.service.yml up -d | |
- name: 打印作业状态 🍏 | |
run: echo "🍏 This job's status is ${{ job.status }}." |