name: Vue Project Deploy With Docker Image on: push: branches: [ master ] paths-ignore: - '**/README.md' - '**/*.yml' tags: [release-v*] pull_request: branches: [master] # 并发组 concurrency: group: vue-deploy cancel-in-progress: true jobs: build_vue: runs-on: ubuntu-latest defaults: run: working-directory: front strategy: matrix: node-version: [12.x] steps: - uses: actions/checkout@v4 - name: User Node.js ${{natrix.node-version}} users: actions/setup=node@v1 with: node-version: ${{matrix.node-version}} - name: npm Build run: | npm install npn run build - uses: actions/upload-artifact@v2 with: name: distfile path: front/dist docker_image: needs: [build_vue] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/download-artifact@v2 with: name: distfile path: wwwroot - name: Push to Docker Hub uses: docker/build-push-acation@v1 with: username: ${{secrets.DOCKER_HUB_NAME}} password: ${{secrets.DOCKER_HUB_PASSWORD}} repository: jianboy/vue_demo tags: test # 构建镜像,推送镜像到仓库,并创建tag,部署 deploy: needs: [docker_image] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: | docker login -u ${{secrets.DOCKER_HUB_NAME}} -p ${{secrets.DOCKER_HUB_PASSWORD}} docker-compose -f docker-compose.yml up -d # 登录GitHub Container Registry,推送镜像到仓库 - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} # 登录远程服务器,拉取代码,部署 deploy2: runs-on: ubuntu-latest steps: - run: | ssh -p 2222 jianboy@xx.com cd ~/xx/xx/xx/ git fetch origin master git reset --hard origin/master docker-compose -f docker-compose.yml up -d