I'm trying to write github actions workflow with this steps:
- Connect to Digital ocean over ssh
- Navigate to
/saver
folder - Pull updates from
main
branch - Install dependencies and build project
My current code looks this way
name: Deploy app
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-20.04
steps:
- name: Deploy to Digital Ocean
uses: appleboy/ssh-action@master
with:
host: ${{secrets.SSH_HOST}}
key: ${{secrets.SSH_KEY}}
username: ${{secrets.SSH_USERNAME}}
passphrase: ${{secrets.SSH_PASSPHRASE}}
script: |
cd saver
mkdir test #just to check if it connects and creates folder
- name: Checkout
uses: actions/checkout@v3
with:
ref: main
- name: Pull changes
run: git pull
- name: Install client dependencies
run: npm run client:prodinstall
- name: Build client
run: npm run client:build
- name: Install server dependencies
run: npm run server:prodinstall
- name: Install server dependencies
run: npm run server:build
As I see in logs in successfully logs to Digital ocean. On server I see folder test
. but git pull doesn't work. I see
Run git pull
Already up to date.
But if I navigate by myself to DO server and run git pull I get new changes.
What's wrong?
UPDATE:
Current config
name: Deploy app
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Executing remote ssh commands using password
uses: appleboy/ssh-action@v0.1.7
env:
SSH_KEY: ${{ secrets.SSH_KEY }}
GIT_SSH_COMMAND: 'ssh -Tv'
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
script: |
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa
host='github.com'
hosts="$(dig +short "$host" | grep -v '\.$' | sed -z 's|\n|,|g')$host"
ssh-keyscan -H "$hosts" > ~/.ssh/known_hosts
cd [appname]
git pull origin main
pm2 restart [appname]
- name: Install
run: npm run build
- I copied public key
cat .ssh/id_rsa.pub
and put it https://github.com/settings/keys - Ran
nano .ssh/authorized_keys
- Ran
chmod 700 .ssh/authorized_keys
- Copied key from server with
cat .ssh/id_rsa
- And saved it as secret SSH_KEY in repos settings
- Same with SSH_USERNAME and SSH_HOST
When I push repo I get this error
" > ~/.ssh/id_rsa
host='github.com'
hosts="$(dig +short "$host" | grep -v '\.$' | sed -z 's|\n|,|g')$host"
ssh-keyscan -H "$hosts" > ~/.ssh/known_hosts
cd [appname]
git pull origin main
pm2 restart [appname]
======END======
err: # 140.82.121.4:22 SSH-2.0-babeld-30fa67d5
err: # 140.82.121.4:22 SSH-2.0-babeld-30fa67d5
err: # 140.82.121.4:22 SSH-2.0-babeld-30fa67d5
err: # 140.82.121.4:22 SSH-2.0-babeld-30fa67d5
err: # 140.82.121.4:22 SSH-2.0-babeld-30fa67d5
err: git@github.com: Permission denied (publickey).
err: fatal: Could not read from remote repository.
err: Please make sure you have the correct access rights
err: and the repository exists.