dockergithubdocker-composegithub-actionsvps

CI/CD Github Workflow not finding build directory


I am currently writing my first CI/CD workflow with Github Actions.

I try to build the application inside the runners workspace and then only copy the docker-compose file and the .dist/ directory with the build artifacts to my vps and start a docker container there.

The build steps are successful, but I struggle to copy the build directory (./dist/*) to my vps. It tells me that the tar archive is empty...

here is my workflow

name: CI/CD Pipeline

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      # Checkout Repository to the runner's workspace.
      - name: Checkout repository
        uses: actions/checkout@v3
      # Set up Node.js on runner's workspace.
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 20.10.0

      # Install dependencies, build and test.
      - name: Install dependencies
        run: |
          npm ci

      - name: Build and test
        run: |
          npm run build

      - name: List Dist Contents
        run: ls -R ./dist

  deploy:
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Deploy to VPS
        uses: appleboy/scp-action@v0.1.7
        with:
          HOST: ${{ secrets.HOST }}
          USERNAME: ${{ secrets.USERNAME }}
          PORT: ${{ secrets.PORT }}
          KEY: ${{ secrets.SSH_KEY }}
          source: |
            ./dist/*
            ./docker-compose.prod.yml
          target: "/usr/src/app"

      - name: Execute remote deployment script
        uses: appleboy/ssh-action@master
        with:
          HOST: ${{ secrets.HOST }}
          USERNAME: ${{ secrets.USERNAME }}
          PORT: ${{ secrets.PORT }}
          KEY: ${{ secrets.SSH_KEY }}
          script: |
            # Change directory to the app folder
            cd /usr/src/app

            # Stop and remove the container
            docker-compose down

            # Set environment variables stored in Github secrets
            echo "VITE_BASE_URL=${VITE_BASE_URL}" > .env
            echo "DATABASE_URL=${DATABASE_URL}" > .env
            echo "NODE_PORT=${NODE_PORT}" > .env
            echo "SECRET_KEY=${SECRET_KEY}" > .env
            echo "REFRESH_SECRET_KEY=${REFRESH_SECRET_KEY}" > .env

            # start container and detach
            docker-compose up -d

The workflow fails with this message

drone-scp version: v1.6.14
tar all files into /tmp/bgHcjxzAcm.tar.gz
tar: empty archive
exit status 1

I logged the dist content right after the build step and it looks totally fine everythink is created. Not sure what iam doing wrong here.

UPDATE:

tried using one job.

name: CI/CD Pipeline

on:
  push:
    branches:
      - main

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest

    steps:
      # Checkout Repository to the runner's workspace.
      - name: Checkout repository
        uses: actions/checkout@v3
      # Set up Node.js on runner's workspace.
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 20.10.0

      # Install dependencies, build and test.
      - name: Install dependencies
        run: |
          npm ci

      - name: Build and test
        run: |
          npm run build

      - name: List Dist Contents
        run: ls -R ./dist

      - name: Deploy to VPS
        uses: appleboy/scp-action@v0.1.7
        with:
          HOST: ${{ secrets.HOST }}
          USERNAME: ${{ secrets.USERNAME }}
          PORT: ${{ secrets.PORT }}
          KEY: ${{ secrets.SSH_KEY }}
          source: |
            ./dist/*
            ./docker-compose.prod.yml
          target: "/usr/src/app"

      - name: Execute remote deployment script
        uses: appleboy/ssh-action@v1.0.3
        with:
          HOST: ${{ secrets.HOST }}
          USERNAME: ${{ secrets.USERNAME }}
          PORT: ${{ secrets.PORT }}
          KEY: ${{ secrets.SSH_KEY }}
          script: |
            # Change directory to the app folder
            cd /usr/src/app

            # Stop and remove the container
            docker-compose down

            # Remove old .env file
            rm .env

            # Set environment variables stored in Github secrets
            echo "VITE_BASE_URL=${VITE_BASE_URL}" > .env
            echo "DATABASE_URL=${DATABASE_URL}" > .env
            echo "NODE_PORT=${NODE_PORT}" > .env
            echo "SECRET_KEY=${SECRET_KEY}" > .env
            echo "REFRESH_SECRET_KEY=${REFRESH_SECRET_KEY}" > .env

            # start container and detach
            docker-compose up -d

Solution

  • Thanks to Azeem for the answer!

    I had to use Comma-Separated Values (CSV) for the source...

    here are the docs, should have red them. Sorry!