羽毛アクションCD構築

14103 ワード

羽毛アクションCD構築ホットスポット


  • 当初設計時프리티어 ec2コンテナを空にする깃 액션画像を作成latest画像の再配置を試みる

  • Prettyメモリ不足のため、構築時からブロックされています
  • 解決する

  • 羽毛動作構築後distフォルダをec 2へ転送
  • pm 2を再稼働する形で配備完了
  • name: CD
    
    on:
      push:
        tags:
          - "v*"
    jobs:
      wait-for-ci:
        runs-on: ubuntu-latest
        strategy:
          matrix:
            node-version: [16.x]
    
        steps:
          - name: Use Node.js ${{ matrix.node-version }}
            uses: actions/setup-node@v2
            with:
              node-version: ${{ matrix.node-version }}
              registry-url: "https://npm.pkg.github.com"
    
          - name: Wait for CI check to pass
            uses: fountainhead/action-wait-for-[email protected]
            id: wait-for-ci
            with:
              token: ${{ secrets.GITHUB_TOKEN }}
              checkName: build (16.x)
              ref: ${{ github.event.head }}
    
          - name: Stop workflow
            if: steps.wait-for-ci.outputs.conclusion != 'success'
            run: node -e 'process.exit(1)'
    
      image-push-scp-build-file:
        needs: wait-for-ci
        runs-on: ubuntu-latest
        strategy:
          matrix:
            node-version: [16.x]
    
        steps:
          - name: Checkout
            uses: actions/checkout@v2
    
          - name: Use Node.js ${{ matrix.node-version }}
            uses: actions/setup-node@v2
            with:
              node-version: ${{ matrix.node-version }}
              registry-url: "https://npm.pkg.github.com"
    
          - name: Install dependencies
            run: npm install
    
          - name: Run Build
            run: npm run build
    
          - name: Set env
            run: |
              ... // 정보 보호
    
          - name: Set up Docker Buildx
            uses: docker/setup-buildx-action@v1
    
          - name: Login to GitHub Container Registry
            uses: docker/login-action@v1
            with:
              registry: ghcr.io
              username: ${{ github.repository_owner }}
              password: ${{ secrets.CR_PAT }}
    
          - name: Build and push
            uses: docker/build-push-action@v2
            with:
              context: .
              file: ./Dockerfile
              target: prod
              push: true
              tags: |
                ghcr.io/${{ github.repository_owner }}/${{env.REPOSITORY_NAME}}:latest
                ghcr.io/${{ github.repository_owner }}/${{env.REPOSITORY_NAME}}:${{ env.RELEASE_VERSION }}
    
          - name: build file upload to ec2
            uses: garygrossgarten/github-action-scp@release
            with:
              local: ./dist
              remote: /home/ubuntu/volunteer-server/dist/
              host: ${{ secrets.HOST }}
              username: ${{ secrets.SSH_USER }}
              privateKey: ${{ secrets.SSH_KEY }}
              recursive: true
    
          - name: ec2 update
            uses: appleboy/ssh-action@master
            with:
              host: ${{ secrets.HOST }}
              username: ${{ secrets.SSH_USER }}
              key: ${{ secrets.SSH_KEY }}
              script: |
                export NVM_DIR=~/.nvm
                source ~/.nvm/nvm.sh
                pm2 restart 0 --update-env
    

    話題を付け加える

  • nvm権限の問題appleboy/ssh-action@masterスクリプト権限
  • リファレンス


    https://padawanr0k.github.io/posts/github/githubAction/
    https://github.com/appleboy/scp-action
    https://stackoverflow.com/questions/62863080/github-actions-err-bash-line-3-npm-command-not-found