Hi from Selys-Africa

My name is CiCd

I can help you deploy quickly your code hosted on github to your vps using your ssh creds. It's easy like deploy and refresh to see changes


Steps to test the process

  1. Go to the repos
  2. Modify this content
  3. Check your modif is ok
  4. Commit and push to the main branch
  5. Come here and refresh.
  6. Enjoy! You should see your new update

Tiny CiCd

Description

This is not a full fledged CiCd tools. This is a simple CiCd that can be used to deploy a simple application to a server using ssh.

Code is not tested before deployment. You may be aware of the consequences when pushing to the main branch.

Of course, you can add more steps to the github action to test your code before deploying it.

Feature improvements

How to use

  1. Create a new repository
  2. Copy the contents of .github folder to your repository .github folder
  3. You should let github set the master branch name to main. If you have already created the repository, you can change the branch name from settings, otherwise do 4.
  4. If not possible to change the branch name, you can change the branch name in the .github/workflows/deploy-from-main.yml file.
  5. Locate the script section of the .github/workflows/deploy-from-main.yml file and change the commands required to deploy your application.

Ex:

name: Deploy to VPS from main branch on push

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Deploy to VPS
        uses: appleboy/ssh-action@v1.0.0
        with:
          host: ${{ secrets.VPS_HOST }}
          username: ${{ secrets.VPS_USERNAME }}
          password: ${{ secrets.VPS_PASSWORD }}
          script: | # This is the script that will be executed on the server in that order
            cd /var/www/cicd
            git pull
            git checkout main
            git reset --hard origin/main
          # Your script start below
          # Your script end here
            echo "Deployed at $(date)"

How it works

When you push to the main branch, the github action will be triggered. It will checkout the code and run the script in the server using ssh with the credentials you provided on the github secrets.

Note due to github freee plan limitations, we must set secrets for each private repo we create. If you have multiple private repos, you must set the secrets for each repo. Organization wide secrets are not available for free plan. Only for paid plans.

If target repos are public, we can use organization wide secrets.

Selys-Africa contribution

When using this tiny cicd, please follow:

  1. Create a new repository with always main as the default branch name.
  2. Follow what is described in How to use section.
  3. Change the branch name in the .github/workflows/deploy-from-main.yml file to dev.
  4. Create a new branch from main and name it dev. This branch will be used for development will be targeted by the cicd.
  5. Create {featureName} branches from dev and merge them to dev when done.
  6. Create {bugfixName} branches from dev and merge them to dev when done.
  7. Redo 4 and 5 until you finish all features or bug fixes.

Note this is only suitable development workflow. For production, wait a bit !

Disclaimer

You should know that you're responsible for the code you push to the main branch. This is not a full fledged CiCd. This is a simple CiCd that can be used to deploy a simple application to a server using ssh.

Script your provided will be executed in the server with the power of the user you provided. So be careful when writing the script what user creds you provide.

Code is not tested before deployment. You may be aware of the consequences when pushing to the main branch.

Code is intellectual property of Selys-Africa

Justin Dah-kenangnon authored

appleboy/ssh-action is used to run remote ssh

Other References