vue_deploy.yml 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. name: Vue Project Deploy With Docker Image
  2. on:
  3. push:
  4. branches: [ master ]
  5. paths-ignore:
  6. - '**/README.md'
  7. - '**/*.yml'
  8. tags: [release-v*]
  9. pull_request:
  10. branches: [master]
  11. # 并发组
  12. concurrency:
  13. group: vue-deploy
  14. cancel-in-progress: true
  15. jobs:
  16. build_vue:
  17. runs-on: ubuntu-latest
  18. defaults:
  19. run:
  20. working-directory: front
  21. strategy:
  22. matrix:
  23. node-version: [12.x]
  24. steps:
  25. - uses: actions/checkout@v4
  26. - name: User Node.js ${{natrix.node-version}}
  27. users: actions/setup=node@v1
  28. with:
  29. node-version: ${{matrix.node-version}}
  30. - name: npm Build
  31. run: |
  32. npm install
  33. npn run build
  34. - uses: actions/upload-artifact@v2
  35. with:
  36. name: distfile
  37. path: front/dist
  38. docker_image:
  39. needs: [build_vue]
  40. runs-on: ubuntu-latest
  41. steps:
  42. - uses: actions/checkout@v4
  43. - uses: actions/download-artifact@v2
  44. with:
  45. name: distfile
  46. path: wwwroot
  47. - name: Push to Docker Hub
  48. uses: docker/build-push-acation@v1
  49. with:
  50. username: ${{secrets.DOCKER_HUB_NAME}}
  51. password: ${{secrets.DOCKER_HUB_PASSWORD}}
  52. repository: jianboy/vue_demo
  53. tags: test
  54. # 构建镜像,推送镜像到仓库,并创建tag,部署
  55. deploy:
  56. needs: [docker_image]
  57. runs-on: ubuntu-latest
  58. steps:
  59. - uses: actions/checkout@v4
  60. - run: |
  61. docker login -u ${{secrets.DOCKER_HUB_NAME}} -p ${{secrets.DOCKER_HUB_PASSWORD}}
  62. docker-compose -f docker-compose.yml up -d
  63. # 登录GitHub Container Registry,推送镜像到仓库
  64. - name: Login to GitHub Container Registry
  65. uses: docker/login-action@v3
  66. with:
  67. registry: ghcr.io
  68. username: ${{ github.repository_owner }}
  69. password: ${{ secrets.GITHUB_TOKEN }}
  70. # 登录远程服务器,拉取代码,部署
  71. deploy2:
  72. runs-on: ubuntu-latest
  73. steps:
  74. - run: |
  75. ssh -p 2222 jianboy@xx.com
  76. cd ~/xx/xx/xx/
  77. git fetch origin master
  78. git reset --hard origin/master
  79. docker-compose -f docker-compose.yml up -d