<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Devops projects]]></title><description><![CDATA[Devops projects]]></description><link>https://projects.hassandevops.com</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Apr 2026 10:34:56 GMT</lastBuildDate><atom:link href="https://projects.hassandevops.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to Run a .NET Project Manually and in Docker]]></title><description><![CDATA[In this guide, we’ll walk through two methods to run a .NET 6.0 application:

Running the application manually on your local machine.

Using Docker to containerize and run the application efficiently.


By the end, you’ll have a clear understanding o...]]></description><link>https://projects.hassandevops.com/how-to-run-a-net-project-manually-and-in-docker</link><guid isPermaLink="true">https://projects.hassandevops.com/how-to-run-a-net-project-manually-and-in-docker</guid><category><![CDATA[dotnet]]></category><category><![CDATA[Docker]]></category><dc:creator><![CDATA[Muhammad Hassan]]></dc:creator><pubDate>Mon, 18 Nov 2024 11:17:42 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1731928619347/619d0461-a635-4e41-a35d-ab405454e026.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this guide, we’ll walk through two methods to run a .NET 6.0 application:</p>
<ol>
<li><p>Running the application manually on your local machine.</p>
</li>
<li><p>Using Docker to containerize and run the application efficiently.</p>
</li>
</ol>
<p>By the end, you’ll have a clear understanding of how to set up and run the application in both environments.</p>
<hr />
<h2 id="heading-part-1-running-the-application-manually"><strong>Part 1: Running the Application Manually</strong></h2>
<p>Running a .NET application manually involves installing necessary tools, building the project, and running it locally. Let’s break this down step-by-step.</p>
<hr />
<h3 id="heading-step-1-install-prerequisites"><strong>Step 1: Install Prerequisites</strong></h3>
<p>Ensure you have the following installed:</p>
<ul>
<li><p><a target="_blank" href="https://dotnet.microsoft.com/download/dotnet/6.0"><strong>.NET SDK 6.0</strong></a> to build and run the application.</p>
</li>
<li><p>A terminal or command prompt (e.g., PowerShell, Bash).</p>
</li>
</ul>
<hr />
<h3 id="heading-step-2-navigate-to-the-project-directory"><strong>Step 2: Navigate to the Project Directory</strong></h3>
<p>Assume the project structure is as follows:</p>
<pre><code class="lang-plaintext">QRCode_CoreMvc/
├── QRCode_UI/
│   ├── QRCode_UI.csproj
├── QRCode_CoreMvc.sln
├── Dockerfile
</code></pre>
<p>Navigate to the project directory:</p>
<pre><code class="lang-plaintext">cd QRCode_CoreMvc
</code></pre>
<hr />
<h3 id="heading-step-3-restore-dependencies"><strong>Step 3: Restore Dependencies</strong></h3>
<p>Run the following command to restore the project dependencies:</p>
<pre><code class="lang-plaintext">dotnet restore
</code></pre>
<p><strong>Explanation:</strong><br />This command:</p>
<ul>
<li><p>Downloads the required NuGet packages.</p>
</li>
<li><p>Resolves dependencies defined in the <code>.csproj</code> file.</p>
</li>
</ul>
<hr />
<h3 id="heading-step-4-build-the-project"><strong>Step 4: Build the Project</strong></h3>
<p>Compile the project using:</p>
<pre><code class="lang-plaintext">dotnet build
</code></pre>
<p><strong>Explanation:</strong><br />This step:</p>
<ul>
<li><p>Compiles the source code.</p>
</li>
<li><p>Generates binaries for your application.</p>
</li>
</ul>
<hr />
<h3 id="heading-step-5-publish-the-application"><strong>Step 5: Publish the Application</strong></h3>
<p>Prepare the application for deployment:</p>
<pre><code class="lang-plaintext">dotnet publish -c Release -o ./publish
</code></pre>
<p><strong>Explanation:</strong><br />This command:</p>
<ul>
<li><p>Builds the application (if not already built).</p>
</li>
<li><p>Packages all necessary files into the <code>./publish</code> directory.</p>
</li>
</ul>
<hr />
<h3 id="heading-step-6-run-the-application"><strong>Step 6: Run the Application</strong></h3>
<p>Navigate to the <code>publish</code> directory and start the application:cd publish</p>
<pre><code class="lang-plaintext">dotnet QRCode_UI.dll
</code></pre>
<p><strong>Explanation:</strong><br />This starts the .NET runtime to execute the application.</p>
<hr />
<h3 id="heading-step-7-access-the-application"><strong>Step 7: Access the Application</strong></h3>
<p>Open a browser and visit the following URLs to access the application:</p>
<ul>
<li><p><code>http://localhost:5000</code> (HTTP)</p>
</li>
<li><p><code>http://localhost:5001</code> (HTTPS)</p>
</li>
</ul>
<p>You’ve successfully run the application manually!</p>
<hr />
<h2 id="heading-part-2-running-the-application-in-docker"><strong>Part 2: Running the Application in Docker</strong></h2>
<p>Now let’s containerize the application using Docker. This approach ensures portability and simplifies deployment across different environments.</p>
<hr />
<h3 id="heading-dockerfile-overview"><strong>Dockerfile Overview</strong></h3>
<p>The <code>Dockerfile</code> defines how the application is built and run in a container. Here’s the <code>Dockerfile</code> we’ll use:</p>
<pre><code class="lang-plaintext"># Stage 1: Build the application
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app

# Restore dependencies
COPY *.sln ./
COPY QRCode_UI/*.csproj ./QRCode_UI/
RUN dotnet restore

# Build and publish the application
COPY . ./
WORKDIR /app/QRCode_UI
RUN dotnet publish -c Release -o /out

# Stage 2: Run the application
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app

# Copy the published output from the build stage
COPY --from=build-env /out .

# Expose the ports used by the application
EXPOSE 5000
EXPOSE 5001

# Configure the application to listen on all network interfaces
ENV ASPNETCORE_URLS="http://0.0.0.0:5000;http://0.0.0.0:5001"

# Run the application
ENTRYPOINT ["dotnet", "QRCode_UI.dll"]
</code></pre>
<p>This Dockerfile has <strong>two stages</strong>:</p>
<ol>
<li><p><strong>Build Stage:</strong> Compiles and publishes the application.</p>
</li>
<li><p><strong>Runtime Stage:</strong> Runs the published application in a lightweight container.</p>
</li>
</ol>
<hr />
<h3 id="heading-step-1-build-the-docker-image"><strong>Step 1: Build the Docker Image</strong></h3>
<p>Run the following command in the directory containing the <code>Dockerfile</code>:</p>
<pre><code class="lang-plaintext">docker build -t my-dotnet-app .
</code></pre>
<p><strong>Explanation:</strong></p>
<ul>
<li><p><code>docker build</code>: Builds a Docker image.</p>
</li>
<li><p><code>-t my-dotnet-app</code>: Tags the image as <code>my-dotnet-app</code>.</p>
</li>
<li><p><code>.</code>: Specifies the current directory as the build context.</p>
</li>
</ul>
<hr />
<h3 id="heading-step-2-run-the-docker-container"><strong>Step 2: Run the Docker Container</strong></h3>
<p>Start a container from the built image:</p>
<pre><code class="lang-plaintext">docker run -d -p 5000:5000 -p 5001:5001 --name my-dotnet-container my-dotnet-app
</code></pre>
<p><strong>Explanation:</strong></p>
<ul>
<li><p><code>docker run</code>: Creates and starts a container.</p>
</li>
<li><p><code>-d</code>: Runs the container in detached mode (in the background).</p>
</li>
<li><p><code>-p 5000:5000 -p 5001:5001</code>: Maps container ports to your machine.</p>
</li>
<li><p><code>--name my-dotnet-container</code>: Names the container <code>my-dotnet-container</code>.</p>
</li>
<li><p><code>my-dotnet-app</code>: Specifies the image to use.</p>
</li>
</ul>
<hr />
<h3 id="heading-step-3-access-the-application"><strong>Step 3: Access the Application</strong></h3>
<p>Open a browser and navigate to:</p>
<ul>
<li><p><code>http://localhost:5000</code></p>
</li>
<li><p><code>https://localhost:5001</code></p>
</li>
</ul>
<p>The application is now running inside a Docker container!</p>
<hr />
<h3 id="heading-step-4-manage-the-container"><strong>Step 4: Manage the Container</strong></h3>
<p>To view the running containers:</p>
<pre><code class="lang-plaintext">docker ps
</code></pre>
<p>To stop the container:</p>
<pre><code class="lang-plaintext">docker stop my-dotnet-container
</code></pre>
<p>To remove the container:</p>
<pre><code class="lang-plaintext">docker rm my-dotnet-container
</code></pre>
<p>To delete the image:</p>
<pre><code class="lang-plaintext">docker rmi my-dotnet-app
</code></pre>
<hr />
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>We’ve demonstrated how to run a .NET application both manually and using Docker. The manual approach is straightforward for development and testing, while Docker simplifies deployment and ensures portability.</p>
<p><strong>Key Benefits of Docker:</strong></p>
<ul>
<li><p>Consistency across environments.</p>
</li>
<li><p>Easy scaling and deployment.</p>
</li>
</ul>
<p>With this knowledge, you can confidently run .NET applications in any environment. Happy coding!</p>
<hr />
<p><strong>Additional Resources:</strong></p>
<ul>
<li><p>Docker Documentation</p>
</li>
<li><p><a target="_blank" href="https://learn.microsoft.com/en-us/dotnet/"><strong>Microsoft .NET Documentation</strong></a></p>
</li>
</ul>
<hr />
<p>This blog provides a complete and well-structured guide for both manual and Docker-based application deployment.</p>
]]></content:encoded></item><item><title><![CDATA[How to Run a Maven Project Locally and with Docker Using a Multi-Stage Dockerfile]]></title><description><![CDATA[If you're working with Java applications, Maven is a popular choice for managing dependencies and automating the build process. Once you have a working application, you may want to containerize it using Docker, which can make deploying your app more ...]]></description><link>https://projects.hassandevops.com/how-to-run-a-maven-project-locally-and-with-docker-using-a-multi-stage-dockerfile</link><guid isPermaLink="true">https://projects.hassandevops.com/how-to-run-a-maven-project-locally-and-with-docker-using-a-multi-stage-dockerfile</guid><category><![CDATA[Devops]]></category><category><![CDATA[maven]]></category><category><![CDATA[projects]]></category><dc:creator><![CDATA[Muhammad Hassan]]></dc:creator><pubDate>Wed, 13 Nov 2024 07:55:26 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1731484392945/701b4a55-40ea-4909-9d13-c64cae3488ae.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you're working with Java applications, Maven is a popular choice for managing dependencies and automating the build process. Once you have a working application, you may want to containerize it using Docker, which can make deploying your app more manageable and portable. This guide will walk you through running a Maven application manually and then show you how to package it with Docker using a multi-stage Dockerfile for an optimized final image.</p>
<hr />
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>Before starting, ensure that you have the following installed:</p>
<ul>
<li><p><strong>Java Development Kit (JDK)</strong>: Make sure it’s compatible with the project.</p>
</li>
<li><p><strong>Apache Maven</strong>: Verify it’s installed by running <code>mvn -v</code>.</p>
</li>
<li><p><strong>Docker</strong>: To containerize and run the application in a container.</p>
</li>
</ul>
<hr />
<h2 id="heading-step-1-clone-and-set-up-the-project">Step 1: Clone and Set Up the Project</h2>
<p>Since you've already cloned the project, navigate to your project directory. Here’s a quick reminder:</p>
<pre><code class="lang-plaintext">git clone https://github.com/your-repository/BankApp.git
cd BankApp
</code></pre>
<p>You should see the following structure in the project:</p>
<pre><code class="lang-plaintext">BankApp/
├── pom.xml
└── src/
    ├── main/
    └── test/
</code></pre>
<p><code>pom.xml</code> contains your project’s dependencies and build instructions, while the <code>src/</code> folder contains the Java source code.</p>
<hr />
<h2 id="heading-step-2-run-the-application-manually-with-maven">Step 2: Run the Application Manually with Maven</h2>
<p>Let's start by building and running the application manually.</p>
<h3 id="heading-build-the-application">Build the Application</h3>
<p>In your project directory, run:</p>
<pre><code class="lang-plaintext">./mvnw clean install
</code></pre>
<p>or if the <code>mvnw</code> script isn’t available, use:</p>
<pre><code class="lang-plaintext">mvn clean install
</code></pre>
<p>This will:</p>
<ol>
<li><p><strong>Download dependencies</strong> specified in <code>pom.xml</code>.</p>
</li>
<li><p><strong>Compile the code</strong> and run any tests.</p>
</li>
<li><p><strong>Package</strong> the application as a <code>.jar</code> file in the <code>target/</code> directory.</p>
</li>
</ol>
<p>After a successful build, you should see something like <code>BankApp-0.0.1-SNAPSHOT.jar</code> in the <code>target/</code> folder.</p>
<h3 id="heading-run-the-application">Run the Application</h3>
<p>To start the application, use:</p>
<pre><code class="lang-plaintext">java -jar target/BankApp-0.0.1-SNAPSHOT.jar
</code></pre>
<p>The application should now be running, and you can access it (if it’s a web app) by navigating to <a target="_blank" href="http://localhost:8080"><code>http://localhost:8080</code></a>.</p>
<hr />
<h2 id="heading-step-3-containerize-the-application-with-docker">Step 3: Containerize the Application with Docker</h2>
<p>Now, let’s make the application easier to deploy by containerizing it with Docker. A multi-stage Dockerfile will help us build and run the application more efficiently.</p>
<h3 id="heading-what-is-a-multi-stage-dockerfile">What is a Multi-Stage Dockerfile?</h3>
<p>A multi-stage Dockerfile separates the build and runtime environments. We use a Maven-based image to compile the project, then copy only the compiled <code>.jar</code> file to a minimal Java runtime image, resulting in a smaller, more efficient Docker image.</p>
<hr />
<h3 id="heading-writing-the-multi-stage-dockerfile">Writing the Multi-Stage Dockerfile</h3>
<p>In the project’s root directory, create a file named <code>Dockerfile</code> and add the following contents:</p>
<pre><code class="lang-plaintext"># Stage 1: Build the application
FROM maven:3.8.7-openjdk-17 AS build

# Set the working directory in the container
WORKDIR /app

# Copy the pom.xml and source code
COPY pom.xml .
COPY src ./src

# Build the application
RUN mvn clean install -DskipTests

# Stage 2: Run the application
FROM openjdk:17-jdk-alpine

# Set the working directory
WORKDIR /app

# Copy the jar file from the build stage
COPY --from=build /app/target/BankApp-0.0.1-SNAPSHOT.jar app.jar

# Expose the port (update if the app uses a different port)
EXPOSE 8080

# Command to run the application
CMD ["java", "-jar", "app.jar"]
</code></pre>
<h3 id="heading-explanation-of-the-dockerfile">Explanation of the Dockerfile</h3>
<ul>
<li><p><strong>Stage 1 (Build Stage)</strong>:</p>
<ul>
<li><p>We use <code>maven:3.8.7-openjdk-17</code> as the base image.</p>
</li>
<li><p>The source code and <code>pom.xml</code> are copied into the container.</p>
</li>
<li><p>The <code>mvn clean install -DskipTests</code> command compiles the application and skips tests for faster builds.</p>
</li>
<li><p>The compiled <code>.jar</code> file is created in <code>/app/target</code>.</p>
</li>
</ul>
</li>
<li><p><strong>Stage 2 (Runtime Stage)</strong>:</p>
<ul>
<li><p>We use a smaller image, <code>openjdk:17-jdk-alpine</code>, to run the app.</p>
</li>
<li><p>The <code>.jar</code> file from the build stage is copied over.</p>
</li>
<li><p>The container exposes port <code>8080</code> (adjust as needed).</p>
</li>
<li><p>The <code>CMD</code> instruction starts the app.</p>
</li>
</ul>
</li>
</ul>
<hr />
<h2 id="heading-step-4-build-and-run-the-docker-image">Step 4: Build and Run the Docker Image</h2>
<p>Now that the Dockerfile is ready, let’s build and run the Docker image.</p>
<h3 id="heading-build-the-docker-image">Build the Docker Image</h3>
<p>Run the following command to build the Docker image:</p>
<pre><code class="lang-plaintext">docker build -t bankapp:latest .
</code></pre>
<p>The <code>-t bankapp:latest</code> option tags the image as <code>bankapp</code> with the <code>latest</code> tag.</p>
<h3 id="heading-run-the-docker-container">Run the Docker Container</h3>
<p>Start a container from the Docker image:</p>
<pre><code class="lang-plaintext">docker run -p 8080:81 bankapp:latest
</code></pre>
<ul>
<li><p>The <code>-p 81:8080</code> option maps port <code>81</code> on your machine to port <code>8080</code> in the container.</p>
</li>
<li><p>Your application should now be accessible at <a target="_blank" href="http://localhost:8080"><code>http://localhost:81</code></a>.</p>
</li>
</ul>
<hr />
<h2 id="heading-step-5-verify-the-application">Step 5: Verify the Application</h2>
<p>To verify that everything is working:</p>
<ol>
<li><p>Open a web browser or use a tool like <code>curl</code> to access <a target="_blank" href="http://localhost:8080"><code>http://localhost:81</code></a>.</p>
</li>
<li><p>Check the logs in your terminal to ensure there are no errors.</p>
</li>
</ol>
<hr />
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1731484474455/3d8ff7f4-6d71-4ec9-a409-f3d9ac02d2c5.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1731484485530/29998c42-6574-40bb-bebb-6715832bd2ac.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-recap">Recap</h2>
<p>Here’s what we covered in this guide:</p>
<ol>
<li><p><strong>Manual Build and Run</strong>: Built and ran the application locally using Maven.</p>
</li>
<li><p><strong>Containerized Build and Run</strong>: Used a multi-stage Dockerfile to build a Docker image and run it in a container.</p>
</li>
</ol>
<p>By containerizing the application, you’ve made it easier to deploy across environments consistently, without the need for a specific JDK or Maven installation. The multi-stage Dockerfile ensures the final image is optimized for size and performance, containing only what’s needed to run the application.</p>
]]></content:encoded></item><item><title><![CDATA[Setting Up Nginx for Node.js Application Deployment]]></title><description><![CDATA[In this guide, we will go through the steps to deploy a Node.js application using Nginx as a reverse proxy. We'll also show how to manage the app using PM2 for process management and auto-starting the app on boot.
Table of Contents:

What is Nginx?

...]]></description><link>https://projects.hassandevops.com/setting-up-nginx-for-nodejs-application-deployment</link><guid isPermaLink="true">https://projects.hassandevops.com/setting-up-nginx-for-nodejs-application-deployment</guid><category><![CDATA[nginx]]></category><category><![CDATA[Node.js]]></category><dc:creator><![CDATA[Muhammad Hassan]]></dc:creator><pubDate>Tue, 12 Nov 2024 12:58:33 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1731415974873/8cc1e745-3d64-4383-8fd3-17e6d65f091b.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this guide, we will go through the steps to deploy a Node.js application using Nginx as a reverse proxy. We'll also show how to manage the app using PM2 for process management and auto-starting the app on boot.</p>
<h2 id="heading-table-of-contents">Table of Contents:</h2>
<ol>
<li><p><a class="post-section-overview" href="#what-is-nginx">What is Nginx?</a></p>
</li>
<li><p><a class="post-section-overview" href="#installing-nginx">Installing Nginx</a></p>
</li>
<li><p><a class="post-section-overview" href="#installing-nodejs">Installing Node.js</a></p>
</li>
<li><p><a class="post-section-overview" href="#setting-up-pm2">Setting Up PM2</a></p>
</li>
<li><p><a class="post-section-overview" href="#deploying-the-nodejs-application">Deploying the Node.js Application</a></p>
</li>
<li><p><a class="post-section-overview" href="#configuring-nginx-as-a-reverse-proxy">Configuring Nginx as a Reverse Proxy</a></p>
</li>
<li><p><a class="post-section-overview" href="#running-the-application">Running the Application</a></p>
</li>
<li><p><a class="post-section-overview" href="#using-pm2-to-manage-the-application">Using PM2 to Manage the Application</a></p>
</li>
</ol>
<hr />
<h2 id="heading-1-what-is-nginx">1. What is Nginx?</h2>
<p><strong>Nginx</strong> is a high-performance web server and reverse proxy server used to serve static content and forward dynamic requests to backend applications like Node.js. It also helps in load balancing, handling high concurrency, and caching, making it ideal for serving both static and dynamic content efficiently.</p>
<h2 id="heading-2-installing-nginx">2. Installing Nginx</h2>
<p>To install Nginx on a Linux-based server (like Ubuntu), follow these steps:</p>
<h3 id="heading-for-ubuntudebian">For Ubuntu/Debian:</h3>
<pre><code class="lang-plaintext">cd
sudo apt update
sudo apt install nginx
</code></pre>
<h3 id="heading-for-centos">For CentOS:</h3>
<pre><code class="lang-plaintext">sudo yum install epel-release
sudo yum install nginx
</code></pre>
<p>After installation, you can start and enable Nginx to run on system boot:</p>
<pre><code class="lang-plaintext">sudo systemctl start nginx
sudo systemctl enable nginx
</code></pre>
<p>Check if Nginx is running:</p>
<pre><code class="lang-plaintext">sudo systemctl status nginx
</code></pre>
<p>You should now be able to visit <code>http://your-server-ip</code> in a browser and see the Nginx welcome page.</p>
<h2 id="heading-3-installing-nodejs">3. Installing Node.js</h2>
<p>Next, you'll need to install Node.js on your server to run your Node.js application.</p>
<h3 id="heading-for-ubuntudebian-1">For Ubuntu/Debian:</h3>
<ol>
<li><p>Install the NodeSource repository for Node.js:</p>
<pre><code class="lang-plaintext"> # installs nvm (Node Version Manager)
 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
</code></pre>
</li>
<li><p>Install Node.js:</p>
<pre><code class="lang-plaintext"> nvm install 22
</code></pre>
</li>
<li><p>Verify the installation:</p>
<pre><code class="lang-plaintext"> node -v
 npm -v
</code></pre>
</li>
</ol>
<p>This should return the version of Node.js and npm installed.</p>
<h2 id="heading-4-setting-up-pm2">4. Setting Up PM2</h2>
<p><strong>PM2</strong> is a process manager for Node.js applications that allows you to keep applications alive forever, restart them on crashes, and even manage multiple instances.</p>
<h3 id="heading-install-pm2-globally">Install PM2 globally:</h3>
<pre><code class="lang-plaintext">sudo npm install pm2@latest -g
</code></pre>
<p>Verify the installation:</p>
<pre><code class="lang-plaintext">pm2 -v
</code></pre>
<h3 id="heading-enable-pm2-to-start-on-boot">Enable PM2 to start on boot:</h3>
<pre><code class="lang-plaintext">pm2 startup
</code></pre>
<p>This command will generate a command that you need to run to configure PM2 to start on system reboot.</p>
<hr />
<h2 id="heading-5-deploying-the-nodejs-application">5. Deploying the Node.js Application</h2>
<p>Now that Nginx and Node.js are set up, you can deploy your Node.js application. For this, you'll typically use Git to clone the repository, check out the desired branch, install dependencies, build the app, and start it using PM2.</p>
<h3 id="heading-step-by-step-guide">Step-by-Step Guide:</h3>
<h3 id="heading-1-clone-the-repository-and-checkout-a-specific-branch">1. Clone the Repository and Checkout a Specific Branch</h3>
<p>Clone the Git repository of your Node.js application:</p>
<pre><code class="lang-plaintext">git clone https://github.com/your-repo/your-node-app.git
cd your-node-app
</code></pre>
<p>Checkout to the specific branch you want to deploy:</p>
<pre><code class="lang-plaintext">git checkout your-branch-name
</code></pre>
<h3 id="heading-2-install-dependencies">2. Install Dependencies</h3>
<p>Run the following command to install all the required dependencies for the Node.js applicatnpm install</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1731414976262/3dc58269-1500-4959-b73d-392bd5a40785.png" alt /></p>
<h3 id="heading-3-build-the-application-optional">3. Build the Application (Optional)</h3>
<p>If your Node.js app requires a build step (e.g., for a frontend build or compiling assets), run:</p>
<pre><code class="lang-plaintext">npm run build
</code></pre>
<p>You can specify an environment for the build using the <code>.env</code> file. For example, to use a <code>production</code> environment, you might set:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1731414582031/8fdb836a-d3c4-46e8-ab32-59d6d0ef338e.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-plaintext">npm run build:prod
</code></pre>
<h3 id="heading-4-start-the-application">4. Start the Application</h3>
<p>Now, you can start your application. To run it normally (without PM2), use:</p>
<pre><code class="lang-plaintext">npm run start
</code></pre>
<p>However, to ensure that your app stays running even if the server restarts or crashes, we’ll use <strong>PM2</strong>.</p>
<hr />
<h2 id="heading-6-configuring-nginx-as-a-reverse-proxy">6. Configuring Nginx as a Reverse Proxy</h2>
<p>Nginx will serve as a reverse proxy to forward incoming HTTP requests to your Node.js application running on a specific port.</p>
<h3 id="heading-configure-nginx">Configure Nginx:</h3>
<ol>
<li>Create a new Nginx server block (virtual host) configuration:</li>
</ol>
<pre><code class="lang-plaintext">sudo nano /etc/nginx/sites-available/your-node-app
</code></pre>
<ol start="2">
<li>Add the following Nginx configuration to proxy requests to the Node.js app running on a specific port (e.g., port 3000):</li>
</ol>
<pre><code class="lang-plaintext"># HTTP server block (port 80) to redirect to HTTPS
server {
    listen 80;
    server_name your-domain.com;

    # Redirect all HTTP requests to HTTPS
    return 301 https://$host$request_uri;
}

# HTTPS server block (port 443)
server {
    listen 443 ssl;
    server_name your-domain.com;

    # Self-signed SSL certificate paths
    ssl_certificate /etc/ssl/certs/selfsigned.crt;
    ssl_certificate_key /etc/ssl/private/selfsigned.key;

    location / {
        proxy_pass http://localhost:3000;  # Replace with your app's port if different
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}
</code></pre>
<ol start="3">
<li>Create a symbolic link to enable this site:</li>
</ol>
<pre><code class="lang-plaintext">sudo ln -s /etc/nginx/sites-available/your-node-app /etc/nginx/sites-enabled/
</code></pre>
<ol start="4">
<li>Test the Nginx configuration for syntax errors:</li>
</ol>
<pre><code class="lang-plaintext">sudo nginx -t
</code></pre>
<ol start="5">
<li>Reload Nginx to apply the changes:</li>
</ol>
<pre><code class="lang-plaintext">sudo systemctl reload nginx
</code></pre>
<p>Your Node.js application should now be accessible through your domain (e.g., <code>http://your-domain.com</code>).</p>
<hr />
<h2 id="heading-7-running-the-application">7. Running the Application</h2>
<p>After building the app, you can start it with PM2, which will ensure it runs in the background and automatically restarts if it crashes.</p>
<ol>
<li>Start the app with PM2:</li>
</ol>
<pre><code class="lang-plaintext">pm2 start server.js --name "my-app"
</code></pre>
<ol start="2">
<li>To check the app’s status:</li>
</ol>
<pre><code class="lang-plaintext">pm2 status
</code></pre>
<ol start="3">
<li>To stop the app:</li>
</ol>
<pre><code class="lang-plaintext">pm2 stop my-app
</code></pre>
<ol start="4">
<li>To restart the app:</li>
</ol>
<pre><code class="lang-plaintext">pm2 restart my-app
</code></pre>
<ol start="5">
<li>To save the PM2 process list so that the app restarts automatically after reboot:</li>
</ol>
<pre><code class="lang-plaintext">pm2 save
</code></pre>
<hr />
<h2 id="heading-8-using-pm2-to-manage-the-application">8. Using PM2 to Manage the Application</h2>
<p>PM2 makes managing your Node.js application easier. Here are some common PM2 commands:</p>
<ul>
<li><p><strong>List all processes</strong>:</p>
<pre><code class="lang-plaintext">  pm2 list
</code></pre>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1731414510947/dcb219a5-b0eb-4900-acb8-83f9e36e36d3.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>View logs</strong>:</p>
<pre><code class="lang-plaintext">  pm2 logs your-node-app
</code></pre>
</li>
<li><p><strong>Monitor app resources</strong>:</p>
<pre><code class="lang-plaintext">  pm2 monit
</code></pre>
</li>
</ul>
<p>PM2 will now ensure that your Node.js application runs smoothly and restarts automatically if there’s a failure or if the server reboots.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1731414697016/009ac667-b33b-411c-a40b-45ca594fd821.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1731414736288/57cdc6af-0a9b-4a9c-a781-394e99f0f643.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-multi-stage-dockerfile">Multi-stage Dockerfile:</h3>
<pre><code class="lang-plaintext"># Build Stage
FROM node:23-alpine3.19 AS builder

WORKDIR /app

# Install dependencies and build the project
COPY package.json package-lock.json ./
RUN npm ci --production

COPY . .
RUN npm run build

# Final Stage (Smaller image)
FROM node:23-alpine3.19 AS final

WORKDIR /app

# Copy the necessary files from the builder stage
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/package-lock.json ./package-lock.json

# Install production dependencies in the final image
RUN npm install --production --silent

# Expose port and define the command to start the app
EXPOSE 3000
CMD ["npm", "run", "start"]
</code></pre>
<h3 id="heading-explanation-of-the-changes">Explanation of the changes:</h3>
<ol>
<li><p><strong>Builder stage</strong>:</p>
<ul>
<li>This stage installs all dependencies and runs <code>npm run build</code> to generate the build output, which for a Next.js app will be in the <code>.next</code> directory.</li>
</ul>
</li>
<li><p><strong>Final stage</strong>:</p>
<ul>
<li><p>Copies only the necessary files (i.e., <code>.next</code> directory, <code>public</code> folder, <code>package.json</code>, and <code>package-lock.json</code>) to the final image.</p>
</li>
<li><p>Installs production dependencies (<code>npm install --production</code>) in the final image.</p>
</li>
</ul>
</li>
</ol>
<h3 id="heading-how-to-use-it">How to use it:</h3>
<ol>
<li><p><strong>Build the Docker image</strong>:</p>
<p> Run the following command to build the image:</p>
<pre><code class="lang-plaintext"> sudo docker build -t node .
</code></pre>
</li>
<li><p><strong>Run the container</strong>:</p>
<p> After building the image, you can run the container using:</p>
<pre><code class="lang-plaintext"> sudo docker run -p 3000:3000 node
</code></pre>
</li>
</ol>
<p>This setup will produce a smaller final image, as it only includes the necessary files for running the production application and avoids including unnecessary development dependencies and files. Let me know how it goes!</p>
]]></content:encoded></item><item><title><![CDATA[Deploying Tetris on Kubernetes with Argo CD]]></title><description><![CDATA[Prerequisites
Before we begin, make sure you have the following:

An AWS account.

eksctl installed on your local machine.

kubectl installed on your local machine.

Git for version control.

https://archive.eksworkshop.com/intermediate/290_argocd/co...]]></description><link>https://projects.hassandevops.com/deploying-tetris-on-kubernetes-with-argo-cd</link><guid isPermaLink="true">https://projects.hassandevops.com/deploying-tetris-on-kubernetes-with-argo-cd</guid><dc:creator><![CDATA[Muhammad Hassan]]></dc:creator><pubDate>Mon, 12 Feb 2024 05:45:11 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1707295374931/1f8cc501-c060-4392-8676-e462e9ab6360.avif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-prerequisites"><strong>Prerequisites</strong></h2>
<p>Before we begin, make sure you have the following:</p>
<ol>
<li><p>An AWS account.</p>
</li>
<li><p><code>eksctl</code> installed on your local machine.</p>
</li>
<li><p><code>kubectl</code> installed on your local machine.</p>
</li>
<li><p>Git for version control.</p>
</li>
<li><p><a target="_blank" href="https://archive.eksworkshop.com/intermediate/290_argocd/configure/">https://archive.eksworkshop.com/intermediate/290_argocd/configure/</a></p>
</li>
</ol>
<h2 id="heading-step-1-create-an-eks-cluster"><strong>Step 1: Create an EKS Cluster</strong></h2>
<p>Use the following <code>eksctl</code> command to create an EKS cluster named "dev" in the EU (Stockholm) region with a managed node group:</p>
<pre><code class="lang-plaintext">eksctl create cluster --name dev --region eu-north-1 --nodegroup-name workers --node-type t3.medium --nodes 2 --nodes-min 2 --nodes-max 2 --managed
</code></pre>
<p>Wait for the cluster to be provisioned before proceeding.</p>
<h2 id="heading-step-2-install-argo-cd"><strong>Step 2: Install Argo CD</strong></h2>
<p>Create a namespace for Argo CD and apply the installation manifests:</p>
<pre><code class="lang-plaintext">kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
</code></pre>
<p>Patch the Argo CD service to use a LoadBalancer:</p>
<pre><code class="lang-plaintext">kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'
</code></pre>
<p>Retrieve the external IP or DNS of the Argo CD server:</p>
<pre><code class="lang-plaintext">kubectl get svc argocd-server -n argocd -o=jsonpath='{.status.loadBalancer.ingress[0].hostname}'
</code></pre>
<p>Now, you can access the Argo CD UI using the provided external IP or DNS.</p>
<pre><code class="lang-plaintext">export ARGO_PWD=`kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d`
echo $ARGO_PWD
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1705312647173/249327ce-2133-4638-8782-e6865a3c1eab.png?auto=compress,format&amp;format=webp" alt /></p>
<h2 id="heading-step-3-deploy-tetris-game-with-argo-cd"><strong>Step 3: Deploy Tetris Game with Argo CD</strong></h2>
<p>Clone the Tetris game repository:</p>
<pre><code class="lang-plaintext">git clone https://github.com/muhammadhassanb111/tetris-game/tree/main
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1705313305441/f211066f-a0dd-4152-a7bd-515062717800.png?auto=compress,format&amp;format=webp" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1705313316790/ff03a368-bcfb-47ee-8191-cf6c9dcb4c4a.png?auto=compress,format&amp;format=webp" alt /></p>
]]></content:encoded></item><item><title><![CDATA[GitHub Actions: Netflix Deployment Powered by DevSecOps]]></title><description><![CDATA[Step1: Launch an Ec2 Instance
To launch an AWS EC2 instance with Ubuntu 22.04 using the AWS Management Console, sign in to your AWS account, access the EC2 dashboard, and click "Launch Instances." In "Step 1," select "Ubuntu 22.04" as the AMI, and in...]]></description><link>https://projects.hassandevops.com/github-actions-netflix-deployment-powered-by-devsecops</link><guid isPermaLink="true">https://projects.hassandevops.com/github-actions-netflix-deployment-powered-by-devsecops</guid><category><![CDATA[github-actions]]></category><dc:creator><![CDATA[Muhammad Hassan]]></dc:creator><pubDate>Wed, 07 Feb 2024 10:30:59 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1707301565959/3d4475d1-4181-48a3-a7d2-188ea26a7fb0.avif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697788120677/7708713d-c403-43f4-83a7-51a36545d708.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<h3 id="heading-step1-launch-an-ec2-instance">Step1: Launch an Ec2 Instance</h3>
<p>To launch an AWS EC2 instance with Ubuntu 2<a target="_blank" href="https://hashnode.com/@se7enAj">2.04 using the</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">AWS Manageme</a>nt Con<a target="_blank" href="https://hashnode.com/@se7enAj">sole, sign in</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">to your AWS</a> account, access the EC2 dashboard, and click "Launch Instances." In "Step 1," select "Ubuntu 22.04" as the AMI, and in "Step 2," choose "t2.medium" as the instance type. Configure the instance details, storage, tags, and security group settings according to your requirements. Review the settings, create or select a key pair for secure access, and launch the instance. Once launched, you can connect to it via SSH using the associated key pair.</p>
<h3 id="heading-step2a-install-docker-and-run-sonarqube-container">Step2A: Install Docker and Run Sonarqube Container</h3>
<p>Connect to your Ec2 in<a target="_blank" href="https://hashnode.com/@se7enAj">stance using Pu</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">tty, Mobaxtr</a>eme or Git bash and install <a target="_blank" href="https://hashnode.com/@se7enAj">docker on it</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">.</a></p>
<pre><code class="lang-plaintext">sudo apt-get update
sudo apt install docker.io -y
sudo usermod -aG docker ubuntu
newgrp docker
sudo chmod 777 /var/run/docker.sock
</code></pre>
<p>Pull the SonarQube Docker image and run it.</p>
<p>After the docker installation, <a target="_blank" href="https://hashnode.com/@se7enAj">we will creat</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">e a Sonarqub</a>e container (Remembe<a target="_blank" href="https://hashnode.com/@se7enAj">r to add 9000</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ports in th</a>e security group).</p>
<pre><code class="lang-plaintext">docker run -d --name sonar -p 9000:9000 sonarqube:lts-community
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694159658559/a607bab7-4ee0-4802-bf77-e9716ac33838.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now copy the IP address of the ec2 instance</p>
<pre><code class="lang-plaintext">&lt;ec2-public-ip:9000&gt;
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694159822624/f07bd773-5992-4b88-b849-ffcea2891b8e.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Provide <a target="_blank" href="https://hashnode.com/@se7enAj">Login and pa</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ssword</a></p>
<pre><code class="lang-plaintext">login admin
password admin
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694159867860/7425ab62-8978-4dbb-a5c5-d0eb3362c15f.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Update your Sonarq<a target="_blank" href="https://hashnode.com/@se7enAj">ube password</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">&amp; This is th</a>e Sonarqube dashboard</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694159887297/6e055b5c-13ea-405f-bc13-1234b05bf2ff.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<h3 id="heading-step2b-integratinghttpshashnodecomse7enaj-sonarqube-wihttpsmrcloudbookhashnodedevgithub-actions-netflix-deployment-powered-by-devsecopsth-github-actions">Step2B: <a target="_blank" href="https://hashnode.com/@se7enAj">Integrating</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">SonarQube wi</a>th GitHub Actions</h3>
<p>Integrating SonarQube w<a target="_blank" href="https://hashnode.com/@se7enAj">ith GitHub Acti</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ons allows y</a>ou to automatically analyz<a target="_blank" href="https://hashnode.com/@se7enAj">e your code f</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">or quality a</a>nd security as part of your continuous integration pipeline.</p>
<p>We already have Sonarqube up and running</p>
<p>On Sonarqube Dashboard click on Ma<a target="_blank" href="https://hashnode.com/@se7enAj">nually</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697733434327/7c1d1747-6a5c-4bfb-86c6-a377c16283c2.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://hashnode.com/@se7enAj">Next</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">, provide a</a> name for your pro<a target="_blank" href="https://hashnode.com/@se7enAj">ject and prov</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ide a Branch</a> name and click on <a target="_blank" href="https://hashnode.com/@se7enAj">setup</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697733461776/7a20890c-4c29-4af6-bc1b-d8f1608e5399.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://hashnode.com/@se7enAj">On t</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">he next page</a> click on With GitHub actions</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697733519026/1ece3e2d-cd62-4d0a-a5af-685052b92a48.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>This will Generate an overvi<a target="_blank" href="https://hashnode.com/@se7enAj">ew of the Pro</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ject and pro</a>vide some instructions <a target="_blank" href="https://hashnode.com/@se7enAj">to integrate</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697733567304/9a982d64-630d-4557-8911-e12f5ee93d21.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Let's Open</a> your GitHub and select your Repository</p>
<p>In my case it is Netflix-<a target="_blank" href="https://hashnode.com/@se7enAj">clone and Cli</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ck on Settin</a>gs</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1706858451786/7ce3fb11-618b-4eb9-9f82-f02c12dd9213.png?auto=compress,format&amp;format=webp" alt /></p>
<p>Search for Secrets an<a target="_blank" href="https://hashnode.com/@se7enAj">d variables a</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">nd click on</a> and again click on actions</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697733831585/cc14f1ff-0874-482a-a696-603996fa7830.png?auto=compress,format&amp;format=webp?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>I<a target="_blank" href="https://hashnode.com/@se7enAj">t will open a</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">page like t</a>his click on New Repository secret</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697733935806/991195ea-a5b2-4680-9862-5cfd83578094.png?auto=compress,format&amp;format=webp?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now go back t<a target="_blank" href="https://hashnode.com/@se7enAj">o Your Sonarq</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ube Dashboar</a>d</p>
<p>Copy SONAR_TOKEN and click on Gener<a target="_blank" href="https://hashnode.com/@se7enAj">ate Token</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697734072182/edf9523e-d085-4ce6-b6bd-71f6e2d6ca87.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://hashnode.com/@se7enAj">C</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">lick on Gene</a>rate</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697734186205/ebc600b1-d572-4c62-a36b-d60c6b898bf6.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Let's cop<a target="_blank" href="https://hashnode.com/@se7enAj">y the Token a</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">nd add it to</a> GitHub secrets</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697734317430/cb2b2908-7b7c-4be2-9189-361f57101243.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now <a target="_blank" href="https://hashnode.com/@se7enAj">go back to Gi</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">tHub an</a><a target="_blank" href="https://hashnode.com/@se7enAj">d Paste the c</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">opied name f</a>or the secret and token</p>
<p>Na<a target="_blank" href="https://hashnode.com/@se7enAj">me: <mark>SONAR_TOK</mark></a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops"><mark>EN</mark></a></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Secret:</a> Paste Your Token and click on Add secret</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697734395256/0e9df5a6-1f71-43dd-84bd-d896b45127e4.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now go <a target="_blank" href="https://hashnode.com/@se7enAj">back to the</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Sonarq</a><a target="_blank" href="https://hashnode.com/@se7enAj">ube Dashboard</a></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Copy the N</a>ame and Value</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697734509638/728bd7b9-b054-47e4-a198-cee97b4d8c84.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Go to GitH<a target="_blank" href="https://hashnode.com/@se7enAj">ub now and pa</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ste-like thi</a>s and click on <a target="_blank" href="https://hashnode.com/@se7enAj">add secret</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697734741619/b10c45fd-6b3a-4d93-8da4-d717afa4e274.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Our Sonarqub</a>e <a target="_blank" href="https://hashnode.com/@se7enAj">secrets are</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">added and yo</a>u can see</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697734812189/1f71c8a4-b476-4bfd-b737-c7d959c2212f.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Go to Sonarqube Dashboard <a target="_blank" href="https://hashnode.com/@se7enAj">and click on</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">continue</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697734879501/99701543-dcaf-49f3-a833-fb5d3c66020f.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">N</a>ow create your Workflow f<a target="_blank" href="https://hashnode.com/@se7enAj">or your Proje</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ct. In my ca</a>se, the Netflix project i<a target="_blank" href="https://hashnode.com/@se7enAj">s built using</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">React Js. T</a>hat's why I am selecting Other</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697735091192/592ee329-3282-4531-86a6-649245d75e2a.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now it Generates and workflow for my Project</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697735193704/d55b9bd6-abc3-43c1-8e79-ca7492e65ef9.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Go back to GitHub. click on A<a target="_blank" href="https://hashnode.com/@se7enAj">dd file and t</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">hen create a</a> new file</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697735294808/28027f5d-a7c7-4a73-8210-dda3aaec5594.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Go back to <a target="_blank" href="https://hashnode.com/@se7enAj">the Sonarqub</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">e dashboard</a> and copy the file name and content</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697735423519/bc7d137f-e683-40d5-8d02-de252a6bba1b.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Here <a target="_blank" href="https://hashnode.com/@se7enAj">file name (i</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">n my case on</a>ly )</p>
<pre><code class="lang-plaintext">sonar-project.properties
</code></pre>
<p>The content to <a target="_blank" href="https://hashnode.com/@se7enAj">add to the f</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ile is (copi</a>ed from the above image)</p>
<pre><code class="lang-plaintext">sonar.projectKey=Netflix
</code></pre>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Add in Gi</a>tHub like this</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697735613515/cdfa1471-d40f-4c6b-9d54-c935cf109d96.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Let's add our workflow</p>
<p>To do that click on Add fi<a target="_blank" href="https://hashnode.com/@se7enAj">le and then c</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">lick on Crea</a>t<a target="_blank" href="https://hashnode.com/@se7enAj">e a new file</a></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Here is t</a><a target="_blank" href="https://hashnode.com/@se7enAj">he file name</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1706858396652/dcce0848-a905-409a-ac4d-6f37b6a079a6.png?auto=compress,format&amp;format=webp" alt /></p>
<pre><code class="lang-plaintext">.github/workflows/build.yml  #you can use any name iam using sonar.yml
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697735742377/942d5afd-c831-45ac-ab0c-a7c63caddfdc.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Copy</a> content and add it to the file</p>
<pre><code class="lang-plaintext">name: Build,Analyze,scan

on:
  push:
    branches:
      - main


jobs:
  build-analyze-scan:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
        with:
          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis

      - name: Build and analyze with SonarQube
        uses: sonarsource/sonarqube-scan-action@master
        env:
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
          SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697735821468/6d9fdc2a-4065-4e5c-99b5-9fc2ae4a565e.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Click on commit changes</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697735887372/f4fff53d-5e8a-4171-87ab-f61d215e615b.png?auto=compress,format&amp;format=webp?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now workflow is created.</p>
<p>Click on Actions now</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697735946338/58acfdf1-e96d-45d9-8148-2877e2e4bae6.png?auto=compress,format&amp;format=webp?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>N<a target="_blank" href="https://hashnode.com/@se7enAj">ow it's autom</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">atically sta</a>r<a target="_blank" href="https://hashnode.com/@se7enAj">ted the workf</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">low</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697736015163/9be8e520-54e7-4eb9-bb7e-841d598a0e14.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697736055832/d2415635-cba2-4f55-b3cd-9147b55c56ee.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Let's</a> <a target="_blank" href="https://hashnode.com/@se7enAj">click on Buil</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">d and see</a> <a target="_blank" href="https://hashnode.com/@se7enAj">what are the</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">steps involv</a>ed</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697736123510/a2ac77be-6cd4-411a-993f-d25613fccb3d.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Click on Run Sona<a target="_blank" href="https://hashnode.com/@se7enAj">rsource and y</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ou can do th</a>is after the build completion</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697736204287/80bce1ff-6fee-4623-a92c-3cf4bf67c05f.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Bu<a target="_blank" href="https://hashnode.com/@se7enAj">ild complete.</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697736325893/8c9309b3-394c-4a58-b91a-3e452e578484.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Go to the</a> Sonarqube dashboard and click on projects and yo<a target="_blank" href="https://hashnode.com/@se7enAj">u can see the</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">anal</a><a target="_blank" href="https://hashnode.com/@se7enAj">ysis</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697736376673/fef41016-089d-4a96-9ca2-34cd7081f508.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://hashnode.com/@se7enAj">If you</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">want to see</a> the full report, click on issues.</p>
<h3 id="heading-step3-lets-scan-files-using-trihttpshashnodecomse7enajvyhttpsmrcloudbookhashnodedevgithub-actions-netflix-deployment-powered-by-devsecops">Step3: Let's scan fi<a target="_blank" href="https://hashnode.com/@se7enAj">les using Tri</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">vy</a></h3>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Add this</a> code to your sonar.yml (I me<a target="_blank" href="https://hashnode.com/@se7enAj">an workflow)</a></p>
<pre><code class="lang-plaintext">- name: install trivy
  run: |
    #install trivy
    sudo apt-get install wget apt-transport-https gnupg lsb-release -y
    wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg &gt; /dev/null
    echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee -a /etc/apt/sources.list.d/trivy.list
    sudo apt-get update
    sudo apt-get install trivy -y
    #command to scan files
    trivy fs .
</code></pre>
<p>GitHub Actions workflow step that installs Trivy, a popular open-source vuln<a target="_blank" href="https://hashnode.com/@se7enAj">erability sca</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">nner for con</a>tainers, and then uses it to scan the files.</p>
<p>I added a step in the workflow</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697737102202/c47866e8-173b-4619-8608-91d7ff4d103f.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Commit changes</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697735887372/f4fff53d-5e8a-4171-87ab-f61d215e615b.png" alt /></p>
<p>Click on actions again</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697735946338/58acfdf1-e96d-45d9-8148-2877e2e4bae6.png" alt /></p>
<p>I<a target="_blank" href="https://hashnode.com/@se7enAj">t started the</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">workflow bu</a>ild</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697737273762/3a338c77-9209-464d-8d46-46733c7fa46a.png?auto=compress,format&amp;format=webp?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Cl<a target="_blank" href="https://hashnode.com/@se7enAj">ick on Build,</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Ana</a><a target="_blank" href="https://hashnode.com/@se7enAj">lyze and scan</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697737352185/8b806279-8e18-4f5c-8e6a-6324fc723ab4.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">It instal</a><a target="_blank" href="https://hashnode.com/@se7enAj">led Trivy ver</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">sion 0.46.0</a> and sca<a target="_blank" href="https://hashnode.com/@se7enAj">nned files al</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">so. See repo</a>rt</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697737445167/f8279a79-0a45-45c2-8c82-ef2c88217535.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>The f<a target="_blank" href="https://hashnode.com/@se7enAj">ile scan is c</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ompleted, th</a>is is another security check</p>
<h3 id="heading-step4a-docker-build-and-puhttpshashnodecomse7enajsh-to-dockerhttpsmrcloudbookhashnodedevgithub-actions-netflix-deployment-powered-by-devsecopshub">Step4A: Docker <a target="_blank" href="https://hashnode.com/@se7enAj">build and pu</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">sh to Docker</a>hub</h3>
<p>Create a Personal Access token <a target="_blank" href="https://hashnode.com/@se7enAj">for your Docke</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">rhub account</a></p>
<p>Go to docker hub <a target="_blank" href="https://hashnode.com/@se7enAj">and click on</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">your profile</a> --&gt; Account settings --&gt; security <a target="_blank" href="https://hashnode.com/@se7enAj">--&gt; New acce</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ss token</a></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">I</a>t asks for a name Provide a name and click on generate token</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1706858314272/fe895ecb-f79c-481b-857e-cf1f2388b5cc.png?auto=compress,format&amp;format=webp" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697738153103/481b06e8-e089-4c49-bddd-892ad8885f3f.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Copy the tok<a target="_blank" href="https://hashnode.com/@se7enAj">en save it in</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">a safe plac</a>e, and close</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697738231443/d69a2fc2-3c7f-4319-b6b1-01fab73cb7c6.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now Go to GitHub again a<a target="_blank" href="https://hashnode.com/@se7enAj">nd click on s</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ettings</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697733771633/aede3330-0e1d-4c50-83aa-1789a792bf70.png?auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Se</a>arch for Secrets and variab<a target="_blank" href="https://hashnode.com/@se7enAj">les and click</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">on and agai</a>n click on actions</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697733831585/cc14f1ff-0874-482a-a696-603996fa7830.png" alt /></p>
<p>I<a target="_blank" href="https://hashnode.com/@se7enAj">t will open a</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">page like t</a>his click on New Repository secret</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697733935806/991195ea-a5b2-4680-9862-5cfd83578094.png" alt /></p>
<p>Add your Dock<a target="_blank" href="https://hashnode.com/@se7enAj">erhub usernam</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">e with the s</a>ecret name as</p>
<pre><code class="lang-plaintext">DOCKERHUB_USERNAME   #use your dockerhub username
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697738532234/8e5480a2-d0c1-4fff-8bba-27a65f1eb7fb.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Click on Add Secret.</p>
<p>Let's add our token also and click on the new reposito<a target="_blank" href="https://hashnode.com/@se7enAj">ry secret aga</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">in</a></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Name</a></p>
<pre><code class="lang-plaintext">DOCKERHUB_TOKEN
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697738661634/236f1094-7ac5-419d-95b2-0dab36d18de7.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Paste</a> the token that you generated and click on Add <a target="_blank" href="https://hashnode.com/@se7enAj">secret.</a></p>
<h3 id="heading-shttpshashnodecomse7enajtep4b-creathttpsmrcloudbookhashnodedevgithub-actions-netflix-deployment-powered-by-devsecopse-a-tmdb-apihttpshashnodecomse7enaj-keyhttpsmrcloudbookhashnodedevgithub-actions-netflix-deployment-powered-by-devsecops"><a target="_blank" href="https://hashnode.com/@se7enAj">S</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">tep4B: Creat</a><a target="_blank" href="https://hashnode.com/@se7enAj">e a TMDB API</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Key</a></h3>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Next, w</a>e will create a TMDB API key</p>
<p>Open a <a target="_blank" href="https://hashnode.com/@se7enAj">new tab in the</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Browser and</a> searc<a target="_blank" href="https://hashnode.com/@se7enAj">h for TMDB</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696676147833/d4b2a30a-9905-4c80-9e35-5f2c4ab507ed.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Click on the</a> first resul<a target="_blank" href="https://hashnode.com/@se7enAj">t, you will s</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ee this page</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696676217664/aa0b301b-4b7f-47d0-b07b-4213f0e60354.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Click on the Login on th<a target="_blank" href="https://hashnode.com/@se7enAj">e top right.</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">You will get</a> this page.</p>
<p>You need to cr<a target="_blank" href="https://hashnode.com/@se7enAj">eate an accou</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">nt here. cli</a>ck on click here. I have an account t<a target="_blank" href="https://hashnode.com/@se7enAj">hat's why I a</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">dded my deta</a>ils there.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696676319480/44376988-549f-41d2-b469-2951d0574359.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>once you create an account you will see this page.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696676407253/ebb7fba4-efb8-4422-a473-b164bc609f3d.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Let's create an API key<a target="_blank" href="https://hashnode.com/@se7enAj">, By clicking</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">on your pro</a>file and clicking settings.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696676474552/d8913c51-3268-463c-9b67-9c1b70d72bef.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://hashnode.com/@se7enAj">Now click o</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">n API from t</a>he left side panel.</p>
<p>Now click on create</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696676552066/d768cbba-5c5c-44c9-8692-14276afa7516.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Click on <a target="_blank" href="https://hashnode.com/@se7enAj">Developer</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696676567781/7f92bfb0-f76c-47c0-9f7b-716cfa8e617d.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://hashnode.com/@se7enAj">N</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ow you have</a> to accept the terms <a target="_blank" href="https://hashnode.com/@se7enAj">and condition</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">s.</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696676601846/c2b4a1c7-e72a-405c-82a5-cfd5fc454403.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Prov</a><a target="_blank" href="https://hashnode.com/@se7enAj">ide basic det</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ails</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696676624029/ac7b685f-3fae-449c-977f-717e406a4933.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://hashnode.com/@se7enAj">Click on subm</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">it and you w</a>ill get your API key.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696676675438/de5b5e7b-370e-4d73-874f-842451e2d508.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Le<a target="_blank" href="https://hashnode.com/@se7enAj">t's add the b</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">elow step to</a> <a target="_blank" href="https://hashnode.com/@se7enAj">the workflow</a></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops"><mark>You have t</mark></a><mark>o add API at the Build c</mark><a target="_blank" href="https://hashnode.com/@se7enAj"><mark>ommand</mark></a></p>
<p><a target="_blank" href="https://hashnode.com/@se7enAj">Chang</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">e your usern</a>ame also</p>
<pre><code class="lang-plaintext">- name: Docker build and push
  run: |
    #run commands to build and push docker images
    docker build --build-arg TMDB_V3_API_KEY=&lt;USE YOUR API KEY&gt; -t netflix .
    docker tag netflix hassanb111/netflix:${{ github.sha }}
    docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}
    docker push hassanb111/netflix:${{ github.sha }}
  env:
    DOCKER_CLI_ACI: 1
</code></pre>
<p>You can see the image, I already added</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697739277274/960ba9a6-a37d-4f52-89b0-ad242ef86d7e.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Let's commit changes</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697735887372/f4fff53d-5e8a-4171-87ab-f61d215e615b.png" alt /></p>
<p>Click on act<a target="_blank" href="https://hashnode.com/@se7enAj">ions again</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697735946338/58acfdf1-e96d-45d9-8148-2877e2e4bae6.png" alt /></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">It started t</a>he workflow buil<a target="_blank" href="https://hashnode.com/@se7enAj">d</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697737273762/3a338c77-9209-464d-8d46-46733c7fa46a.png" alt /></p>
<p><a target="_blank" href="https://hashnode.com/@se7enAj">Click on</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Build, Ana</a><a target="_blank" href="https://hashnode.com/@se7enAj">lyze and Scan</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">. You will s</a><a target="_blank" href="https://hashnode.com/@se7enAj">ee this Docke</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">r image is b</a>uilding <a target="_blank" href="https://hashnode.com/@se7enAj">now</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697784303064/218537fa-9768-4d44-8402-057d39186869.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://hashnode.com/@se7enAj">Build</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Succeeded</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697784355130/0296231f-dfc4-46cc-85dc-5da7b738b286.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>If you go to your Docker hub, you will find that the image <a target="_blank" href="https://hashnode.com/@se7enAj">is pushed to</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Dock</a><a target="_blank" href="https://hashnode.com/@se7enAj">erhub</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697784447586/e331d2f7-69cf-4767-adfc-a7457583f503.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<h3 id="heading-stehttpshashnodecomse7enajp5a-add-a-shttpsmrcloudbookhashnodedevgithub-actions-netflix-deployment-powered-by-devsecopself-hosted-runner-to-ec2"><a target="_blank" href="https://hashnode.com/@se7enAj">Ste</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">p5A: Add a s</a>elf-hosted runner to Ec2</h3>
<p>Go to GitHub and click on <mark>Setting</mark><a target="_blank" href="https://hashnode.com/@se7enAj"><mark>s --&gt; Actions -</mark></a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops"><mark>-&gt; Runners</mark></a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697784904684/3c0ee142-c3de-4727-97f8-1efd25d70fae.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Click on New se<a target="_blank" href="https://hashnode.com/@se7enAj">lf-hosted run</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ner</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697785132651/80efa346-558b-4bec-8da3-e8cb57c928d9.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Now se</a>lect <mark>Linux</mark> and Architecture <mark>X64</mark></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697785277210/ac5ac3d3-1acb-4612-996c-ddb71747ff69.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Us<a target="_blank" href="https://hashnode.com/@se7enAj">e the below c</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ommands to a</a>dd a self<a target="_blank" href="https://hashnode.com/@se7enAj">-hosted runne</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">r</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697785495740/46e13d60-5495-4c54-94a3-3c2bdea4561d.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Go to Pu</a>tty or Mobaxtre<a target="_blank" href="https://hashnode.com/@se7enAj">me and connec</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">t to your ec</a>2 instance</p>
<p>And paste the co<a target="_blank" href="https://hashnode.com/@se7enAj">mmands</a></p>
<p><a target="_blank" href="https://hashnode.com/@se7enAj"><mark>NOTE:</mark></a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops"><mark>USE YOUR RU</mark></a><mark>NNER COMMANDS (EXAMPLE CASE IAM USI</mark><a target="_blank" href="https://hashnode.com/@se7enAj"><mark>NG MINE)</mark></a></p>
<pre><code class="lang-plaintext">mkdir actions-runner &amp;&amp; cd actions-runner
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697785757454/95c807b3-fb92-4648-a209-d0e57652811d.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>The command "mkdir actions-runner &amp;&amp; cd actions-runner" is used to create a <a target="_blank" href="https://hashnode.com/@se7enAj">new directory</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">called "act</a>ions-runner" in the current working directory and then immediately change the current working directory to the newly created "actions-runner" directory. This allows you to organize your files and perform subsequent actions within the newly created directory without having to navigate to it separately.</p>
<pre><code class="lang-plaintext">curl -o actions-runner-linux-x64-2.310.2.tar.gz -L https://github.com/actions/runner/releases/download/v2.310.2/actions-runner-linux-x64-2.310.2.tar.gz
</code></pre>
<p>This command downloads a file called "actions-runner-linux-x64-2.310.2.tar.g<a target="_blank" href="https://hashnode.com/@se7enAj">z" from a spe</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">cific web ad</a>dress on GitHub and saves it in your current directory.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697785890834/03a46ac0-0fe1-4d78-8583-9c8d35d5c6fd.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Let's validate the hash installation</p>
<pre><code class="lang-plaintext">echo "fb28a1c3715e0a6c5051af0e6eeff9c255009e2eec6fb08bc2708277fbb49f93  actions-runner-linux-x64-2.310.2.tar.gz" | shasum -a 256 -c
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697785991432/05c19f2d-138b-415d-b7bc-acd1b9ffd63e.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now Extract the installer</p>
<pre><code class="lang-plaintext">tar xzf ./actions-runner-linux-x64-2.310.2.tar.gz
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697786043970/57ba915c-9e91-4944-80f2-654d90976c5f.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://hashnode.com/@se7enAj">Let's con</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">figure the r</a>unner</p>
<pre><code class="lang-plaintext">./config.sh --url https://github.com/hassanb111/Netflix-clone --token A2MXW4323ALGB72GGLH34NLFGI2T4
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697786345444/58749331-f0f4-4dac-9807-902746a80723.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Let's start runner</p>
<pre><code class="lang-plaintext">./run.sh
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697786436625/5e13c1dd-cb2e-42ec-8cf8-b5eeb965afcf.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<h3 id="heading-step5b-final-workflow-to-run-the-containerhttpshashnodecomse7enaj">Step5B: Final workflow to run the containe<a target="_blank" href="https://hashnode.com/@se7enAj">r</a></h3>
<p><a target="_blank" href="https://hashnode.com/@se7enAj">Let's add</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">a deployment</a> workfl<a target="_blank" href="https://hashnode.com/@se7enAj">ow</a></p>
<pre><code class="lang-plaintext">deploy:    
    needs: build-analyze-scan  
    runs-on: [aws-netflix]  
    steps:
      - name: Pull the docker image
        run: docker pull hassanb111/netflix:${{ github.sha }}
      - name: Trivy image scan
        run: trivy image hassanb111/netflix:${{ github.sha }}
      - name: Run the container netflix
        run: docker run -d --name netflix -p 8081:80 hassanb111/netflix:${{ github.sha }}
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697786712536/6a2f6787-26c0-4bd4-807e-9ffef33f9d69.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<ol>
<li><p><code>deploy:</code>: This is the name of a workflow or job, likely associated with a CI/<a target="_blank" href="https://hashnode.com/@se7enAj">CD pipeline.</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">It specifies</a> what should happen when this deployment job is triggered.</p>
</li>
<li><p><code>needs: build-analyze-scan</code>: This line indicates that this deployment job depe<a target="_blank" href="https://hashnode.com/@se7enAj">nds on the su</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ccessful com</a>pletion of a previous job named "build-analyze-scan." In other words, it waits for "build-analyze-scan" to finish before starting.</p>
</li>
<li><p><code>runs-on: [aws-netflix]</code>: This job is set to run on a specific type of runner <a target="_blank" href="https://hashnode.com/@se7enAj">or environmen</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">t, labeled a</a>s "aws-netflix." Runners are the environments where jobs are executed, and "aws-netflix" suggests that this deployment might be intended for an AWS-based infrastructure.</p>
</li>
<li><p><code>steps:</code>: This section lists the individual steps or tasks to be executed as p<a target="_blank" href="https://hashnode.com/@se7enAj">art of the de</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ployment job</a>.</p>
<ul>
<li><p><code>name: Pull the docker image</code>: This step has a descriptive name. It uses the <code>d</code><a target="_blank" href="https://hashnode.com/@se7enAj"><code>ocker pull</code> co</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">mmand to fet</a>ch a Docker image labeled "sevenajay/netflix:latest." This is a common step in container-based deployments, where it ensures that the latest version of the Docker image is available locally.</p>
</li>
<li><p><code>name: Trivy image scan</code>: This step performs a security scan on the Docker ima<a target="_blank" href="https://hashnode.com/@se7enAj">ge "sevenajay</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">/netflix:lat</a>est" using a tool called Trivy. Trivy is used for vulnerability scanning of container images.</p>
</li>
<li><p><code>name: Run the container netflix</code>: This step starts a Docker container named "<a target="_blank" href="https://hashnode.com/@se7enAj">netflix" usin</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">g the image</a> "sevenajay/netflix:latest." It runs the container in detached mode ("-d") and maps port 8081 on the host to port 80 in the container, making the service accessible via port 8081 on the host.</p>
</li>
</ul>
</li>
</ol>
<p>This workflow is designed to automate the deployment of a Docker container, <a target="_blank" href="https://hashnode.com/@se7enAj">with checks f</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">or the lates</a>t image, a security scan, and launching the container. The success of this job depends on the success of the preceding "build-analyze-scan" job, and it's meant to be executed on the specified runner, possibly in an AWS environment.</p>
<p>Commit changes</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697735887372/f4fff53d-5e8a-4171-87ab-f61d215e615b.png" alt /></p>
<p>Click on actions again</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697735946338/58acfdf1-e96d-45d9-8148-2877e2e4bae6.png" alt /></p>
<p>You will see two different Jobs no<a target="_blank" href="https://hashnode.com/@se7enAj">w</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697787022248/a3b34120-45dd-45d5-8f8d-ba5303b36c0a.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://hashnode.com/@se7enAj">Click on</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Buil</a><a target="_blank" href="https://hashnode.com/@se7enAj">d and Push do</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">cker image B</a><a target="_blank" href="https://hashnode.com/@se7enAj">uild (using t</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">he above ima</a>ge), you will <a target="_blank" href="https://hashnode.com/@se7enAj">see this onc</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">e the first</a> job completes</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697787115094/4bfe83a3-6b23-477b-af43-3a8e161fc0b8.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now come back by clicking on Summary and click on Deploy now</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697787219269/9f9b6c50-06cb-476d-be8d-d977794fe6e6.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>You can see h<a target="_blank" href="https://hashnode.com/@se7enAj">ow it's pulli</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ng image and</a> scanning image</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697787413957/17fa1910-0547-4c4f-9178-6d362f4954b8.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>It starts running th<a target="_blank" href="https://hashnode.com/@se7enAj">e job on your</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Ec2 instanc</a>e</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697787285371/5ff707a4-fec2-43bb-9f6d-bc3227affa92.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now it's completed running <a target="_blank" href="https://hashnode.com/@se7enAj">the container</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697787466071/0e4c055b-06ce-4239-83e4-10867018c495.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">You will</a> see this in the instance</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697787596671/0df83d09-41ca-4c0a-88b5-80338703b892.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://hashnode.com/@se7enAj">On GitHub,</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">you will se</a>e this. the build <a target="_blank" href="https://hashnode.com/@se7enAj">succeeded</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697787645836/5d4d44d1-bf33-4bdd-8045-3dcd010e1331.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><a target="_blank" href="https://hashnode.com/@se7enAj">N</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ow copy your</a> ec2 instan<a target="_blank" href="https://hashnode.com/@se7enAj">ce ip and go</a> <a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">to the brows</a>er</p>
<pre><code class="lang-plaintext">&lt;Ec2-instance-ip:8081&gt;
</code></pre>
<p><a target="_blank" href="https://hashnode.com/@se7enAj">You will se</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">e Netflix ap</a>p will run</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697787725932/3c33714a-bf1a-4446-9be4-25bcf9cd93fc.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Deployment is done.</p>
<p>FULL WORKFLOW</p>
<pre><code class="lang-plaintext">name: Build,Analyze,scan

on:
  push:
    branches:
      - main


jobs:
  build-analyze-scan:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
        with:
          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis

      - name: Build and analyze with SonarQube
        uses: sonarsource/sonarqube-scan-action@master
        env:
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
          SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

      - name: install trivy
        run: |
           #install trivy
           sudo apt-get install wget apt-transport-https gnupg lsb-release -y
           wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg &gt; /dev/null
           echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee -a /etc/apt/sources.list.d/trivy.list
           sudo apt-get update
           sudo apt-get install trivy -y
           #scanning files
           trivy fs .

      - name: Docker build and push
        run: |
          #run commands to build and push docker images
          docker build --build-arg TMDB_V3_API_KEY=cc43e68ccd7edc1f4cbe88e891ad7059 -t netflix .
          docker tag netflix hassanb111/netflix:${{ github.sha }}
          docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}
          docker push hassanb111/netflix:${{ github.sha }}
        env:
          DOCKER_CLI_ACI: 1     

  deploy:    
    needs: build-analyze-scan  
    runs-on: [aws-netflix]  
    steps:
      - name: Pull the docker image
        run: docker pull hassanb111/netflix:${{ github.sha }}
      - name: Trivy image scans
        run: trivy image hassanb111/netflix:${{ github.sha }}
      - name: Run the container netflix
        run: docker run -d --name netflix -p 8081:80 hassanb111/netflix:${{ github.sha }}
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697787897982/b38b2cbb-c497-4ab2-a88b-cbb01d191f35.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Clear the instance.</p>
<p>I hope you found this blog insightful and that you've l<a target="_blank" href="https://hashnode.com/@se7enAj">earned someth</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">ing new</a> <a target="_blank" href="https://hashnode.com/@se7enAj">about how Git</a><a target="_blank" href="https://mrcloudbook.hashnode.dev/github-actions-netflix-deployment-powered-by-devsecops">Hub Actions</a> can supercharge your Netflix deployments through the lens of DevSecOps. As technology evolves, staying informed and adaptable is key to thriving in the world of software development. If you have any questions or would like to share your thoughts, feel free to reach out. Your feedback and engagement are invaluable as we continue to explore and embrace the exciting innovations in the tech landscape. Thank you for joining me on this journey of discovery!</p>
]]></content:encoded></item><item><title><![CDATA[Deploy Netflix Clone on Cloud using Jenkins - DevSecOps Project!]]></title><description><![CDATA[Phase 1: Initial Setup and Deployment
Step 1: Launch EC2 (Ubuntu 22.04):

Provision an EC2 instance on AWS with Ubuntu 22.04.

Connect to the instance using SSH.


Step 2: Clone the Code:

Update all the packages and then clone the code.

Clone your ...]]></description><link>https://projects.hassandevops.com/deploy-netflix-clone-on-cloud-using-jenkins-devsecops-project</link><guid isPermaLink="true">https://projects.hassandevops.com/deploy-netflix-clone-on-cloud-using-jenkins-devsecops-project</guid><category><![CDATA[DevSecOps]]></category><dc:creator><![CDATA[Muhammad Hassan]]></dc:creator><pubDate>Wed, 07 Feb 2024 10:22:20 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1707301170388/bb059a89-a3bf-4ce5-96ee-cc588db33a19.avif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><img src="https://github.com/muhammadhassanb111/DevSecOps-Project/raw/main/public/assets/home-page.png" alt="Logo" /></p>
<p><strong>Phase 1: Initial Setup and Deployment</strong></p>
<p><strong>Step 1: Launch EC2 (Ubuntu 22.04):</strong></p>
<ul>
<li><p>Provision an EC2 instance on AWS with Ubuntu 22.04.</p>
</li>
<li><p>Connect to the instance using SSH.</p>
</li>
</ul>
<p><strong>Step 2: Clone the Code:</strong></p>
<ul>
<li><p>Update all the packages and then clone the code.</p>
</li>
<li><p>Clone your application's code repository onto the EC2 instance:</p>
</li>
</ul>
<ul>
<li><pre><code class="lang-plaintext">    https://github.com/muhammadhassanb111/DevSecOps-Project.git
</code></pre>
</li>
</ul>
<p><strong>Step 3: Install Docker and Run the App Using a Container:</strong></p>
<ul>
<li>Set up Docker on the EC2 instance:</li>
</ul>
<ul>
<li><pre><code class="lang-plaintext">    sudo apt-get update
    sudo apt-get install docker.io -y
    sudo usermod -aG docker $USER  # Replace with your system's username, e.g., 'ubuntu'
    newgrp docker
    sudo chmod 777 /var/run/docker.sock
</code></pre>
</li>
<li><p>Build and run your application using Docker containers:</p>
</li>
</ul>
<ul>
<li><pre><code class="lang-plaintext">    docker build -t netflix .
    docker run -d --name netflix -p 8081:80 netflix:latest

    #to delete
    docker stop &lt;containerid&gt;
    docker rmi -f netflix
</code></pre>
</li>
</ul>
<p>It will show an error cause you need API key</p>
<p><strong>Step 4: Get the API Key:</strong></p>
<ul>
<li><p>Open a web browser and navigate to TMDB (The Movie Database) website.</p>
</li>
<li><p>Click on "Login" and create an account.</p>
</li>
<li><p>Once logged in, go to your profile and select "Settings."</p>
</li>
<li><p>Click on "API" from the left-side panel.</p>
</li>
<li><p>Create a new API key by clicking "Create" and accepting the terms and conditions.</p>
</li>
<li><p>Provide the required basic details and click "Submit."</p>
</li>
<li><p>You will receive your TMDB API key.</p>
</li>
</ul>
<p>Now recreate the Docker image with your api key:</p>
<pre><code class="lang-plaintext">docker build --build-arg TMDB_V3_API_KEY=&lt;your-api-key&gt; -t netflix .
</code></pre>
<p><strong>Phase 2: Security</strong></p>
<ol>
<li><p><strong>Install SonarQube and Trivy:</strong></p>
<ul>
<li><p>Install SonarQube and Trivy on the EC2 instance to scan for vulnerabilities.</p>
<p>  sonarqube</p>
</li>
</ul>
</li>
</ol>
<ol>
<li><ul>
<li><pre><code class="lang-plaintext">     docker run -d --name sonar -p 9000:9000 sonarqube:lts-community
</code></pre>
</li>
</ul>
</li>
</ol>
<p>To access:</p>
<p>publicIP:9000 (by default username &amp; password is admin)</p>
<p>To install Trivy:</p>
<pre><code class="lang-plaintext">sudo apt-get install wget apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
echo deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main | sudo tee -a /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install trivy
</code></pre>
<p>to scan image using trivy</p>
<pre><code class="lang-plaintext">trivy image &lt;imageid&gt;
</code></pre>
<ol>
<li><p><strong>Integrate SonarQube and Configure:</strong></p>
<ul>
<li><p>Integrate SonarQube with your CI/CD pipeline.</p>
</li>
<li><p>Configure SonarQube to analyze code for quality and security issues.</p>
</li>
</ul>
</li>
</ol>
<p><strong>Phase 3: CI/CD Setup</strong></p>
<ol>
<li><p><strong>Install Jenkins for Automation:</strong></p>
<ul>
<li>Install Jenkins on the EC2 instance to automate deployment: Install Java</li>
</ul>
</li>
</ol>
<pre><code class="lang-plaintext">    sudo apt update
    sudo apt install fontconfig openjdk-17-jre
    java -version
    openjdk version "17.0.8" 2023-07-18
    OpenJDK Runtime Environment (build 17.0.8+7-Debian-1deb12u1)
    OpenJDK 64-Bit Server VM (build 17.0.8+7-Debian-1deb12u1, mixed mode, sharing)

    #jenkins
    sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
    https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
    echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
    https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
    /etc/apt/sources.list.d/jenkins.list &gt; /dev/null
    sudo apt-get update
    sudo apt-get install jenkins
    sudo systemctl start jenkins
    sudo systemctl enable jenkins
</code></pre>
<ol>
<li><ul>
<li><p>Access Jenkins in a web browser using the public IP of your EC2 instance.</p>
<p>   publicIp:8080</p>
</li>
</ul>
</li>
<li><p><strong>Install Necessary Plugins in Jenkins:</strong></p>
</li>
</ol>
<p>Goto Manage Jenkins →Plugins → Available Plugins →</p>
<p>Install below plugins</p>
<p>1 Eclipse Temurin Installer (Install without restart)</p>
<p>2 SonarQube Scanner (Install without restart)</p>
<p>3 NodeJs Plugin (Install Without restart)</p>
<p>4 Email Extension Plugin</p>
<h3 id="heading-configure-java-and-nodejs-in-global-tool-configuration"><strong>Configure Java and Nodejs in Global Tool Configuration</strong></h3>
<p>Goto Manage Jenkins → Tools → Install JDK(17) and NodeJs(16)→ Click on Apply and Save</p>
<h3 id="heading-sonarqube">SonarQube</h3>
<p>Create the token</p>
<p>Goto Jenkins Dashboard → Manage Jenkins → Credentials → Add Secret Text. It should look like this</p>
<p>After adding sonar token</p>
<p>Click on Apply and Save</p>
<p><strong>The Configure System option</strong> is used in Jenkins to configure different server</p>
<p><strong>Global Tool Configuration</strong> is used to configure different tools that we install using Plugins</p>
<p>We will install a sonar scanner in the tools.</p>
<p>Create a Jenkins webhook</p>
<ol>
<li><strong>Configure CI/CD Pipeline in Jenkins:</strong></li>
</ol>
<ul>
<li>Create a CI/CD pipeline in Jenkins to automate your application deployment.</li>
</ul>
<pre><code class="lang-plaintext">pipeline {
    agent any
    tools {
        jdk 'jdk17'
        nodejs 'node16'
    }
    environment {
        SCANNER_HOME = tool 'sonar-scanner'
    }
    stages {
        stage('clean workspace') {
            steps {
                cleanWs()
            }
        }
        stage('Checkout from Git') {
            steps {
                git branch: 'main', url: 'https://github.com/muhammadhassanb111/DevSecOps-Project.git'
            }
        }
        stage("Sonarqube Analysis") {
            steps {
                withSonarQubeEnv('sonar-server') {
                    sh '''$SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=Netflix \
                    -Dsonar.projectKey=Netflix'''
                }
            }
        }
        stage("quality gate") {
            steps {
                script {
                    waitForQualityGate abortPipeline: false, credentialsId: 'Sonar-token'
                }
            }
        }
        stage('Install Dependencies') {
            steps {
                sh "npm install"
            }
        }
    }
}
</code></pre>
<p>Certainly, here are the instructions without step numbers:</p>
<p><strong>Install Dependency-Check and Docker Tools in Jenkins</strong></p>
<p><strong>Install Dependency-Check Plugin:</strong></p>
<ul>
<li><p>Go to "Dashboard" in your Jenkins web interface.</p>
</li>
<li><p>Navigate to "Manage Jenkins" → "Manage Plugins."</p>
</li>
<li><p>Click on the "Available" tab and search for "OWASP Dependency-Check."</p>
</li>
<li><p>Check the checkbox for "OWASP Dependency-Check" and click on the "Install without restart" button.</p>
</li>
</ul>
<p><strong>Configure Dependency-Check Tool:</strong></p>
<ul>
<li><p>After installing the Dependency-Check plugin, you need to configure the tool.</p>
</li>
<li><p>Go to "Dashboard" → "Manage Jenkins" → "Global Tool Configuration."</p>
</li>
<li><p>Find the section for "OWASP Dependency-Check."</p>
</li>
<li><p>Add the tool's name, e.g., "DP-Check."</p>
</li>
<li><p>Save your settings.</p>
</li>
</ul>
<p><strong>Install Docker Tools and Docker Plugins:</strong></p>
<ul>
<li><p>Go to "Dashboard" in your Jenkins web interface.</p>
</li>
<li><p>Navigate to "Manage Jenkins" → "Manage Plugins."</p>
</li>
<li><p>Click on the "Available" tab and search for "Docker."</p>
</li>
<li><p>Check the following Docker-related plugins:</p>
<ul>
<li><p>Docker</p>
</li>
<li><p>Docker Commons</p>
</li>
<li><p>Docker Pipeline</p>
</li>
<li><p>Docker API</p>
</li>
<li><p>docker-build-step</p>
</li>
</ul>
</li>
<li><p>Click on the "Install without restart" button to install these plugins.</p>
</li>
</ul>
<p><strong>Add DockerHub Credentials:</strong></p>
<ul>
<li><p>To securely handle DockerHub credentials in your Jenkins pipeline, follow these steps:</p>
<ul>
<li><p>Go to "Dashboard" → "Manage Jenkins" → "Manage Credentials."</p>
</li>
<li><p>Click on "System" and then "Global credentials (unrestricted)."</p>
</li>
<li><p>Click on "Add Credentials" on the left side.</p>
</li>
<li><p>Choose "Secret text" as the kind of credentials.</p>
</li>
<li><p>Enter your DockerHub credentials (Username and Password) and give the credentials an ID (e.g., "docker").</p>
</li>
<li><p>Click "OK" to save your DockerHub credentials.</p>
</li>
</ul>
</li>
</ul>
<p>Now, you have installed the Dependency-Check plugin, configured the tool, and added Docker-related plugins along with your DockerHub credentials in Jenkins. You can now proceed with configuring your Jenkins pipeline to include these tools and credentials in your CI/CD process.</p>
<pre><code class="lang-plaintext">pipeline{
    agent any
    tools{
        jdk 'jdk17'
        nodejs 'node16'
    }
    environment {
        SCANNER_HOME=tool 'sonar-scanner'
    }
    stages {
        stage('clean workspace'){
            steps{
                cleanWs()
            }
        }
        stage('Checkout from Git'){
            steps{
                git branch: 'main', url: 'https://github.com/muhammadhassanb111/DevSecOps-Project.git'
            }
        }
        stage("Sonarqube Analysis "){
            steps{
                withSonarQubeEnv('sonar-server') {
                    sh ''' $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=Netflix \
                    -Dsonar.projectKey=Netflix '''
                }
            }
        }
        stage("quality gate"){
           steps {
                script {
                    waitForQualityGate abortPipeline: false, credentialsId: 'Sonar-token' 
                }
            } 
        }
        stage('Install Dependencies') {
            steps {
                sh "npm install"
            }
        }
        stage('OWASP FS SCAN') {
            steps {
                dependencyCheck additionalArguments: '--scan ./ --disableYarnAudit --disableNodeAudit', odcInstallation: 'DP-Check'
                dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
            }
        }
        stage('TRIVY FS SCAN') {
            steps {
                sh "trivy fs . &gt; trivyfs.txt"
            }
        }
        stage("Docker Build &amp; Push"){
            steps{
                script{
                   withDockerRegistry(credentialsId: 'docker', toolName: 'docker'){   
                       sh "docker build --build-arg TMDB_V3_API_KEY=&lt;yourapikey&gt; -t netflix ."
                       sh "docker tag netflix hassanb111/netflix:latest "
                       sh "docker push hassanb111/netflix:latest "
                    }
                }
            }
        }
        stage("TRIVY"){
            steps{
                sh "trivy image hassanb111/netflix:latest &gt; trivyimage.txt" 
            }
        }
        stage('Deploy to container'){
            steps{
                sh 'docker run -d --name netflix -p 8081:80 hassanb111/netflix:latest'
            }
        }
    }
}


If you get docker login failed errorr

sudo su
sudo usermod -aG docker jenkins
sudo systemctl restart jenkins
</code></pre>
<p><strong>Phase 4: Monitoring</strong></p>
<ol>
<li><p><strong>Install Prometheus and Grafana:</strong></p>
<p> Set up Prometheus and Grafana to monitor your application.</p>
<p> <strong>Installing Prometheus:</strong></p>
<p> First, create a dedicated Linux user for Prometheus and download Prometheus:</p>
</li>
</ol>
<ol>
<li><pre><code class="lang-plaintext">  sudo useradd --system --no-create-home --shell /bin/false prometheus
  wget https://github.com/prometheus/prometheus/releases/download/v2.47.1/prometheus-2.47.1.linux-amd64.tar.gz
</code></pre>
</li>
</ol>
<p>Extract Prometheus files, move them, and create directories:</p>
<pre><code class="lang-plaintext">tar -xvf prometheus-2.47.1.linux-amd64.tar.gz
cd prometheus-2.47.1.linux-amd64/
sudo mkdir -p /data /etc/prometheus
sudo mv prometheus promtool /usr/local/bin/
sudo mv consoles/ console_libraries/ /etc/prometheus/
sudo mv prometheus.yml /etc/prometheus/prometheus.yml
</code></pre>
<p>Set ownership for directories:</p>
<pre><code class="lang-plaintext">sudo chown -R prometheus:prometheus /etc/prometheus/ /data/
</code></pre>
<p>Create a systemd unit configuration file for Prometheus:</p>
<pre><code class="lang-plaintext">sudo nano /etc/systemd/system/prometheus.service
</code></pre>
<p>Add the following content to the <code>prometheus.service</code> file:</p>
<pre><code class="lang-plaintext">[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

StartLimitIntervalSec=500
StartLimitBurst=5

[Service]
User=prometheus
Group=prometheus
Type=simple
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/bin/prometheus \
  --config.file=/etc/prometheus/prometheus.yml \
  --storage.tsdb.path=/data \
  --web.console.templates=/etc/prometheus/consoles \
  --web.console.libraries=/etc/prometheus/console_libraries \
  --web.listen-address=0.0.0.0:9090 \
  --web.enable-lifecycle

[Install]
WantedBy=multi-user.target
</code></pre>
<p>Here's a brief explanation of the key parts in this <code>prometheus.service</code> file:</p>
<ul>
<li><p><code>User</code> and <code>Group</code> specify the Linux user and group under which Prometheus will run.</p>
</li>
<li><p><code>ExecStart</code> is where you specify the Prometheus binary path, the location of the configuration file (<code>prometheus.yml</code>), the storage directory, and other settings.</p>
</li>
<li><p><code>web.listen-address</code> configures Prometheus to listen on all network interfaces on port 9090.</p>
</li>
<li><p><code>web.enable-lifecycle</code> allows for management of Prometheus through API calls.</p>
</li>
</ul>
<p>Enable and start Prometheus:</p>
<pre><code class="lang-plaintext">sudo systemctl enable prometheus
sudo systemctl start prometheus
</code></pre>
<p>Verify Prometheus's status:</p>
<pre><code class="lang-plaintext">sudo systemctl status prometheus
</code></pre>
<p>You can access Prometheus in a web browser using your server's IP and port 9090:</p>
<p><code>http://&lt;your-server-ip&gt;:9090</code></p>
<p><strong>Installing Node Exporter:</strong></p>
<p>Create a system user for Node Exporter and download Node Exporter:</p>
<pre><code class="lang-plaintext">sudo useradd --system --no-create-home --shell /bin/false node_exporter
wget https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gz
</code></pre>
<p>Extract Node Exporter files, move the binary, and clean up:</p>
<pre><code class="lang-plaintext">tar -xvf node_exporter-1.6.1.linux-amd64.tar.gz
sudo mv node_exporter-1.6.1.linux-amd64/node_exporter /usr/local/bin/
rm -rf node_exporter*
</code></pre>
<p>Create a systemd unit configuration file for Node Exporter:</p>
<pre><code class="lang-plaintext">sudo nano /etc/systemd/system/node_exporter.service
</code></pre>
<p>Add the following content to the <code>node_exporter.service</code> file:</p>
<pre><code class="lang-plaintext">[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target

StartLimitIntervalSec=500
StartLimitBurst=5

[Service]
User=node_exporter
Group=node_exporter
Type=simple
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/bin/node_exporter --collector.logind

[Install]
WantedBy=multi-user.target
</code></pre>
<p>Replace <code>--collector.logind</code> with any additional flags as needed.</p>
<p>Enable and start Node Exporter:</p>
<pre><code class="lang-plaintext">sudo systemctl enable node_exporter
sudo systemctl start node_exporter
</code></pre>
<p>Verify the Node Exporter's status:</p>
<pre><code class="lang-plaintext">sudo systemctl status node_exporter
</code></pre>
<ul>
<li><p>You can access Node Exporter metrics in Prometheus.</p>
</li>
<li><p><strong>Configure Prometheus Plugin Integration:</strong></p>
<p>  Integrate Jenkins with Prometheus to monitor the CI/CD pipeline.</p>
<p>  <strong>Prometheus Configuration:</strong></p>
<p>  To configure Prometheus to scrape metrics from Node Exporter and Jenkins, you need to modify the <code>prometheus.yml</code> file. Here is an example <code>prometheus.yml</code> configuration for your setup:</p>
</li>
</ul>
<ul>
<li><pre><code class="lang-plaintext">    global:
      scrape_interval: 15s

    scrape_configs:
      - job_name: 'node_exporter'
        static_configs:
          - targets: ['localhost:9100']

      - job_name: 'jenkins'
        metrics_path: '/prometheus'
        static_configs:
          - targets: ['&lt;your-jenkins-ip&gt;:&lt;your-jenkins-port&gt;']
</code></pre>
</li>
</ul>
<p>Make sure to replace <code>&lt;your-jenkins-ip&gt;</code> and <code>&lt;your-jenkins-port&gt;</code> with the appropriate values for your Jenkins setup.</p>
<p>Check the validity of the configuration file:</p>
<pre><code class="lang-plaintext">promtool check config /etc/prometheus/prometheus.yml
</code></pre>
<p>Reload the Prometheus configuration without restarting:</p>
<pre><code class="lang-plaintext">curl -X POST http://localhost:9090/-/reload
</code></pre>
<ol>
<li><p>You can access Prometheus targets at:</p>
<p> <code>http://&lt;your-prometheus-ip&gt;:9090/targets</code></p>
</li>
</ol>
<p>####Grafana</p>
<p><strong>Install Grafana on Ubuntu 22.04 and Set it up to Work with Prometheus</strong></p>
<p><strong>Step 1: Install Dependencies:</strong></p>
<p>First, ensure that all necessary dependencies are installed:</p>
<pre><code class="lang-plaintext">sudo apt-get update
sudo apt-get install -y apt-transport-https software-properties-common
</code></pre>
<p><strong>Step 2: Add the GPG Key:</strong></p>
<p>Add the GPG key for Grafana:</p>
<pre><code class="lang-plaintext">wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
</code></pre>
<p><strong>Step 3: Add Grafana Repository:</strong></p>
<p>Add the repository for Grafana stable releases:</p>
<pre><code class="lang-plaintext">echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
</code></pre>
<p><strong>Step 4: Update and Install Grafana:</strong></p>
<p>Update the package list and install Grafana:</p>
<pre><code class="lang-plaintext">sudo apt-get update
sudo apt-get -y install grafana
</code></pre>
<p><strong>Step 5: Enable and Start Grafana Service:</strong></p>
<p>To automatically start Grafana after a reboot, enable the service:</p>
<pre><code class="lang-plaintext">sudo systemctl enable grafana-server
</code></pre>
<p>Then, start Grafana:</p>
<pre><code class="lang-plaintext">sudo systemctl start grafana-server
</code></pre>
<p><strong>Step 6: Check Grafana Status:</strong></p>
<p>Verify the status of the Grafana service to ensure it's running correctly:</p>
<pre><code class="lang-plaintext">sudo systemctl status grafana-server
</code></pre>
<p><strong>Step 7: Access Grafana Web Interface:</strong></p>
<p>Open a web browser and navigate to Grafana using your server's IP address. The default port for Grafana is 3000. For example:</p>
<p><code>http://&lt;your-server-ip&gt;:3000</code></p>
<p>You'll be prompted to log in to Grafana. The default username is "admin," and the default password is also "admin."</p>
<p><strong>Step 8: Change the Default Password:</strong></p>
<p>When you log in for the first time, Grafana will prompt you to change the default password for security reasons. Follow the prompts to set a new password.</p>
<p><strong>Step 9: Add Prometheus Data Source:</strong></p>
<p>To visualize metrics, you need to add a data source. Follow these steps:</p>
<ul>
<li><p>Click on the gear icon (⚙️) in the left sidebar to open the "Configuration" menu.</p>
</li>
<li><p>Select "Data Sources."</p>
</li>
<li><p>Click on the "Add data source" button.</p>
</li>
<li><p>Choose "Prometheus" as the data source type.</p>
</li>
<li><p>In the "HTTP" section:</p>
<ul>
<li><p>Set the "URL" to <code>http://localhost:9090</code> (assuming Prometheus is running on the same server).</p>
</li>
<li><p>Click the "Save &amp; Test" button to ensure the data source is working.</p>
</li>
</ul>
</li>
</ul>
<p><strong>Step 10: Import a Dashboard:</strong></p>
<p>To make it easier to view metrics, you can import a pre-configured dashboard. Follow these steps:</p>
<ul>
<li><p>Click on the "+" (plus) icon in the left sidebar to open the "Create" menu.</p>
</li>
<li><p>Select "Dashboard."</p>
</li>
<li><p>Click on the "Import" dashboard option.</p>
</li>
<li><p>Enter the dashboard code you want to import (e.g., code 1860).</p>
</li>
<li><p>Click the "Load" button.</p>
</li>
<li><p>Select the data source you added (Prometheus) from the dropdown.</p>
</li>
<li><p>Click on the "Import" button.</p>
</li>
</ul>
<p>You should now have a Grafana dashboard set up to visualize metrics from Prometheus.</p>
<p>Grafana is a powerful tool for creating visualizations and dashboards, and you can further customize it to suit your specific monitoring needs.</p>
<p>That's it! You've successfully installed and set up Grafana to work with Prometheus for monitoring and visualization.</p>
<ol>
<li><p><strong>Configure Prometheus Plugin Integration:</strong></p>
<ul>
<li>Integrate Jenkins with Prometheus to monitor the CI/CD pipeline.</li>
</ul>
</li>
</ol>
<p><strong>Phase 5: Notification</strong></p>
<ol>
<li><p><strong>Implement Notification Services:</strong></p>
<ul>
<li>Set up email notifications in Jenkins or other notification mechanisms.</li>
</ul>
</li>
</ol>
<h1 id="heading-phase-6-kubernetes">Phase 6: Kubernetes</h1>
<h2 id="heading-create-kubernetes-cluster-with-nodegroups">Create Kubernetes Cluster with Nodegroups</h2>
<p>In this phase, you'll set up a Kubernetes cluster with node groups. This will provide a scalable environment to deploy and manage your applications.</p>
<h2 id="heading-monitor-kubernetes-with-prometheus">Monitor Kubernetes with Prometheus</h2>
<p>Prometheus is a powerful monitoring and alerting toolkit, and you'll use it to monitor your Kubernetes cluster. Additionally, you'll install the node exporter using Helm to collect metrics from your cluster nodes.</p>
<h3 id="heading-install-node-exporter-using-helm">Install Node Exporter using Helm</h3>
<p>To begin monitoring your Kubernetes cluster, you'll install the Prometheus Node Exporter. This component allows you to collect system-level metrics from your cluster nodes. Here are the steps to install the Node Exporter using Helm:</p>
<ol>
<li>Add the Prometheus Community Helm repository:</li>
</ol>
<ol>
<li><pre><code class="lang-plaintext">  helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
</code></pre>
</li>
</ol>
<p>Create a Kubernetes namespace for the Node Exporter:</p>
<pre><code class="lang-plaintext">kubectl create namespace prometheus-node-exporter
</code></pre>
<p>Install the Node Exporter using Helm:</p>
<pre><code class="lang-plaintext">helm install prometheus-node-exporter prometheus-community/prometheus-node-exporter --namespace prometheus-node-exporter
</code></pre>
<p>Add a Job to Scrape Metrics on nodeip:9001/metrics in prometheus.yml:</p>
<p>Update your Prometheus configuration (prometheus.yml) to add a new job for scraping metrics from nodeip:9001/metrics. You can do this by adding the following configuration to your prometheus.yml file:</p>
<pre><code class="lang-plaintext">  - job_name: 'Netflix'
    metrics_path: '/metrics'
    static_configs:
      - targets: ['node1Ip:9100']
</code></pre>
<p>Replace 'your-job-name' with a descriptive name for your job. The static_configs section specifies the targets to scrape metrics from, and in this case, it's set to nodeip:9001.</p>
<p>Don't forget to reload or restart Prometheus to apply these changes to your configuration.</p>
<p>To deploy an application with ArgoCD, you can follow these steps, which I'll outline in Markdown format:</p>
<h3 id="heading-deploy-application-with-argocd">Deploy Application with ArgoCD</h3>
<ol>
<li><p><strong>Install ArgoCD:</strong></p>
<p> You can install ArgoCD on your Kubernetes cluster by following the instructions provided in the <a target="_blank" href="https://archive.eksworkshop.com/intermediate/290_argocd/install/">EKS Workshop</a> documentation.</p>
</li>
<li><p><strong>Set Your GitHub Repository as a Source:</strong></p>
<p> After installing ArgoCD, you need to set up your GitHub repository as a source for your application deployment. This typically involves configuring the connection to your repository and defining the source for your ArgoCD application. The specific steps will depend on your setup and requirements.</p>
</li>
<li><p><strong>Create an ArgoCD Application:</strong></p>
<ul>
<li><p><code>name</code>: Set the name for your application.</p>
</li>
<li><p><code>destination</code>: Define the destination where your application should be deployed.</p>
</li>
<li><p><code>project</code>: Specify the project the application belongs to.</p>
</li>
<li><p><code>source</code>: Set the source of your application, including the GitHub repository URL, revision, and the path to the application within the repository.</p>
</li>
<li><p><code>syncPolicy</code>: Configure the sync policy, including automatic syncing, pruning, and self-healing.</p>
</li>
</ul>
</li>
<li><p><strong>Access your Application</strong></p>
<ul>
<li>To Access the app make sure port 30007 is open in your security group and then open a new tab paste your NodeIP:30007, your app should be running.</li>
</ul>
</li>
</ol>
<p><strong>Phase 7: Cleanup</strong></p>
<ol>
<li><p><strong>Cleanup AWS EC2 Instances:</strong></p>
<ul>
<li>Terminate AWS EC2 instances that are no longer needed.</li>
</ul>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[Super Mario on Kubernetes using Amazon EKS!]]></title><description><![CDATA[🌐 Deployed Super Mario on Kubernetes using Amazon EKS! 🎮 Leveraged Kubernetes for container orchestration and EKS for cluster management. Super Mario is now containerized with Docker, ensuring scalability and high availability. Check out the projec...]]></description><link>https://projects.hassandevops.com/super-mario-on-kubernetes-using-amazon-eks</link><guid isPermaLink="true">https://projects.hassandevops.com/super-mario-on-kubernetes-using-amazon-eks</guid><category><![CDATA[k8s]]></category><dc:creator><![CDATA[Muhammad Hassan]]></dc:creator><pubDate>Wed, 07 Feb 2024 10:15:56 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1707300828415/753555c7-369b-412f-b122-dffda79f4af1.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>🌐 Deployed Super Mario on Kubernetes using Amazon EKS! 🎮 Leveraged Kubernetes for container orchestration and EKS for cluster management. Super Mario is now containerized with Docker, ensuring scalability and high availability. Check out the project on GitHub [<a target="_blank" href="https://lnkd.in/e9AFq2W2">https://lnkd.in/e9AFq2W2</a>] to explore how Kubernetes transforms gaming experiences in a cloud-native environment. 🚀🕹️ <a target="_blank" href="https://www.linkedin.com/feed/hashtag/?keywords=kubernetes&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7150808096238424066">hashtag#Kubernetes</a> <a target="_blank" href="https://www.linkedin.com/feed/hashtag/?keywords=amazoneks&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7150808096238424066">hashtag#AmazonEKS</a> <a target="_blank" href="https://www.linkedin.com/feed/hashtag/?keywords=supermario&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7150808096238424066">hashtag#SuperMario</a> <a target="_blank" href="https://www.linkedin.com/feed/hashtag/?keywords=cloudgaming&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7150808096238424066">hashtag#CloudGaming</a> <a target="_blank" href="https://www.linkedin.com/feed/hashtag/?keywords=techinnovation&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7150808096238424066">hashtag#</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1707300849655/994ae68a-2c5b-4abf-9cfb-dc97d0284dc9.jpeg" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1707300859748/f21919f1-5684-4eea-9837-abade59b2f22.jpeg" alt class="image--center mx-auto" /></p>
]]></content:encoded></item><item><title><![CDATA[Node.js app on Kubernetes with GitHub Actions!]]></title><description><![CDATA[🚀 Just deployed my Node.js app on Kubernetes with GitHub Actions! 🌐 Here's how:1️⃣ Testing: Ensured reliability with thorough tests.2️⃣ Code Coverage: Checked code health using npm run coverage.3️⃣ Docker Login: Securely containerized and pushed im...]]></description><link>https://projects.hassandevops.com/nodejs-app-on-kubernetes-with-github-actions</link><guid isPermaLink="true">https://projects.hassandevops.com/nodejs-app-on-kubernetes-with-github-actions</guid><category><![CDATA[github-actions]]></category><category><![CDATA[k8s]]></category><dc:creator><![CDATA[Muhammad Hassan]]></dc:creator><pubDate>Wed, 07 Feb 2024 10:13:07 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1707300745732/a1d9d20f-89f5-45fc-929c-6c826ecd17b3.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>🚀 Just deployed my Node.js app on Kubernetes with GitHub Actions! 🌐 Here's how:<br />1️⃣ Testing: Ensured reliability with thorough tests.<br />2️⃣ Code Coverage: Checked code health using npm run coverage.<br />3️⃣ Docker Login: Securely containerized and pushed images.<br />4️⃣ Deploy on K8s: Automated deployment with GitHub Actions.</p>
<p><a target="_blank" href="https://github.com/muhammadhassanb111/solar-system">https://github.com/muhammadhassanb111/solar-system</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1707300668536/f58f051e-be83-446e-8df3-cbef51aa3c8c.jpeg" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1707300679897/d04c3caa-3843-4920-a955-e7a933d41f2e.jpeg" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1707300686452/d71588e6-8951-4e71-9e01-906d4dce37eb.jpeg" alt class="image--center mx-auto" /></p>
<p><a target="_blank" href="https://www.linkedin.com/feed/hashtag/?keywords=nodejs&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7155161072851660801">hashtag#nodejs</a> <a target="_blank" href="https://www.linkedin.com/feed/hashtag/?keywords=kubernetes&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7155161072851660801">hashtag#kubernetes</a> <a target="_blank" href="https://www.linkedin.com/feed/hashtag/?keywords=githubactions&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7155161072851660801">hashtag#githubactions</a> <a target="_blank" href="https://www.linkedin.com/feed/hashtag/?keywords=devops&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7155161072851660801">hashtag#devops</a></p>
]]></content:encoded></item><item><title><![CDATA[YouTube App Deployment with GitLab CI/CD]]></title><description><![CDATA[In today's software development landscape, speed and reliability are paramount. Continuous Integration and Continuous Deployment (CI/CD) pipelines offer a way to automate and streamline your development and deployment processes. In this guide, we'll ...]]></description><link>https://projects.hassandevops.com/youtube-app-deployment-with-gitlab-cicd</link><guid isPermaLink="true">https://projects.hassandevops.com/youtube-app-deployment-with-gitlab-cicd</guid><category><![CDATA[GitLab]]></category><dc:creator><![CDATA[Muhammad Hassan]]></dc:creator><pubDate>Wed, 07 Feb 2024 10:06:13 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1707297532329/73e5ad49-533e-443b-bac7-ad75d73d377d.avif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In today's software development landscape, speed and reliability are paramount. Continuous Integration and Continuous Deployment (CI/CD) pipelines offer a way to automate and streamline your development and deployment processes. In this guide, we'll show you how to set up a complete CI/CD pipeline for a React YouTube app clone using GitLab.</p>
<p>Picture this: you're creating a YouTube-like platform where users can explore videos and channels. It's a fantastic project, but managing the development workflow can be complex. That's where GitLab CI/CD comes in, offering a straightforward and powerful solution to automate your work.</p>
<p>This step-by-step tutorial is for developers and tech enthusiasts looking to make their projects more efficient with CI/CD. By the end, you'll know how to set up a robust CI/CD pipeline, including automated testing, code quality checks, and secure containerization. Let's embark on this journey together and see how CI/CD can transform your development experience while building a React YouTube app clone.</p>
<p>Ready? Let's simplify CI/CD and make your development life easier!</p>
<h3 id="heading-youtube-video">YouTube video:</h3>
<p><a target="_blank" href="https://youtu.be/YHPvCB3IQdI">https://youtu.be/YHPvCB3IQdI</a></p>
<p>Step 1: Create an API key for Youtube.</p>
<p>Step 2: Create a Repository and push it to GitLab.</p>
<p>Step 3: Launch an Ec2 instance and run Sonarqube on it.</p>
<p>Step 4A: Create a <code>.gitlab-ci.yml</code> File.</p>
<p>Step 4B: Add the required variables for the project.</p>
<p>Step 5: Install Gitlab Runner on Ec2.</p>
<p>Step 6: Run the Application on the Docker container.</p>
<p>Step 7: Access the Application on Browser.</p>
<h3 id="heading-step-1-create-an-api-key-from-rapid-api">Step 1: Create an API key from Rapid API</h3>
<p>Open a new tab in the browser and search for <a target="_blank" href="http://rapidapi.com"><strong>rapidapi.com</strong></a></p>
<p>It will automatically provide your mail and select a mail to create an account</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697368283025/82ec778d-40b8-4ef3-87fd-a381877b0960.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Account is created</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697368308756/c9a1edc4-05ed-4f97-8d68-fda0a5cc5f38.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now in the search bar search for YouTube and select YouTube v3</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697368349278/01d54b7a-5c5b-4582-bf13-f37863d7ee02.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Copy API and save it for further use at the docker stage.</p>
<p>docker build --build-arg REACT_APP_RAPID_API_KEY=<mark>&lt;API-KEY&gt;</mark> -t ${imageName} .</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697368436144/4ccabe98-1f73-40c8-aba7-68c3034347ea.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><strong>Second way:</strong></p>
<p>Open a new tab in the browser and search for <a target="_blank" href="http://rapidapi.com"><strong>rapidapi.com</strong></a></p>
<p>You will see the page like this and click on signUp</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699451440232/00f1e56f-2c2a-4fa7-8cc7-ff29d10108c3.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now click on Sign Up with Google</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699451484458/58614730-2899-4ab2-9357-76abe1552dd9.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Select your mail here</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699451606357/481aba41-21a7-479a-9719-4965326ccb83.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>It will automatically create your account now</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699451653280/6d2a0688-acfc-4926-85e0-3e4050887b20.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now in the search bar search for YouTube and select YouTube v3</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697368349278/01d54b7a-5c5b-4582-bf13-f37863d7ee02.png?auto=compress,format&amp;format=webp" alt /></p>
<p>Copy API and save it for further use at the docker stage.</p>
<p>docker build --build-arg REACT_APP_RAPID_API_KEY=<mark>&lt;API-KEY&gt;</mark> -t ${imageName} .</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697368436144/4ccabe98-1f73-40c8-aba7-68c3034347ea.png?auto=compress,format&amp;format=webp" alt /></p>
<h3 id="heading-step-2-create-a-repository-and-push-it-to-gitlab">Step 2: Create a Repository and push it to GitLab</h3>
<p>Go to <a target="_blank" href="http://GitLab.com">GitLab.com</a> and login to your account</p>
<p>Click on New Project</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699451775243/90cda173-9382-410e-9c2d-272dec60ea7d.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Click on Create Blank Project</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699451838427/670ecd01-8c9e-4389-a015-8d15dafb2444.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Provide a name for the Project</p>
<p>Keep Visibility to the public</p>
<p>Uncheck the Readme and create the Project.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699451945375/06bcd85b-27f8-4060-ae9c-a83421361ded.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Use the below commands to push code to GitLab</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699452070613/5966ae99-4558-4ac7-ba11-5b44f36e66ca.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Files pushed to GitLab</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699452114770/1e4fdbb0-c5f2-4554-abd5-db824d5b7004.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<h3 id="heading-step-3-launch-an-ec2-instance-and-run-sonarqube-on-it">Step 3: Launch an Ec2 instance and run Sonarqube on it</h3>
<p><strong>Log into AWS Console:</strong> Sign in to your AWS account.</p>
<p><strong>Launch an Instance:</strong></p>
<p>Choose <strong>"EC2"</strong> from services. Click "Launch Instance."</p>
<p><strong>Choose an AMI:</strong> Select an Ubuntu image.</p>
<p><strong>Choose an Instance Type:</strong> Pick "t2.medium."</p>
<p><strong>Key Pair:</strong> Choose an existing key pair or create a new one.</p>
<p><strong>Configure Security Group:</strong></p>
<p>Create a new security group. Add rules for HTTP, and HTTPS, and open all ports for learning purposes. Add Storage: Allocate at least 10 GB of storage.</p>
<p><strong>Launch Instance:</strong> Review and launch the instance.</p>
<p>Access Your Instance: Use SSH to connect to your instance with the private key.</p>
<p>Keep in mind, that opening all ports is not recommended for production environments; it's just for educational purposes.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694159201292/35d8cf58-7ba8-4dc0-a1f8-9cc017439910.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><strong>Connect to Your EC2 Instance and install docker:</strong></p>
<p>Run the below commands to install the docker</p>
<pre><code class="lang-plaintext">sudo apt-get update
sudo apt-get install docker.io -y
sudo usermod -aG docker $USER   #my case is ubuntu
newgrp docker
sudo chmod 777 /var/run/docker.sock
</code></pre>
<p>After the docker installation, we will create a Sonarqube container (Remember to add 9000 ports in the security group).</p>
<p>Run this command on your EC2 instance to create a SonarQube container:</p>
<pre><code class="lang-plaintext">docker run -d --name sonar -p 9000:9000 sonarqube:lts-community
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694159658559/a607bab7-4ee0-4802-bf77-e9716ac33838.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now copy the IP address of the ec2 instance</p>
<pre><code class="lang-plaintext">&lt;ec2-public-ip:9000&gt;
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694159822624/f07bd773-5992-4b88-b849-ffcea2891b8e.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Enter username and password, click on login and change password</p>
<pre><code class="lang-plaintext">username admin
password admin
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694159867860/7425ab62-8978-4dbb-a5c5-d0eb3362c15f.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Update New password, This is Sonar Dashboard.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694159887297/6e055b5c-13ea-405f-bc13-1234b05bf2ff.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<h3 id="heading-step-4a-create-a-gitlab-ciyml-file">Step 4A: Create a <code>.gitlab-ci.yml</code> File.</h3>
<p>Now go to GitLab click on '+' and click on Newfile</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699452540234/1910a553-d454-4370-968c-bb078654a588.png?auto=compress,format&amp;format=webp?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>File name <code>.gitlab-ci.yml</code></p>
<p>Content</p>
<pre><code class="lang-plaintext">stages:
    - npm

Install dependecy:
    stage: npm    
    image:
        name: node:16
    script:
        - npm install
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699452609575/a9a0d794-a5c7-4501-8d9d-93f093441e8d.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Commit the changes and it will automatically start the build</p>
<p>Now click on Build and Pipelines</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699452738697/d2dfd55d-cae4-4c5c-876b-6da33b438b42.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now click on Running.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699452805209/23c81d3b-531f-42ca-a320-bd8a6e056386.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Click on Install dependency</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699452923723/318afb5c-e74d-4104-a8df-07ff46372147.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>You will build output</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699452985679/04534cfb-6397-47a1-92df-c7da376afb44.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now add the Sonarqube stage to the pipeline</p>
<p>Go to the Sonarqube dashboard and click on Manually.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699453113737/703cb437-6072-4c62-b4f5-b3182244e91c.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Provide the name of the Project and click on Setup</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699453190201/9e10f50d-a125-41a8-b400-4b24b4df6944.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Select the CI tool as GitLab CI</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699453238357/cf6ae97a-a6fd-4d28-8a7e-0505cf3dc032.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Select Other because we are using the JS App</p>
<p>It will provide code and we need to create a file inside our repo</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699453308067/e9219457-2bba-4ca3-84c9-3933ec1092cf.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Go to Gitlab and click on + and Newfile</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699452540234/1910a553-d454-4370-968c-bb078654a588.png" alt /></p>
<p>Filename is <code>sonar-project.properties</code></p>
<p>Paste the content that you got from Sonarqube</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699453515944/6a8cd5e1-80b4-4b72-9958-8c704182f741.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>The file looks like this and click on commit changes</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699453557845/3badc428-61bc-40b8-b30b-d69b3b52f4c7.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Go to Sonarqube and click on continue</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699453614668/8ef310fb-7306-4863-9f0b-2eebf6d80ad0.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now it will provide Variables to add to our GitLab</p>
<h3 id="heading-step-4b-add-the-required-variables-for-the-project">Step 4B: Add the required variables for the project.</h3>
<p>Variables Generated</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699454672224/22cea9c4-f102-44af-babb-4a4e1a5c77e7.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now go to GitLab</p>
<p>Click on settings and CI/CD</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699454768899/f3f9475f-71f3-42ae-b980-c4f4d5799dc3.png?auto=compress,format&amp;format=webp?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Click on Expand in variables</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699454881700/a5d831b7-bdad-40fc-8860-7be1d14ae108.png?auto=compress,format&amp;format=webp?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Click on Add variable</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699454933773/f3a7406f-ff27-4e59-ad51-2b560c8b9514.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now go back to Sonarqube and copy the Key</p>
<p>Click on Generate a token</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699455069519/8d9b9784-ee94-45f4-b31d-2fc489cb8fe1.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Again Click on Generate</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699455192574/d7b64024-d697-4994-bfcf-a1e992242864.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Copy the token</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699455122645/0fee8721-f955-4823-ad72-96fb76c81d06.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now come back to GitLab and add them like the below image and click on add variable.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699455326754/a3e4c640-3d74-45c5-a384-c693b12762ae.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Sonar token is added</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699458436039/80e686d4-fb61-4290-ac95-c9cf10fe0bab.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now go to the Sonarqube Dashboard again</p>
<p>Let's add another variable, copy them</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699458516421/555516f9-2dfa-432c-884f-a74940e1bbab.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now go to GitLab and click on Add variable</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699458605982/ffec759c-7dae-40f5-a298-dd9d6ce8bbea.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Add the copied values like the below image</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699458655369/84b8e4c3-4521-4ff2-aa33-ec1dff726c0f.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Two variables were added.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699458724321/4d614a87-4c37-482b-98f0-de7f46311159.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now go back to the Sonarqube Dashboard</p>
<p>Click on continue</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699458788856/9016e8c4-c62f-46fd-a3ba-c632ae12a52d.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>It will provide and CI configuration file copy it and use it inside our <code>.gitlab-ci.yml</code> file</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699458903130/777eab4b-46a2-4cd9-897a-89d6ec124d08.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now go back to GitLab and edit the <code>.gitlab-ci.yml</code> file</p>
<p>Full file (update with your content)</p>
<pre><code class="lang-plaintext">stages:
    - npm
    - sonar

Install dependecy:
    stage: npm    
    image:
        name: node:16
    script:
        - npm install    

sonarqube-check:
  stage: sonar
  image: 
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script: 
    - sonar-scanner
  allow_failure: true
  only:
    - main
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699459068250/84f95e79-99a8-4555-9f45-4a7c2984f82e.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Commit changes and it will automatically start the build.</p>
<p>Click on Build --&gt; Pipelines</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699459257511/7b7ccfa3-db61-42ed-9d82-f95e682a2ef9.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Click on Running</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699459344571/90ced23e-eae2-4cd2-aa9b-fb13d54fd3a5.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now click on Sonarqube-check</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699459388669/fcaeb85a-5339-43bb-8593-87e58846470f.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1706691995933/e3ff1093-bb4e-4bc7-8084-9742e7067185.png?auto=compress,format&amp;format=webp" alt /></p>
<p>Build output</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699459421037/66465bd9-851a-4624-bd5d-d27a60d64c42.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now add the next stage of the Trivy file scan</p>
<p>Update the <code>.gitlab-ci.yml</code> file</p>
<pre><code class="lang-plaintext">stages:
    - npm
    - sonar
    - trivy file scan

Install dependecy:
    stage: npm    
    image:
        name: node:16
    script:
        - npm install    

sonarqube-check:
  stage: sonar
  image: 
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script: 
    - sonar-scanner
  allow_failure: true
  only:
    - main

Trivy file scan:
  stage: trivy file scan
  image:
    name: aquasec/trivy:latest
    entrypoint: [""]
  script:
    - trivy fs .
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699459867536/6b14f916-3182-44ba-a2d6-efa6c2fbcbac.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Commit changes and go to pipeline stages</p>
<p>Click on the Trivy file scan</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699459993243/b8a4dff7-d8ac-458e-b9dd-23d567527a10.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Build output</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699460035893/569b64ca-54f5-4d18-8c57-0e0e41a6a168.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Add the Docker build and push stage</p>
<p>Before that Add docker credentials to GitLab Variables as secrets.</p>
<p>Go to the docker hub and create a Personal Access token</p>
<p>Click on your profile name and Account Settings</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699460746374/7c8409f6-5bd8-4536-b505-58e859e8c4c6.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now click on Security --&gt; New Access Token</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699460814896/5b42c310-a512-4654-8463-10779d7b8fce.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Provide a name --&gt; Generate</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699460863720/a48f7f33-074a-4111-a066-5fc5e476031a.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now copy the token and keep it safe</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699460932872/efa3e8bf-5fc1-47f4-a06c-e0e61305834b.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now go back to Gitlab</p>
<p>Click on settings and CI/CD</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699454768899/f3f9475f-71f3-42ae-b980-c4f4d5799dc3.png" alt /></p>
<p>Click on Expand in variables</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699454881700/a5d831b7-bdad-40fc-8860-7be1d14ae108.png" alt /></p>
<p>Click on Add variable</p>
<p>Use your DockerHub username in value and Add variable</p>
<p>Key DOCKER_USERNAME</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699461168875/b63c5f77-60d1-44b3-b955-691627c032f6.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Click on Add variable again</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699461254121/79877f0e-4100-4ad6-a527-901f1ac169dd.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Key DOCKER_PASSWORD</p>
<p>For value use the Generated Personal Access token and add a variable.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699461312976/416d164b-296a-4fac-8b41-007643a60c6f.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Variables added.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699461412146/24f15467-af4d-4b2a-a8ec-00773b031e48.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now add the below stage to the Configuration <code>.gitlab-ci.yml</code> file</p>
<p>Added Docker and Trivy image scan stages</p>
<pre><code class="lang-plaintext">stages:
    - npm
    - sonar
    - trivy file scan
    - docker
    - trivy image scan

Install dependecy:
    stage: npm    
    image:
        name: node:16
    script:
        - npm install    

sonarqube-check:
  stage: sonar
  image: 
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script: 
    - sonar-scanner
  allow_failure: true
  only:
    - main

Trivy file scan:
  stage: trivy file scan
  image:
    name: aquasec/trivy:latest
    entrypoint: [""]
  script:
    - trivy fs . 

Docker build and push:
  stage: docker
  image:
    name: docker:latest
  services:
    - docker:dind   
  script:
    - docker build --build-arg REACT_APP_RAPID_API_KEY=f0ead79813mshb0aa7ddf114a7dap1adb3djsn483b017de1a9 -t youtubev1 .    
    - docker tag youtubev1 hassanb111/youtubev1:latest
    - docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
    - docker push hassanb111/youtubev1:latest

Scan image:
  stage: trivy image scan
  image:
    name: aquasec/trivy:latest
    entrypoint: [""]
  script:
    - trivy image hassanb111/youtubev1:latest
</code></pre>
<p>Added stages</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699461630726/95375272-9cff-40ac-9314-ed7170081d1a.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Commit changes and it will automatically start building.</p>
<p>Go to Pipelines view</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699461750535/b0365c17-c9a0-4210-bd8b-5cccaee8350d.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now click on Docker build and push</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699461833223/8e163651-aab9-4b3a-82dd-31afa34f2e13.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Build view</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699462049675/4e0692ac-1d73-4172-839d-aabe40656b3d.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699462057276/407cc0f4-cd34-4536-9493-1608ec076939.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Go to Dockerhub and see the image</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699462100916/b8bea68b-1d89-4324-b722-249c0084a213.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now come back to GitLab and click on Trivy image scan</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699462164271/8665eb18-3c89-4c7a-af46-a0898337a93d.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Output raw</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699462215958/0dc44340-f401-4db8-b895-c29239cd7ed2.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<h3 id="heading-step-5-install-gitlab-runner-on-ec2">Step 5: Install Gitlab Runner on Ec2</h3>
<p>Go to GitLab and Click on Settings and CI/CD</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699454768899/f3f9475f-71f3-42ae-b980-c4f4d5799dc3.png" alt /></p>
<p>Click on Expand at Runners</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699496390091/debb391d-790a-44da-8e7e-05fa45a89d9a.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Click on Three dots and then click on Show Runner installation</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699496481444/b65ca11e-c3ed-482b-b88f-ca09de982e91.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Click on Linux and amd64 and copy the commands</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699496578546/89e00113-ad74-49e5-8429-8afbe613432e.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now come back to Putty or Mobaxtreme</p>
<p>Create a new file</p>
<pre><code class="lang-plaintext">sudo vi gitlab-runner-installation
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699496723526/5171e599-9ef4-4ea6-85f1-22f10ebe94be.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Paste the below commands into it</p>
<pre><code class="lang-plaintext"># Download the binary for your system
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64

# Give it permission to execute
sudo chmod +x /usr/local/bin/gitlab-runner

# Create a GitLab Runner user
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash

# Install and run as a service
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699496847567/f7d6b7b4-8911-4716-a005-3fc9a40aea8e.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Provide executable permissions and run the script</p>
<pre><code class="lang-plaintext">sudo chmod +x &lt;file-name&gt;
./&lt;file-name&gt;
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699496912602/8b0ce19c-9936-4af7-a31a-ef9bdff61ca6.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Installation completed</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699496951977/da63c9a2-7b9b-4704-8773-f48e6df332db.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Start the GitLab runner</p>
<pre><code class="lang-plaintext">sudo gitlab-runner start
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699497141540/d2f13a08-dbe8-4a69-b6cc-53d959a576b0.png?auto=compress,format&amp;format=webp?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now run the below command or your command to register the runner</p>
<p>Update the token is enough</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699497176944/40784d71-02ec-4ea2-9a2a-a27bc2ef176e.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<pre><code class="lang-plaintext">sudo gitlab-runner register --url https://gitlab.com/ --registration-token &lt;token&gt;
</code></pre>
<p>Provide the details for registering the runner</p>
<ol>
<li><p>Provide Enter for <a target="_blank" href="http://GitLab.com">GitLab.com</a></p>
</li>
<li><p>For token we already added with token, so click on Enter again</p>
</li>
<li><p>Description as your wish</p>
</li>
<li><p>Tags also and you can use multiple tags by providing a comma after each tga</p>
</li>
<li><p>Maintenance note is just optional</p>
</li>
<li><p>For executors use Shell</p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699497412725/c1a2fa03-a00f-4680-a063-9a7628a70c25.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Runner added successfully.</p>
<p>Start the GitLab runner</p>
<pre><code class="lang-plaintext">sudo gitlab-runner start
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699497141540/d2f13a08-dbe8-4a69-b6cc-53d959a576b0.png" alt /></p>
<p>Run the GitLab runner</p>
<pre><code class="lang-plaintext">sudo gitlab-runner run
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699497647142/86e76d77-d0c1-4f8f-b33c-235fccd872bf.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Go to GitLab and refresh the page once or click on Enable for this project</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699497778257/f644495c-f055-4248-9284-44170acd350d.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now the runner is active and waiting for jobs</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699497860970/90704675-cf26-476e-988f-aa19d1a4839e.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Click on the Pencil mark to edit</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699497961772/47ae60e1-4bd3-44cb-9ed2-1ea5a54e206f.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Click on the Check box to indicate whether this runner can pick jobs without tags.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699498014680/42aeb192-53e8-4034-af22-dcd8f824a6e1.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Click on save changes.</p>
<h3 id="heading-step-6-run-the-application-on-the-docker-container">Step 6: Run the Application on the Docker container</h3>
<p>Now edit the <code>.gitlab-ci.yml</code> file for the deploy stage</p>
<p>The complete file</p>
<pre><code class="lang-plaintext">stages:
    - npm
    - sonar
    - trivy file scan
    - docker
    - trivy image scan
    - run container

Install dependecy:
    stage: npm    
    image:
        name: node:16
    script:
        - npm install    

sonarqube-check:
  stage: sonar
  image: 
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script: 
    - sonar-scanner
  allow_failure: true
  only:
    - main

Trivy file scan:
  stage: trivy file scan
  image:
    name: aquasec/trivy:latest
    entrypoint: [""]
  script:
    - trivy fs . 

Docker build and push:
  stage: docker
  image:
    name: docker:latest
  services:
    - docker:dind   
  script:
    - docker build --build-arg REACT_APP_RAPID_API_KEY=f0ead79813mshb0aa7ddf114a7dap1adb3djsn483b017de1a9 -t youtubev1 .    
    - docker tag youtubev1 hassanb111/youtubev1:latest
    - docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
    - docker push hassanb111/youtubev1:latest

Scan image:
  stage: trivy image scan
  image:
    name: aquasec/trivy:latest
    entrypoint: [""]
  script:
    - trivy image hassanb111/youtubev1:latest

deploy:
  stage: run container
  tags:
    - youtube        #use your own tags 
  script:
    - docker run -d --name youtube -p 3000:3000 hassanb111/youtubev1:latest
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699498330575/911dcf06-c765-472d-9365-9deb15d40aa7.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Commit changes, it will automatically start to build</p>
<p>Click on Build --&gt; Pipelines</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699498482326/67580d52-ac14-4366-8311-486ca6992da3.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Click on Running</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699498530920/f1797acb-99b7-49cb-8a93-04841ac02027.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>The last stage is added to the Pipeline</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699498599684/c6df4448-104e-4f6c-ad2c-47c89b0b2e3f.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>If you get an error like this</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699502625809/10f5e76f-0f2a-4c1b-9476-c127137424cd.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Go to GitLab and click on deploy job</p>
<p>Let's see what is the error</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699502669596/c5411778-9bbc-42ce-8c2b-a6e4a43f587b.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>If you get an error like this, click on that link</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699502747916/8fadd648-572e-44a7-a985-f875b2fcf2ec.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>It will open a new tab and provide a solution for that</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699502840964/4e11fc1d-5470-4f3d-9409-b8aa87bb6bea.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now go to Mobaxtreme and stop the Runner</p>
<p>Go to root and use the below commands</p>
<pre><code class="lang-plaintext">sudo su
sudo vi /home/gitlab-runner/.bash_logout
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699502967163/b6b738e4-55ef-47c2-9b11-b4161be5a892.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>You will see file like this</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699503008404/5065157e-8f53-4b3e-8498-0be4ebeb725a.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Comment them</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699503040759/93a93949-7031-4514-9917-fa1af41d0841.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Save and exit from that file and restart GitLab runner</p>
<pre><code class="lang-plaintext">sudo gitlab-runner restart
exit #from root
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699506206570/47caec6b-d6e8-4be7-9e1f-6bed8c93b7b7.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now start and Run the GitLab runner</p>
<pre><code class="lang-plaintext">sudo gitlab-runner start
sudo gitlab-runner run
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699506253690/007c6be8-483c-4d76-a15d-6119fcb539e7.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now go to GitLab --&gt; Build --&gt; Pipelines</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699506271429/7fe88464-cb96-42a6-9f1c-f68f37eefe48.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Click on Run Pipeline</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699506297695/0a2bcc5f-70ea-421a-9bed-be6345fac5c7.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Again Click on Run Pipeline</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699506320815/c7cf6d9f-7064-4a58-a92d-b9ee5e7596ff.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Build completed and click on Deploy job</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699506355412/2565dc1a-c999-456e-a60c-e8f52f352a22.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>See the output it ran a container on ec2</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699506386737/0a65db61-87c6-43be-abde-dfeb56ba45b3.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Now go to MobaXtreme or Putty and Provide the below command to see running containers.</p>
<pre><code class="lang-plaintext">docker ps
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699506425447/c92295b1-6c54-4f31-b826-48dd34ccda51.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p>Container running.</p>
<h3 id="heading-step-7-access-the-application-on-browser">Step 7: Access the Application on Browser</h3>
<p>Copy the Public IP of the ec2 instance and paste it into the Browser.</p>
<p>Don't forget to open the 3000 port in the Security Group</p>
<pre><code class="lang-plaintext">&lt;Public-ip:3000&gt;
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699506610475/7e8cca2c-b000-4cd4-8b4a-a706391a4bf5.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699506627834/248f2f9c-f58d-4c3f-8590-cc06133dfede.png?auto=compress,format&amp;format=webp&amp;auto=compress,format&amp;format=webp" alt /></p>
<h3 id="heading-step-8-termination">Step 8: Termination</h3>
<ol>
<li><p>Delete the personal Access token of the docker.</p>
</li>
<li><p>Delete the containers.</p>
</li>
</ol>
<ol>
<li><pre><code class="lang-plaintext">    docker stop &lt;container name&gt;
    docker rm &lt;container name&gt;
</code></pre>
</li>
<li><p>Delete the Ec2 instance.</p>
</li>
</ol>
<p>And there you have it, folks! You're now the DevOps master of your YouTube app deployment universe. We've journeyed through code, quality, security, containers, and automation, all with GitLab as our trusty sidekick. Now it's your turn to unleash the power of DevOps and take your YouTube app to the next level!</p>
<p>So, what's next on your development adventure? Whether it's conquering new projects, exploring even cooler tech, or simply celebrating with a well-deserved coffee break, remember that DevOps is all about making your life easier and your code better. Embrace the joy of seamless deployments, keep learning, and never stop having fun in the ever-evolving world of software development. 🚀😎</p>
<p>If you enjoyed this Blog, don't forget to hit that like button, share with your fellow tech enthusiasts, and subscribe for more exciting DevOps adventures. And as always, stay curious, stay creative, and keep coding with a smile! 😄✨</p>
]]></content:encoded></item><item><title><![CDATA[deployed a 10-tier microservices application using Azure DevOps]]></title><description><![CDATA[🚀 Exciting News! Just deployed a 10-tier microservices application using Azure DevOps, ensuring top-notch quality with static code testing through SonarQube, and running on Amazon EKS! 🌐💡 What's the takeaway?Azure DevOps: Simplifying complex deplo...]]></description><link>https://projects.hassandevops.com/deployed-a-10-tier-microservices-application-using-azure-devops</link><guid isPermaLink="true">https://projects.hassandevops.com/deployed-a-10-tier-microservices-application-using-azure-devops</guid><category><![CDATA[azure-devops]]></category><dc:creator><![CDATA[Muhammad Hassan]]></dc:creator><pubDate>Wed, 07 Feb 2024 08:47:36 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1707295634114/bc41e0e7-0440-4ed1-b1f5-f391ce787a6d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>🚀 Exciting News! Just deployed a 10-tier microservices application using Azure DevOps, ensuring top-notch quality with static code testing through SonarQube, and running on Amazon EKS! 🌐<br />💡 What's the takeaway?<br />Azure DevOps: Simplifying complex deployments with a seamless CI/CD experience.<br />SonarQube: Elevating code quality and security through rigorous static code analysis.<br />Amazon EKS: Harnessing the agility of Kubernetes for optimal container management.<br />🔗 Explore the repository here: <a target="_blank" href="https://lnkd.in/dCrvER9a">https://lnkd.in/dCrvER9a</a><br />Followed the guidance of <a target="_blank" href="https://www.linkedin.com/in/adityajaiswal7/">Aditya Jaiswal</a> to make this journey seamless. 🙌<br /><a target="_blank" href="https://www.linkedin.com/feed/hashtag/?keywords=azuredevops&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7158017455209000960">hashtag#AzureDevOps</a> <a target="_blank" href="https://www.linkedin.com/feed/hashtag/?keywords=sonarqube&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7158017455209000960">hashtag#SonarQube</a> <a target="_blank" href="https://www.linkedin.com/feed/hashtag/?keywords=microservices&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7158017455209000960">hashtag#Microservices</a> <a target="_blank" href="https://www.linkedin.com/feed/hashtag/?keywords=eks&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7158017455209000960">hashtag#EKS</a> <a target="_blank" href="https://www.linkedin.com/feed/hashtag/?keywords=cloudcomputing&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A7158017455209000960">hashtag#CloudCom</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1707295516772/85fc4148-0cec-47c8-a5b3-ebe076ee99b2.jpeg" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1707295522426/c22aa102-193a-4da9-9f7d-4d91480c620c.jpeg" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1707295547484/aa9002c5-bb71-4109-bd21-f4c4cc5e85e4.jpeg" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1707295553315/29bc863c-ec1b-4856-b175-1e58e1b13d69.jpeg" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1707295559360/c270cc7f-44c2-4b9b-880c-c85e43049274.jpeg" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1707295569747/cc8b3c95-7392-452d-8419-b7c574edda9c.jpeg" alt class="image--center mx-auto" /></p>
]]></content:encoded></item><item><title><![CDATA[Automating CI/CD with Jenkins: A Dockerized Approach]]></title><description><![CDATA[In today's fast-paced world of software development, the need for automation in building, testing, and deploying applications is more critical than ever. Continuous Integration (CI) and Continuous Deployment (CD) pipelines play a key role in streamli...]]></description><link>https://projects.hassandevops.com/automating-cicd-with-jenkins-a-dockerized-approach</link><guid isPermaLink="true">https://projects.hassandevops.com/automating-cicd-with-jenkins-a-dockerized-approach</guid><category><![CDATA[#]]></category><dc:creator><![CDATA[Muhammad Hassan]]></dc:creator><pubDate>Wed, 07 Feb 2024 08:41:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1707295229581/b0bb1df6-9375-4601-a3f2-74e911885d59.avif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In today's fast-paced world of software development, the need for automation in building, testing, and deploying applications is more critical than ever. Continuous Integration (CI) and Continuous Deployment (CD) pipelines play a key role in streamlining these processes. In this blog post, we'll explore a Jenkins pipeline written in Groovy that leverages Docker to automate these tasks seamlessly.</p>
<h4 id="heading-jenkins-pipeline-overview">Jenkins Pipeline Overview:</h4>
<p>Our Jenkins pipeline consists of several stages, each serving a specific purpose:</p>
<ol>
<li><p><strong>Code Stage:</strong></p>
<pre><code class="lang-plaintext"> groovyCopy codestage('code') {
     steps {
         git url: 'https://github.com/muhammadhassanb111/node-todo-cicd.git', branch: 'master'
     }
 }
</code></pre>
<p> In this stage, we fetch the latest code from our GitHub repository, ensuring that we're always working with the most up-to-date version of our application.</p>
</li>
<li><p><strong>Build and Test Stage:</strong></p>
<pre><code class="lang-plaintext"> groovyCopy codestage('build and test') {
     steps {
         script {
             echo '=== Building Docker Image ==='
             sh 'docker build . -t hassanb111/node-todo-app:latest'
             echo '=== Docker Image Built ==='

             echo '=== Docker Images List ==='
             sh 'docker images'
             echo '=== End of Docker Images List ==='
         }
     }
 }
</code></pre>
<p> In this stage, we build a Docker image from our application's Dockerfile. The process is accompanied by informative messages, and we list the Docker images for visibility.</p>
</li>
<li><p><strong>Login and Push Images Stage:</strong></p>
<pre><code class="lang-plaintext"> groovyCopy codestage('login and push images') {
     steps {
         echo 'Logging into Docker Hub'
         withCredentials([usernamePassword(credentialsId: 'dockerhub', passwordVariable: 'dockerhubpassword', usernameVariable: 'dockerhubuser')]) {
             sh "docker login -u ${env.dockerhubuser} -p ${env.dockerhubpassword}"
             sh "docker push hassanb111/node-todo-app:latest"
         }
     }
 }
</code></pre>
<p> This stage handles the secure login to Docker Hub using Jenkins credentials and subsequently pushes the Docker image to the Docker Hub repository.</p>
</li>
<li><p><strong>Deploy Stage:</strong></p>
<pre><code class="lang-plaintext"> groovyCopy codestage('deploy') {
     steps {
         script {
             echo '=== Stopping and Removing Containers ==='
             sh 'docker-compose down'
             echo '=== Containers Stopped and Removed ==='

             echo '=== Starting Containers ==='
             sh 'docker-compose up -d'
             echo '=== Containers Started ==='
         }
     }
 }
</code></pre>
<p> The final stage involves stopping and removing existing Docker containers and then initiating fresh containers using Docker Compose.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1703055382007/323eb73a-bcba-4175-a6fd-a78523dee770.png" alt /></p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1703055424161/6b6c8a88-ce23-4650-94b7-ac464fa6551c.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1703055725607/444a0fa6-28a9-4e64-a413-ed3a6e62065c.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1703055495544/f41d677c-b2c2-4862-b521-01d3bf69ab2b.png" alt class="image--center mx-auto" /></p>
<p>By breaking down our CI/CD process into these stages, we ensure a systematic and automated approach to software development. This Jenkins pipeline, combined with Docker, provides a powerful foundation for building, testing, and deploying applications efficiently.</p>
]]></content:encoded></item></channel></rss>