Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
No Result
View All Result
Home Google Cloud

Setup CI/CD Workflow with GitHub Actions

by Cloudbooklet
2 years ago
in Google Cloud, AWS, Linux
Setup Ci/Cd Workflow With Github Actions
ShareTweetSendShare
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

Setup and configure CI/CD workflow with GitHub actions to deploy source code to remote server. In this guide you are going to learn how to configure GitHub actions to make automated deployments to server once a push is made. We will setup SSH keys to authenticate with the server. Prerequisites Follow this guide to create […]

ADVERTISEMENT

Setup and configure CI/CD workflow with GitHub actions to deploy source code to remote server.

In this guide you are going to learn how to configure GitHub actions to make automated deployments to server once a push is made. We will setup SSH keys to authenticate with the server.

Prerequisites

Follow this guide to create new user and configure SSH keys which is necessary for GitHub to make secure connections with your server.

ADVERTISEMENT

Once you have completed the above step you can proceed to GitHub to configure actions.

You might also like

&Quot; Systemd Service On Linux

How to Create a New systemd Service on Linux: A Step-by-Step Guide

3 months ago
List Groups In Linux

How to List Groups in Linux: A Guide for Beginners

3 months ago

Take note of the following details from the above setup.

  1. Username: The new user you created using adduser command.
  2. Hostname: This is the IP address of your server.
  3. Private key: This key is created automatically using the ssh-keygen command. Make sure the key is in RSA format which begins with -----BEGIN RSA PRIVATE KEY-----.

These 3 details are necessary to make connection to the server from GitHub.

ADVERTISEMENT

Setup Secrets

Login to your GitHub account and go to your repository.

Navigate to Settings >> Secrets.

ADVERTISEMENT

Click New repository secret.

In the Name add SSH_HOST and in value enter the IP address of your server.

ADVERTISEMENT

Click Add secret.

Again click New repository secret.

ADVERTISEMENT

In the Name add SSH_USERNAME and in value enter the username you noted above which was created in the post mentioned in the prerequisites section.

Click Add secret.

Again click New repository secret.

In the Name add SSH_KEY and in value enter the private key you noted above which was created in the post mentioned in the prerequisites section.

Click Add secret.

Now you should have your secrets as shown below.

Github Secrets
Setup CI/CD Workflow with GitHub Actions 1

Once the secrets are in place you can setup actions.

Initiate Actions Workflow

Now click on the Actions tab.

You will see a list of workflows that can be configured by default.

Github Default Workflows
Setup CI/CD Workflow with GitHub Actions 2

You can click on Setup an workflow yourself.

You will see some default configurations here.

Configure Actions Workflow

You can name the workflow file as per your wish. I will name it as deploy.yml.

You can remove all workflows that was included by default.

Copy the below workflow and add it.

name: Identifier Name
on:
  push:
    branches: [ branch-name ]

jobs:
  deploy:    
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Deploy source-code
        uses: appleboy/scp-action@master
        env:
          HOST: ${{ secrets.SSH_HOST }}
          USERNAME: ${{ secrets.SSH_USERNAME }}
          PORT: 22
          KEY: ${{ secrets.SSH_KEY }}
        with:
          source: "*"
          target: "/path/in/your/server"

The above code will perform a deployment to your server when a push is made to a speck branch.

It deploys all the source code located in the root location of your repository. If you need to deploy any specific folder only your can configure it in the source directive.

Make sure the user has permissions on the server to perform deployment.

For example if you are using Nginx or Apache web server which runs using www-data user you need setup permissions and reset the permissions as shown below.

name: Identifier Name
on:
  push:
    branches: [ branch-name ]

jobs:
  deploy:    
    runs-on: ubuntu-latest
    steps:
      - name: Reset Permissions before deployment
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.SSH_HOST }}
          username: ${{ secrets.SSH_USERNAME }}
          key: ${{ secrets.SSH_KEY }}
          port: 22
          script: |
            sudo chmod -R 755 /path/in/your/server
            sudo chown -R username:username /path/in/your/server
            sudo setfacl -R -m u:www-data:rwx /path/in/your/server 

      - uses: actions/checkout@v2
      - name: Deploy source-code
        uses: appleboy/scp-action@master
        env:
          HOST: ${{ secrets.SSH_HOST }}
          USERNAME: ${{ secrets.SSH_USERNAME }}
          PORT: 22
          KEY: ${{ secrets.SSH_KEY }}
        with:
          source: "*"
          target: "/path/in/your/server"

      - name: Reset Permissions after deployment
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.SSH_HOST }}
          username: ${{ secrets.SSH_USERNAME }}
          key: ${{ secrets.SSH_KEY }}
          port: 22
          script: |
            sudo chmod -R 755 /path/in/your/server
            sudo chown -R www-data:www-data /path/in/your/server
            sudo setfacl -R -m u:username:rwx /path/in/your/server

The above deployment configuration configures the user to have full access over the folder for deployment and the configure access for the user www-data which is used by Apache and Nignx.

Once done click Start commit and click Commit new file to complete the setup.

Now you have a deployment configured to be executed whenever a push is made to the speicifc branch.

Conclusion

Now you have learned how to setup and configure GitHub actions workflow for CI/CD.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

Tags: CICDJenkins
Share2Tweet1SendShare
Cloudbooklet

Cloudbooklet

Comments 1

  1. Avatar Of Durgesh Durgesh says:
    2 years ago

    I have done all above the process but still it doesn’t going live whenever i push in master branch

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

Hostname In Linux

How to Modify the Hostname in Linux

3 months ago
Linux Systems

Linux systems Hacked with OpenSSH Malware

3 months ago
Install Iptables On Ubuntu

How to Install Iptables on Linux

3 months ago
Open Port In Linux

How to Open Port in Linux: Simple Step-by-Step Guide

3 months ago

Follow Us

Trending Articles

Ai Comic Generator

Best 10 AI Comic Generator: Create Comic book in Seconds

September 18, 2023

Amazon Prime Big Deal Days 2023: Best Deals

AI Statistics and Trends: What You Need to Know in 2023

Microsoft Unveils New Disc-Less Xbox Series X with Lift-to-Wake Controller

Create a Professional Website with Wix AI Website Builder

10 Best AI Song Generator in 2023 (Free and Paid)

Popular Articles

Ai Youtube Video Summarizers

9 Best AI YouTube Video Summarizers Online

August 24, 2023

10 NFT Art Generator: Create and Sell Your Own NFT Artwork

9 Best FREE AI Character Generators to Create Characters from Photo

How to Create and Customize Stunning Contact Poster on iPhone

10 Best AI Copywriting Tools That Will Boost Your Content Marketing

7 Best Deepswap AI Free Online Tools to Create FaceSwap Videos and Photos

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Cloudbooklet Logo

Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.

  • About
  • Contact
  • Disclaimer
  • Privacy Policy

Cloudbooklet © 2023 All rights reserved.

No Result
View All Result
  • News
  • Artificial Intelligence
  • Applications
  • Linux

Cloudbooklet © 2023 All rights reserved.