A simple Node.js project to demonstrate ### Build the Docker Image
To build the Docker image locally, run the following command in the project's root directory:
docker build -t node-ci-demo .To run the Docker container locally, use the following command:
docker run -d -p 3000:3000 --name node-ci-demo node-ci-demo
```ub Actions, Docker, and AWS.
## Prerequisites
- Node.js version 20.0.0 or higher
- Docker (for containerization)
## Installation
First, ensure you have the correct Node.js version installed. You can check your version with:
```bash
node --versionThen install the dependencies by running:
npm installTo start the application, run:
npm startThe application will be available at http://localhost:3000.
To run the tests, use:
npm testThis project uses GitHub Actions for continuous integration and deployment. The pipeline:
- Runs on Node.js 20.x and 21.x
- Installs dependencies
- Runs linting checks
- Executes tests
- Builds and pushes Docker image
- Deploys to AWS EC2
This project can be containerized using Docker.
To build the Docker image locally, run the following command in the project's root directory:
docker build -t node-ci-demo:latest .To run the Docker container locally, use the following command:
docker run -d -p 3000:3000 --name node-ci-demo node-ci-demo:latestTo stop and remove the container (if you need to rebuild and run again):
docker stop node-ci-demo
docker rm node-ci-demoThe application will be available at http://localhost:3000.
This project is configured with a CI/CD pipeline using GitHub Actions. The workflow is defined in .github/workflows/node.yml.
The pipeline includes the following jobs:
- build: Installs dependencies and runs tests for different Node.js versions.
- deploy: Deploys the application to an AWS EC2 instance using Docker.
The deployment process involves:
- Connecting to the EC2 instance via SSH.
- Stopping and removing any existing Docker containers.
- Pulling the latest code from the GitHub repository.
- Building a new Docker image.
- Running a new Docker container with the updated image.