YouTube Clone with Slack Notifications Integration
Introduction
Today, we are excited to embark on the deployment of our YouTube clone project. This project is not only a valuable addition to your portfolio but also showcases a range of skills and technologies that are highly relevant in today’s tech industry.
Step 1: Create an IAM Role
Go to AWS Console and Navigate to IAM Role and Click on it.
Follow the below process.
Step 2: Create a server
- Go to the AWS Console and Launch Ubuntu 22.04, t2.medium Instance, And in User Data Paste the below Script.
#!/bin/bash
sudo apt update -y
wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | tee /etc/apt/keyrings/adoptium.asc
echo "deb [signed-by=/etc/apt/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | tee /etc/apt/sources.list.d/adoptium.list
sudo apt update -y
sudo apt install temurin-17-jdk -y
/usr/bin/java --version
#install jenkins
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
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 > /dev/null
sudo apt-get update -y
sudo apt-get install jenkins -y
sudo systemctl start jenkins
sudo systemctl status jenkins
#install docker
sudo apt-get update
sudo apt-get install docker.io -y
sudo usermod -aG docker ubuntu
sudo usermod -aG docker jenkins
newgrp docker
sudo chmod 777 /var/run/docker.sock
sudo systemctl restart jenkins
# 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 > /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
# Install Terraform
sudo apt install wget -y
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
# Install kubectl
sudo apt update
sudo apt install curl -y
curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client
Step 3: Setup Jenkins
- Follow the below process which is in the below article
Step 4: Install Plugins
All plugins related to Docker
All Plugins related to Slack
Eclipse Temurin
NodeJs
Step 5: Tools Installation
- For tools installation for the below process
- You can also use SonarQube and other Tools, for that follow this article
- After installing all the tools, Let's create a Pipeline now.
Step 6: Pipeline Creation
- Head to the Jenkins Dashboard, Click New Item, And Create a Pipeline.
- Paste the below pipeline in the pipeline section.
pipeline {
agent any
tools {
jdk 'jdk17'
nodejs 'node16'
}
stages {
stage('Clean Workspace') {
steps {
cleanWs()
}
}
stage('Checkout from Git') {
steps {
git branch: 'main', url: 'https://github.com/nacromancer858/youtube-clone-app.git'
}
}
stage('Install Dependencies') {
steps {
sh "npm install"
}
}
stage('Docker Build & Push') {
steps {
script {
withDockerRegistry(credentialsId: 'docker', toolName: 'docker') {
sh "docker build -t youtube-clone ."
sh "docker tag youtube-clone nacromancer858/youtube-clone:latest"
sh "docker push nacromancer858/youtube-clone:latest"
}
}
}
}
stage('Deploy to Container') {
steps {
sh 'docker run -d --name youtube-clone -p 3000:3000 nacromancer858/youtube-clone:latest'
}
}
}
}
Save and Build.
Then you can see your application is running on Port 3000 with your Instance IP. If not then check your Security Groups and all.
Step 7: Slack Integration with Jenkins
Go to the browser and search for Slack.
Then follow the account creation process as below.
- Give some project name or team's name.
- Then you can see like this.
- Then search for Slack app directory and Search for Jenkins CI.
- Select your channel name
- Then you can see like this.
Go to the Jenkins Dashboard, Then to Manage Jenkins and in System.
Search for "Slack" and enter the details. In the "Workspace" field, use the Team subdomain you obtained in the previous step. For the "Credentials" section, click on "Add." Then, select "Secret text" from the "Kind" dropdown menu. Paste your Integration Token credential ID, which you retrieved earlier, into the "Secret" field. Finally, provide a name and description for the credential.
- Click on save. Then you can see a new notification that came on Slack.
- Now edit the pipeline and run it again then you can see the result of the pipeline over the slack.
pipeline {
agent any
tools {
jdk 'jdk17'
nodejs 'node16'
}
stages {
stage('Clean Workspace') {
steps {
cleanWs()
}
}
stage('Checkout from Git') {
steps {
git branch: 'main', url: 'https://github.com/Saurabh-DevOpsVoyager77/youtube-clone-app.git'
}
}
stage('Install Dependencies') {
steps {
sh "npm install"
}
}
stage('Docker Build & Push') {
steps {
script {
withDockerRegistry(credentialsId: 'docker', toolName: 'docker') {
sh "docker build -t youtube-clone ."
sh "docker tag youtube-clone nacromancer858/youtube-clone:latest"
sh "docker push nacromancer858/youtube-clone:latest"
}
}
}
}
stage('Deploy to Container') {
steps {
sh 'docker run -d --name youtube-clone -p 3000:3000 nacromancer858/youtube-clone:latest'
}
}
}
post {
success {
slackSend(channel: '#all-the-cloud-hub', color: 'good', message: "Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL}) was successful.")
}
failure {
slackSend(channel: '#all-the-cloud-hub', color: 'danger', message: "Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL}) failed.")
}
always {
echo 'Build finished, check Slack for notifications.'
}
}
}
In this guide, we successfully deployed a YouTube clone project using Jenkins, Docker, and AWS. We set up an IAM role, configured an Ubuntu server with essential tools, and installed Jenkins. We created a Jenkins pipeline to automate the build and deployment process, including Docker image management.
We also integrated Slack with Jenkins for real-time notifications on build statuses. This streamlined setup showcases a practical and efficient approach to modern DevOps practices, ensuring smooth and automated deployments.
Feel free to adapt this process to suit other projects or environments as needed.
Subscribe to my newsletter
Read articles from Saurabh Adhau directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Saurabh Adhau
Saurabh Adhau
As a DevOps Engineer, I thrive in the cloud and command a vast arsenal of tools and technologies: ☁️ AWS and Azure Cloud: Where the sky is the limit, I ensure applications soar. 🔨 DevOps Toolbelt: Git, GitHub, GitLab – I master them all for smooth development workflows. 🧱 Infrastructure as Code: Terraform and Ansible sculpt infrastructure like a masterpiece. 🐳 Containerization: With Docker, I package applications for effortless deployment. 🚀 Orchestration: Kubernetes conducts my application symphonies. 🌐 Web Servers: Nginx and Apache, my trusted gatekeepers of the web.