Table of contents
No headings in the article.
What is Github Actions:
GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline.
You can create workflows that build and test every pull request to your repository, or deploy merged pull requests to production.
We need to install
Docker,
Docker-compose,
NVM,
Yarn on the remote server where the API has to be deployed.
Lets start with Docker installation:-
1- Installation of Docker:-
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
sudo apt update
apt-cache policy docker-ce
sudo apt install docker-ce
2- Docker compose Installation:-
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
3- NVM Installation (Subject to the requirement of the project):-
sudo apt install curl
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.bashrc
Install LTS node:-
nvm install --lts
nvm use --lts
4- Yarn Installation (Subject to the requirement of the project):-
npm install --global yarn
5- SSH Github Connection:-
Create an SSH
key in the server through
ssh-keygen
the command:Paste the rsa_pub key to GitHub Secret. follow these steps--
In the upper-right corner of the page, click your profile photo, then click Settings.
In the "Access" section of the sidebar, click SSH and GPG keys.
Click New SSH key or Add SSH key.
6- Clone Repo link with ssh link:-
git clone
7- Github actions connection with the server:-
Paste the public key in authorized_keys, which we created on 5th step.
After that, we need to Paste the private key under the repository setting.
Under secrets (GitHub actions) we need to paste the private key.
All set for GitHub action connection.
8- For the Github action YAML file, We need to click on GitHub actions:-
Then, Click on set up a workflow yourself. And paste this YAML. we only need some changes to the live host, username, secret, and script commands.
# This is a basic workflow to help you get started with Actions.
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Runs a single command using the runners shell
- name: Deploy to dev EC2, (Git pull and docker compose up)
uses: appleboy/ssh-action@master
with:
host: ${{YOUR_HOST_IP}}
username: ubuntu
key: ${{secrets.TEST}}
envs: GITHUB_SHA
script: |
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
cd pedalsup-backend-guide
git pull
yarn docker:dev-ga
Thank you for reading:)