0

I am trying to copy my artifact to /var/www/build so it is served by nginx. Unfortunately, for some unknown reason it doesn't copy.

err: cp: cannot stat '/home/runner/work/investing/investing/client/build': No such file or directory

Perhaps cp is referencing the server instead of the host (runner)? Not sure but 100% time killer. Solution please.

name: CI/CD Pipeline

concurrency: production

on:
  push:
    branches: [main]

jobs:
  build-clientside:
    runs-on: ubuntu-latest
    steps:
      - name: Set CI environment variable to false
        run: echo "CI=false" >> $GITHUB_ENV

      - name: Checkout code
        uses: actions/checkout@v2

      - name: Setup Node.js
        uses: actions/setup-node@v2
        with:
          node-version: "14.x"

      - name: Install clientside dependencies
        run: |
          cd $GITHUB_WORKSPACE/client
          npm ci

      - name: Build clientside
        run: |
          cd $GITHUB_WORKSPACE/client
          npm run build

      - name: Publish artifact
        uses: actions/upload-artifact@v2
        with:
          name: client-build
          path: ${{ github.workspace }}/client/build/
          if-no-files-found: error

  deploy:
    needs: build-clientside
    runs-on: ubuntu-latest
    steps:
      - name: Download build artifact
        id: download
        uses: actions/download-artifact@v2
        with:
          name: client-build
          path: ${{ github.workspace }}/client/build/

      - name: 'Echo download path'
        run:  | 
            echo ${{steps.download.outputs.download-path}}
            cd ${{steps.download.outputs.download-path}}
            chmod u+rx ${{steps.download.outputs.download-path}}
            ls -la

      - name: Deployment
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.DROPLET_URL }}
          key: ${{ secrets.DROPLET_PEM_KEY }}
          username: root
          script: |
            rm -rf /var/www/build
            cp -R ${{steps.download.outputs.download-path}} /var/www/
            systemctl reload nginx 
            cd /root/investing 
            git reset --hard 
            git checkout main 
            git pull 
            docker-compose down --rmi local 
            docker-compose pull 
            docker-compose up -d
Michael Paccione
  • 2,467
  • 6
  • 39
  • 74
  • Clearly, the path is not valid i.e. `/home/runner/work/investing/investing/client/build`. Add a `pwd` along with `ls -l` after downloading the artifact. – Azeem Apr 23 '23 at 04:26
  • I verify the path in the - name: 'Echo download path' step. The path and file contents are correct in that step. – Michael Paccione Apr 23 '23 at 04:39
  • Oh, got it. You're copying through SSH. You need to use SCP. See https://github.com/appleboy/scp-action. Once you SSH into the remote server, that path becomes invalid as no artifacts is preset there. – Azeem Apr 23 '23 at 04:42
  • 1
    What @azeem wrote, copy the build artifact to the deployment host first. And: Why not download the artifact in the deployment script as well? Then you've got everything together and you don't need to negotiate between so many systems. – hakre Apr 23 '23 at 05:29
  • Thanks guys I'll give it a go. Don't do much devops so its been interesting... – Michael Paccione Apr 25 '23 at 19:31

1 Answers1

0

err: cp: cannot stat '/home/runner/work/investing/investing/client/build': No such file or directory

You're copying through SSH. You need to use SCP.

See https://github.com/appleboy/scp-action.

Once you SSH into the remote server, that path i.e. ${{steps.download.outputs.download-path}} becomes invalid as no artifacts is preset there. You need to SCP it first before running the SSH script.

Azeem
  • 11,148
  • 4
  • 27
  • 40
  • 1
    so it uploads it to /var/www/build/github/workspace/tmp instead of /var/www/build ... I have source: ${{ github.workspace }}/tmp/build/* and target: /var/www/build/ – Michael Paccione Apr 25 '23 at 22:34