Github Actions Artifact build wont successfully copy

704 Views Asked by At

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
1

There are 1 best solutions below

1
On BEST ANSWER

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.