Day-23 Project Title: Hosting a Node.js Todo Application on a Docker Container with CI/CD Pipeline and Nginx Reverse Proxy(Part-2)
Project Overview:
This project involves hosting a Node.js todo application on a Docker container using Nginx as a reverse proxy. The project includes setting up a CI/CD pipeline to automate the installation of dependencies and deployment of the application on the container.
Project Features:
The project includes the following features:
Creation of a Dockerfile to build the Docker image for the application
Setting up a pipeline on a CI/CD platform to automate the installation of dependencies and deployment of the application on the container
Configuration of Nginx as a reverse proxy to forward requests from the web server to the Node.js server running on the container
Testing of the website by going to the URL specified by the client
Project Prerequisites:
Before starting the project, the following prerequisites are required:
A Docker installation on the system
A GitHub account to clone the project repository
An account on a CI/CD platform such as Jenkins, CircleCI, or GitHub Actions to create the pipeline
Project Steps:
- Install Docker & Jenkins on the server where you want to host the website.
apt-get update && apt-get install docker.io
sudo usermod -aG docker jenkins
sudo systemctl restart jenkins
also set up Jenkins using your credential and make it ready.
Clone the
node-todo-cd
repository from Git using a docker file.Create a new file called
Dockerfile
in the root directory and install nginx and clone the prerequisite of the project
# Pull base image
FROM ubuntu
# Install nginx, vim, and git and create website configuration
RUN apt-get update && \
apt-get install -y nginx vim git && \
mkdir /website /etc/website && \
rm -rf /etc/nginx/sites-available/default ; \
rm -rf /etc/nginx/sites-enabled/default ; \
echo "daemon off;" >> /etc/nginx/nginx.conf && \
sed -i '/^deamon/d' /etc/nginx/nginx.conf && \
git clone https://github.com/LondheShubham153/node-todo-cicd.git /etc/website
COPY arsfile /etc/nginx/sites-available/
RUN ln -s /etc/nginx/sites-available/* /etc/nginx/sites-enabled/
# Expose port 80
EXPOSE 80
# Start nginx when container starts
CMD ["nginx"]
- Create an
nginx. conf
file in the root directory of the project and add the following lines to it:
- Create a pipeline for this and try to build it.
Now build the Project.
++++++++++++++++++++++++++++++++++++++++++++++++
For Calculator app
pipeline {
agent any
stages {
stage("build image") {
steps {
sh 'docker build -t image1 .'
}
}
stage("create container") {
steps {
sh 'docker run -d -p 80:80 --name Abhijeet_cont image1'
}
}
stage("start nginx service") {
steps {
sh 'docker exec Abhijeet_cont service nginx start'
}
}
stage("Install dependencies") {
steps {
sh 'docker exec Abhijeet_cont apt update'
sh 'docker exec Abhijeet_cont apt-get install -y python3-venv'
sh 'docker exec Abhijeet_cont sh -c "cd /etc/calculator && python3 -m venv env && . env/bin/activate && pip install flask==2.2.3 Jinja2==3.1.2 Werkzeug==2.2.3 MarkupSafe==2.1.2 gunicorn==19.5.0 gevent"'
}
}
stage("start app") {
steps {
sh 'docker exec Abhijeet_cont sh -c "cd /etc/calculator && . /etc/calculator/env/bin/activate && python app.py &"'
}
}
}
}
- Verify that the container is running by going to
http://localhost
orhttp://<your_server_ip>
in a web browser.
- Verify that the container is running by going to
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++