Skip to content

Instantly share code, notes, and snippets.

@fajarwz
Created October 13, 2023 03:34
Show Gist options
  • Save fajarwz/e76c92bdeac3c6a91e351a8334d417a6 to your computer and use it in GitHub Desktop.
Save fajarwz/e76c92bdeac3c6a91e351a8334d417a6 to your computer and use it in GitHub Desktop.
notes for CD with Github Actions

How to create CD with Github Actions

  • using appleboy/ssh-action@master for cd
  • see cd.yml for the yml example
  • make sure the SSH_KEY is correct. Use the SSH private key. create SSH key in your server and copy the private key to Github Secrets
  • make sure to write your public key to authorized keys in server. you can use this command to do that: cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
  • make sure that the server dont ask password while we git pulling it manually. Use this command: "git config credential.helper store" or "git config --global credential.helper store" to store the git credential in cache. after we once again pulling the repo in the server, the git cache our credential. with that when github actions try to pull the repo automatically, it doesnt need to write credentials
name: Continuous Deployment
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: SSH and deploy app
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd ~/forum-api
git pull origin master
npm install
npm run migrate up
pm2 restart forum-api
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment