GithubHelp home page GithubHelp logo

hgschandeepa / nodejs-rest-api-ec2 Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 1.0 26 KB

Auto Deploy Node.js REST API on AWS EC2 | CI/CD Pipeline using GitHub Actions

Home Page: https://medium.com/@saminchandeepa/auto-deploy-node-js-rest-api-on-aws-ec2-ci-cd-pipeline-using-github-actions-031be66824d1

JavaScript 100.00%
aws-ec2 ci-cd github github-actions githubaction-workflow nginx pm2

nodejs-rest-api-ec2's Introduction

Node.js REST API Deployment on AWS EC2 with GitHub Actions CI/CD Pipeline

This repository demonstrates a streamlined approach to deploying a Node.js REST API on an AWS EC2 instance using GitHub Actions for continuous integration and continuous deployment (CI/CD).

Overview

In this project, we utilize GitHub Actions workflows to automate the CI/CD pipeline for deploying changes to our Node.js application on an EC2 instance. The workflow consists of:

  • Continuous Integration (CI): Automatically building and testing the application on each push to the main branch.
  • Continuous Deployment (CD): Automatically deploying changes to the EC2 instance upon successful completion of CI.

Setup Instructions

Follow these steps to set up the deployment pipeline for your Node.js REST API on AWS EC2:

  1. Create an EC2 Instance:

    • Create a new EC2 instance in your AWS account or use an existing one.
    • Generate or use an existing SSH key pair for accessing the instance.
  2. Git Repository Setup:

    • Create a new Git repository and push your Node.js code to it.
  3. GitHub Actions Setup:

    • Navigate to your repository settings on GitHub and select Actions.
    • Add a self-hosted runner and follow the setup instructions.
  4. Environment Setup for GitHub Actions:

    • Create a .env file with your environment variables and add them as secrets in your GitHub repository settings.
  5. CI/CD Workflows:

    • Define CI/CD workflows in the .github/workflows directory.
    • Customize workflows to suit your project requirements.
  6. Environment Setup in EC2 Instance:

    • Install Node.js and Nginx on your EC2 instance.
    • Configure Nginx as a reverse proxy for your Node.js application.
    • Install PM2 to manage your Node.js process.

Workflow Explanation

  • CI Process: On each push to the main branch, the workflow executes CI tasks such as checking out code, setting up the Node.js environment, installing dependencies, and running tests (if applicable).
  • CD Process: Upon successful CI, the workflow triggers CD tasks including SSH into the EC2 instance, pulling the latest changes, restarting the Node.js application, and verifying deployment.

Directory Structure

  • src/: Contains the source code for the Node.js application.
  • .github/workflows/: Contains CI/CD workflow configuration files.
  • .env: Stores environment variables for the application.
  • server.js: Entry point for the Node.js application.
  • package.json: Dependency configuration for npm.

Usage

  1. Clone the repository:

    git clone https://github.com/HGSChandeepa/nodejs-rest-api-EC2
  2. Customize the Node.js application code in the server.js file according to your requirements.

  3. Push changes to the main branch. GitHub Actions will automatically trigger the CI/CD pipeline.

Contributions

Contributions to improve this CI/CD setup or add additional features are welcome! Feel free to submit pull requests or open issues.

License

This project is licensed under the MIT License.

nodejs-rest-api-ec2's People

Contributors

hgschandeepa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.