I want to auto deploy my private repository on my VPS whenever I push changes to my main branch. My yaml file looks like this:
name: push-and-deploy-to-server
on:
push:
branches: [ main ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: checkout repo
uses: actions/checkout@v2
- name: ssh and deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: 22
script: |
git pull origin main
git status
npm install --only=prod
pm2 restart index.js
this is not working, I get the following error:
err: fatal: could not read Username for 'https://github.com': No such device or address
When ssh-ing into my server and cloning the repo myself, it asks for my username and password (access token). When I provide it, it works, but with the yaml file, it doesnt.
How can I clone and deploy a private repo? It’s a nodejs project btw.
2
Answers
Considering your setup
What does your current configuration and github secrets setup do?
appleboy/ssh-action@master
ssh’s into your VPSgit pull origin main
in your VPS.Issue what you have is that your VPS is not authenticated to access your repository.
You have multiple options.
${{ secrets.SSH_USERNAME }}
and authenticate that user against github using your Github Personal access token which you can generate under your https://github.com/settings/tokens giving it a read repo permissions. Then test that you can clone your repo into VPS if so then your next build will succeed.${{ secrets.SSH_USERNAME }}
and add it under your repository settings Deploy keys. When using deploy key, you need to make sure that your repository remote in vps is using[email protected]:<username>/<repository>.git
git url nothttps
url.appleboy/scp-action
step
beforeappleboy/ssh-action
and copy all contents from current directory to your VPS and then run yournpm install
etc. withappleboy/ssh-action
.You proceed may work if you have git installed on your server. But the scp project can also deploy the code directly to your server.
I used an IP address instead of a domain name, cos I felt like my hosting service was screwing with me.
Check out this URL for more details