This repository contains a simple Node.js RESTful API, containerized using Docker, with a CI/CD pipeline set up using GitHub Actions. The application is ready for deployment to cloud providers like AWS, Heroku, or DigitalOcean.
This project demonstrates a basic setup for a Node.js application with a focus on deployment. It includes:
- A simple Express.js API.
- Dockerfile for containerization.
- Docker Compose setup for local development.
- GitHub Actions workflow for CI/CD.
- Deployment scripts for cloud providers.
-
Clone the repository:
git clone https://github.com/kindrew/nodejs-api-deployment.git cd nodejs-api-deployment -
Install dependencies:
npm install
-
Start the application:
npm start
The application will run on
http://localhost:3000.
To run the application inside a Docker container:
-
Build the Docker image:
docker build -t nodejs-api-deployment . -
Run the Docker container:
docker run -p 3000:3000 nodejs-api-deployment
For local development with Docker Compose:
-
Start the services:
docker-compose up --build
-
The application will be accessible at
http://localhost:3000.
This project includes a GitHub Actions workflow that:
- Installs dependencies.
- Builds and tests the application.
- Builds a Docker image and pushes it to DockerHub.
- Deploys the application to a cloud provider.
The CI/CD pipeline is triggered on every push to the main or staging branches.
The workflow is defined in .github/workflows/ci.yml. It performs the following steps:
- Checkout code: Retrieves the code from the repository.
- Set up Node.js: Installs the specified Node.js version.
- Install dependencies: Runs
npm installto install project dependencies. - Build Docker image: Builds the Docker image for the application.
- Push Docker image: Pushes the Docker image to DockerHub.
- Deploy: Deploys the application to the specified cloud provider.
This project includes a sample deployment script for AWS Elastic Beanstalk.
-
Ensure that you have the AWS CLI and Elastic Beanstalk CLI installed.
-
Run the deployment script:
./deploy.sh
This script builds the Docker image, pushes it to AWS ECR, and deploys the application using Elastic Beanstalk.
Environment variables are managed using a .env file. Ensure that your deployment environment securely handles these variables.
Contributions are welcome! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch.
- Make your changes and commit them.
- Push to your fork and submit a pull request.