|
| 1 | +# 部署到服务器 |
| 2 | +name: Deploy-ESC |
| 3 | + |
| 4 | +on: |
| 5 | + push: # 推送的时候触发 |
| 6 | + branches: [ "master" ] # 推送的分支 |
| 7 | + # Publish semver tags as releases. |
| 8 | + tags: [ 'v*.*.*' ] |
| 9 | + # 手动触发部署 |
| 10 | + workflow_dispatch: |
| 11 | + pull_request: |
| 12 | + branches: [ "next" ] |
| 13 | + |
| 14 | +env: |
| 15 | + # 仓库地址 |
| 16 | + REGISTRY: registry.cn-hangzhou.aliyuncs.com |
| 17 | + UserName: mmdapl |
| 18 | + |
| 19 | + |
| 20 | +jobs: |
| 21 | + ENV_Init: |
| 22 | + name: "环境初始化" |
| 23 | + runs-on: ubuntu-latest |
| 24 | + permissions: |
| 25 | + contents: read |
| 26 | + packages: write |
| 27 | + # This is used to complete the identity challenge |
| 28 | + # with sigstore/fulcio when running outside of PRs. |
| 29 | + id-token: write |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Checkout repository |
| 33 | + uses: actions/checkout@v3 |
| 34 | + |
| 35 | + - name: Setup Node And PNPM |
| 36 | + uses: actions/setup-node@v3 |
| 37 | + with: |
| 38 | + node-version: 14.20.1 |
| 39 | + # 缓存 pnpm 依赖 |
| 40 | + cache: pnpm |
| 41 | + |
| 42 | + - name: Login Docker |
| 43 | + run: |
| 44 | + docker version; |
| 45 | + # 登录阿里云镜像仓库 |
| 46 | + docker login --username=${{ env.UserName }} --password=${{ secrets.Docker_Password }} ${{env.REGISTRY}} |
| 47 | + |
| 48 | + - name: PNPM Install |
| 49 | + uses: pnpm/action-setup@v2 |
| 50 | + with: |
| 51 | + version: 7 |
| 52 | + # 使用 pnpm 安装依赖 |
| 53 | + run_install: true |
| 54 | + |
| 55 | + Build_Service: |
| 56 | + runs-on: ubuntu-latest |
| 57 | + permissions: |
| 58 | + contents: read |
| 59 | + packages: write |
| 60 | + # This is used to complete the identity challenge |
| 61 | + # with sigstore/fulcio when running outside of PRs. |
| 62 | + id-token: write |
| 63 | + |
| 64 | + steps: |
| 65 | + ## 构建镜像并推送 |
| 66 | + - name: Build And Push Docker image |
| 67 | + run: |
| 68 | + PROXY_DOMAIN=true pnpm image |
| 69 | + |
| 70 | + # 列出所有镜像 |
| 71 | + - name: Docker Images And Container List |
| 72 | + run: |
| 73 | + docker images |
| 74 | + echo "-----------正在运行的服务--------" |
| 75 | + docker ps |
| 76 | + |
| 77 | + Deploy_ESC: |
| 78 | + name: "ESC服务更新" |
| 79 | + runs-on: ubuntu-latest |
| 80 | + permissions: |
| 81 | + contents: read |
| 82 | + packages: write |
| 83 | + # This is used to complete the identity challenge |
| 84 | + # with sigstore/fulcio when running outside of PRs. |
| 85 | + id-token: write |
| 86 | + |
| 87 | + steps: |
| 88 | + - name: 读取当前版本号 |
| 89 | + id: version |
| 90 | + uses: ashley-taylor/read-json-property-action@v1.0 |
| 91 | + with: |
| 92 | + path: ./package.json |
| 93 | + property: version |
| 94 | + # 拉取镜像,更新服务 |
| 95 | + - name: Pull Image And Update ESC |
| 96 | + uses: appleboy/ssh-action@master |
| 97 | + with: |
| 98 | + host: ${{ secrets.Server_Host }} |
| 99 | + port: ${{ secrets.Server_Port }} |
| 100 | + username: ${{ secrets.Server_UserName }} |
| 101 | + password: ${{ secrets.Server_Password }} |
| 102 | + script: |
| 103 | + docker images; |
| 104 | + echo "-----------正在运行的服务--------"; |
| 105 | + docker ps; |
| 106 | + cd /service && git reset --hard && git pull origin master; |
| 107 | + bash ./scripts/book_doc.deploy.sh jsc v${{steps.version.outputs.value}} ; |
0 commit comments