In the development process, sometimes something that speeds up team performance is needed by most people.
One way to improve team performance is to create a CI/CD deployment. CI/CD deployment is a way for us to upload our work in a particular branch of git to the server automatically. Before getting into this material it would be nice if we understand the following terms:
CI/CD
CI/CD is a method for frequently delivering applications to customers by introducing automation into the application development stages. The main concepts associated with CI/CD are continuous integration, continuous delivery, and continuous deployment. CI/CD is a solution to the problem of integrating new code that can make development teams and operations greatly simplified.
In particular, CI/CD introduces continuous automation and continuous monitoring throughout the application lifecycle, from the integration and test phases to delivery and deployment. Together, these connected practices are often referred to as "CI/CD pipelines" and are supported by development and operations teams working together in agile DevOps approaches or site reliability engineering (SRE).
SSH
Secure Shell Protocol (SSH) is a cryptographic network protocol for operating network services securely over an insecure network.[1] Its most prominent application is remote login using the command line. SSH is commonly used by devOps or server administrators to process servers, for example to install applications, run applications, and so on.
Over time, SSH is also used for web application deployment (backend/front end) via CI/CD.
Deployment of SSH-Action CI/CD
Because I made the cover image of this article with the github logo, I made an example of how to implement a node.js application deployment using github workflow.
Create a file .github/workflow/filename.yml in your repository. then write the following code:
#ci/cd name
name: publish to server
#explains that it only runs when there is a push on the master branch
on:
push:
branches:
- masters
jobs:
deploy-intima:
runs-on: ubuntu-latest #Operating system used
steps:
- name: Uploading to server
uses: appleboy/ssh-action@master # package that we can use to run ssh
with: # We set all our secrets here for the action, these won't be shown in the action logs
host: ${{secrets.HOST}} #variable host / ip of your vps
username: ${{secrets. USER}} #your ssh user
password: ${{secrets. PASSWORD}} #your ssh password
port: ${{secrets. PORT}} #your ssh port
scripts: |
cd /to/path/application
git pull
PATH=${{secrets. NPM_BIN}}
npm install
pm2 restart app
I have written several explanations in the comment code above. Furthermore, for the script I will explain below:
1. cd /to/path/application is the way we go to directory our application
2. git pull is a way to pull changes from your repository
3. PATH=${{secrets.NPM_BIN}} is an option for nvm users to be able to run npm. While secrets are taken from the menu setting->secrets->actions in your github repository
4. npm install < /font> is for installing packages
5. pm2 restart application is to restart the application that we have deployed on at the start of the clone repository on the server