Github CI/CD reuse step

Viewed 29

I'm kinda beginner with CI/CD, but I wrote a code that deploys Vue/Vite project to Ubuntu VPS. But, it's not as it should be. So what am I doing actually?

First as usual, installing the project and building it.

jobs:
  build:
    name: "Build"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Install
        run: yarn

      - name: Build
        run: yarn build

So the problem is when that passes. I'm connecting to ssh like:

deploy:
    name: "Deploy"
    needs: project_setup
    runs-on: ubuntu-latest
    steps:
      - name: Deploy to server
        uses: appleboy/ssh-action@master
        env:
          GIT_REPO: Comet-Frontend
          GIT_SSH: ${{ github.repositoryUrl }}
        with:
          host: ${{ secrets.VPS_IP }}
          username: ${{ secrets.VPS_USER }}
          password: ${{ secrets.VPS_PASSWORD }}
          port: ${{ secrets.VPS_PORT }}
          envs: GIT_SSH, GIT_REPO

and at the very bottom:

script: |
            cd /var/www/vue
            git pull
            ls
            yarn
            yarn build
            cp -R /root/Frontend/dist /var/www/vue

So I would like to define ssh connection once and run those scripts separately with different step names. Is that possible or I have to connect to ssh for every step?

1 Answers

If each step needs SSH to access either a remote repository URL or your VPS target server, then yes, you would need SSH to each step.

The alternative being to copy a deployment script to the server (through SSH): the steps included in that script could be executed directly on that server (where the script has been copied). No need for SSH then for that script execution, since it is already at target.

Related