Welcome to the DevOps Essentials Lab Cheat Sheet!
This guide provides step-by-step instructions for completing various DevOps labs, covering tasks like:
Setting up servers using Terraform,
Working with Git and GitHub,
Configuring Jenkins and GitWebHook,
and Deploying code in Docker containers.
- Basic understanding of Linux commands,
- Basic knowledge of a Cloud platform such as AWS,
- It's good to have an AWS-Free Tier Account for Practice.
Objective: The objective of this lab is to set up two AWS EC2 instances, one for Jenkins and one for Docker, using Terraform. This lab aims to provide a foundation for building a Continuous Integration/Continuous Deployment (CICD) environment.
- Region: North Virginia (us-east-1).
- Use tag Name:
CICDLab-YourName
- AMI Type and OS Version(latest):
Ubuntu 24.04 LTS
- Instance type:
t2.micro
- Create a new Keypair with the Name
CICDLab-Keypair-YourName
- In security groups, include ports
22 (SSH)
and80 (HTTP)
(Add remaining ports later) - Configure Storage: 10 GiB
- Click on
Launch Instance.
- Once it is Launched, Ensure to add the remaining ports in the security group ie...
8080,
9999,
and4243.
Once the Anchor EC2 server is up and running, SSH into the machine using MobaXterm
or Putty
with the username ubuntu
and do the following:
sudo hostnamectl set-hostname CICDLab
bash
sudo apt update
sudo apt install wget unzip -y
wget https://releases.hashicorp.com/terraform/1.6.4/terraform_1.6.4_linux_amd64.zip
View the Terraform's Latest Versions
unzip terraform_1.6.4_linux_amd64.zip
ls
sudo mv terraform /usr/local/bin
ls
terraform -v
rm terraform_1.6.4_linux_amd64.zip
Install Python 3 and the required packages:
sudo apt-get update
sudo apt-get install python3-pip -y
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
sudo apt install ansible
Note: We need permissions for Terraform, Follow the below steps:
- Go to the AWS console. Choose IAM Service.
- Select Roles and click on create Role.
- Select AWS Service and under services select EC2.
- Select AdministratorAccess policy and create a role
- Go to EC2 concole, Select EC2, SELECT Actions ---> security---> Modify IAM Role
- Attach the role created in the previous step
You can check using any one command
aws s3 ls
(Or)
aws iam list-users
sudo mkdir /etc/ansible && sudo touch /etc/ansible/hosts
sudo chmod 766 /etc/ansible/hosts
Note: The above command gives read and write permissions to the owner,
read and write permissions to the group,
and read and write permissions to others.
Create the Terraform configuration and variables files as described.
- We need to create two additional servers (
Docker-server
andJenkins-server,
You can use t2.micro for Docker and Jenkins servers) - For Git Operations we will use the same Anchor EC2 from where we are operating now
mkdir devops-labs && cd devops-labs
As a first step, create a key using ssh-keygen.
ssh-keygen -t rsa -b 2048
-t rsa:
Specifies the type of key to create, in this case, RSA.-b 2048:
Specifies the number of bits in the key, 2048 bits in this case. The larger the number of bits, the stronger the key.
Note:
- This will create
id_rsa
andid_rsa.pub
in /home/ubuntu/.ssh/ - Keep the path as /home/ubuntu/.ssh/id_rsa; don't set up any passphrase, just hit the 'Enter' key for the 3 questions it asks
vi DevOpsServers.tf
Copy and paste the below code into DevOpsServers.tf
provider "aws" {
region = var.region
}
resource "aws_key_pair" "mykeypair" {
key_name = var.key_name
public_key = file(var.public_key)
}
# to create 2 EC2 instances
resource "aws_instance" "my-machine" {
# Launch 2 servers
for_each = toset(var.my-servers)
ami = var.ami_id
key_name = var.key_name
vpc_security_group_ids = [var.sg_id]
instance_type = var.ins_type
# Read from the list my-servers to name each server
tags = {
Name = each.key
}
provisioner "local-exec" {
command = <<-EOT
echo [${each.key}] >> /etc/ansible/hosts
echo ${self.public_ip} >> /etc/ansible/hosts
EOT
}
}
Now, create the variables file with all variables to be used in the main config file.
vi variables.tf
Change the following data in variables.tf File.
- Edit the Allocated Region (Ex: ap-south-1) & AMI ID of same region,
- Replace the same Security Group ID Created for the Anchor Server
- Add your Name for KeyPair (Example: "YourName-CICDlab-KeyPair")
variable "region" {
default = "us-east-1"
}
# Change the SG ID. You can use the same SG ID used for your CICD anchor server
# Basically the SG should open ports 22, 80, 8080, 9999, and 4243
variable "sg_id" {
default = "sg-06dc8863d3ed3d280" # us-east-1
}
# Choose a free tier Ubuntu AMI. You can use below.
variable "ami_id" {
default = "ami-04505e74c0741db8d" # us-east-1; Ubuntu
}
# We are only using t2.micro for this lab
variable "ins_type" {
default = "t2.micro"
}
# Replace 'yourname' with your first name
variable key_name {
default = "YourName-CICDlab-KeyPair"
}
variable public_key {
default = "/home/ubuntu/.ssh/id_rsa.pub" #Ubuntu OS
}
variable "my-servers" {
type = list(string)
default = ["jenkins-server", "docker-server"]
}
terraform init
terraform fmt
terraform validate
terraform plan
terraform apply -auto-approve
cat /etc/ansible/hosts
It will show IP addresses of the Jenkins server and docker server as an example shown below.
- [jenkins-server] 44.202.164.153
- [docker-server] 34.203.249.54
(Optional Step): When you stop and start the EC2 Instances Public IP Changes. In that case, To update Jenkins & Docker Public IP addresses use the below command
sudo vi /etc/ansible/hosts
Use i key on keyboard to Insert, Once Updated,press ESC then :wq! to Save and exit from the File.
ssh ubuntu@<Jenkins ip address>
sudo hostnamectl set-hostname Jenkins
bash
sudo apt update
Exit only from the Jenkins Server, not the Anchor Server.
ssh ubuntu@<Docker ip address>
sudo hostnamectl set-hostname Docker
bash
sudo apt update
Exit only from the Docker Server, not the Anchor Server.
cd ~
mkdir ansible && cd ansible
wget https://devosp-essentials-lab.s3.amazonaws.com/DevOpsSetup.yml
ansible-playbook DevOpsSetup.yml
At the end of this step, the Docker-Server
and Jenkins-Server
will be ready for performing further Labs
- Use your respective Jenkin'sPublic IP address as shown: http://44.202.164.153:8080/
- Use your respective Docker's Public IP address as shown: http://34.203.249.54:4243/version
Summary:
- Launch two EC2 instances in AWS - one for Jenkins and one for Docker.
- Install Terraform on the Jenkins server to automate infrastructure provisioning.
- Configure AWS CLI and Ansible for managing resources.
- Create a Terraform configuration to define the servers and their attributes.
- Launch the servers using Terraform.
- Update the Ansible hosts file with the server details.
- Configure Jenkins and Docker servers with proper host names.
- Use Ansible to install necessary software packages and dependencies on both servers.
Objective:
This lab focuses on Git
and GitHub operations,
including initializing a Git repository,
making commits,
creating branches,
and pushing code to a GitHub repository.
-
Create a GitHub Account & Empty Public Repository with name as "hello-world"
Note: (To SignUp for GitHub Account, Click Here)
-
You need to generate a Personal Access Token (PAT) in GitHub.
-
Basic familiarity with Git Commands.
Once the GitHub Account and Empty repository is ready, let's operate in the local Anchor Server.
On the CICD anchor EC2,
do the below:
cd ~/
Check the GIT version.
git --version
(Optional) If it does not exist, then you can install it with the below command. Else no need to execute the below line:
sudo apt install git -y
Download the Java Code that we are going to use in the CICD pipeline.
wget https://devosp-essentials-lab.s3.amazonaws.com/hello-world-master.zip
unzip hello-world-master.zip
ls
rm hello-world-master.zip
cd hello-world-master
ls
git init .
To set the User Identity
ie... email and user name.
you can use below:
git config --global user.email "< Add your email >"
git config --global user.name "< Add your Name >"
git status
git add .
git status
git log
git commit -m "This is the first commit"
git log
git status
- To push code to Github, You need to generate a Personal Access Token (PAT) in github.
To Generate the Token Follow the below steps:
-
First, Go to your
GitHub homepage,
Click on the top rightprofile Icon
and thensettings
-
Click on
Developer settings
(At the bottom on the left side menu). Click onPersonal Access Token
and then Click onGenerate New Token.
-
Under 'Select Scopes' select all items. Click on 'generate token'.
-
Once generated, Copy and save the token in a safe location as it is not visible again in GitHub.
Example: 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
-
Create
Alias
asOrigin
to GitHub's Remote repository URL.
git remote add origin < Replace your Repository URL >
(Example: git remote add origin https://github.com/janjiralakirankumar/hello-world.git
)
- To view the list of Aliases, run the below command in Terminal.
alias
- To view a specific alias use the below command.
git remote show origin
- Now you can push your code to the Remote repository using the below command.
git push origin master
- When it asks for a password, enter the Personal Access Token and Press Enter (PAT is invisible and It's the expected behavior.)
- To create a new Branch
git branch dev
- To know the current branch
git branch
- To switch to another branch
git checkout dev
git branch
vi index.html
Press INSERT and add the below content
<html>
<body>
<h1> Hi There! This file is added in dev branch </h1>
</body>
</html>
Save the file using ESCAPE+:wq!
git status
git add index.html
git status
git commit -m "adding new file index.html in new branch dev"
git log
git push origin dev
When it asks for a User ID
enter GitHub's User ID,
when it asks for a password
Enter PAT
and Press Enter. (Note: PAT is invisible when you paste)
git branch
git branch prod
git branch
git checkout prod
git branch
git merge dev
git push origin prod
When it asks for a User ID
enter GitHub's User ID,
when it asks for a password
Enter PAT
and Press Enter. (Note: PAT is invisible when you paste)
git checkout master
git merge prod
git push origin master
When it asks for a User ID
enter GitHub's User ID,
when it asks for a password
Enter PAT
and Press Enter. (Note: PAT is invisible when you paste)
Summary:
- Initialize a local Git repository on Anchor EC2 instance.
- Configure Git settings like email and username.
- Add and commit changes to the Git repository.
- Create and switch between Git branches.
- Make changes and commits in different branches.
- Merge branches and Push the code to a GitHub repository.
Lab 3: Configuring Jenkins server and Installing Tomcat onto Jenkin's Server for Deploying our Application.
Objective:
The objective of this lab is to configure Jenkins to build and deploy applications. It includes Setting up Jenkins,
installing necessary plugins
and configuring Jenkins to build Maven projects,
and Installing Tomcat Server.
Initially, Copy the private key from Anchor Server to the Jenkins Server & Docker Server. so, that we can SSH from Jenkins Server to Docker Server and viseversa.
cd ~
ansible jenkins-server -m copy -a "src=/home/ubuntu/.ssh/id_rsa dest=/home/ubuntu/.ssh/id_rsa" -b
Here's a breakdown of the command:
ansible
: The Ansible command-line tool.jenkins-server
: The target machine specified in your inventory file.-m copy
: Specifies the Ansible module to use, in this case, thecopy
module.-a "src=/home/ubuntu/.ssh/id_rsa dest=/home/ubuntu/.ssh/id_rsa"
: Specifies the arguments for the module, indicating the source and destination paths for the file copy.-b
: Run the Ansible command with elevated privileges.
ansible docker-server -m copy -a "src=/home/ubuntu/.ssh/id_rsa dest=/home/ubuntu/.ssh/id_rsa" -b
Here's a breakdown of the command:
ansible
: The Ansible command-line tool.docker-server
: The target machine specified in your inventory file.-m copy
: Specifies the Ansible module to use, in this case, thecopy
module.-a "src=/home/ubuntu/.ssh/id_rsa dest=/home/ubuntu/.ssh/id_rsa"
: Specifies the arguments for the module, indicating the source and destination paths for the file copy.-b
: Run the Ansible command with elevated privileges.
Using Jenkin's Public IP
SSH into the Jenkins Server from the Anchor Server.
Get the Initial Password for Jenkins from the below path.
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
(Example: "afbe8d33e25b4b908c0b9f91546f09e6")
- Now, go to the Web Browser and enter the Jenkins URL as shown: http://< Jenkin's Public IP>:8080/
- Under Unlock Jenkins, enter the above initialAdminPassword & click Continue.
- Click on Install suggested Plugins on the Customize Jenkins page.
- Once the plugins are installed, it gives you the page where you can create a New Admin User.
- Enter the User Id and Password followed by Name and E-Mail ID then click on Save & Continue.
- In the next step, on the Instance Configuration Page, verify your Jenkins Public IP and Port Number then click on Save and Finish
- Click on Manage Jenkins > Plugins > Available Plugins tab and search for Maven.
- Select the "Maven Integration" Plugin and "Unleash Maven" Plugin and click Install (without restart).
- Once the installation is completed, click on Go back to the top page.
- On Home Page select Manage Jenkins > Tool.
- Inside Tool Configuration, look for Maven installations, click Add Maven.
- Give the Name as "Maven", choose Version as 3.9.5, and Save the configuration.
- Now you need to make a project for your application build, that selects New Item from the Home Page of Jenkins
- Enter an item name as hello-world and select the project as Maven Project and then click OK. ( You will be prompted to the configure page inside the hello-world project.)
- Go to the "Source Code Management" tab, and select Source Code Management as Git, Now you need to provide the GitHub Repository Master Branch URL and GitHub Account Credentials.
- In the Credentials field, you have to click Add and then click on Jenkins.
- Then you will be prompted to the Jenkins Credentials Provider page. Under Add Credentials, you can add your GitHub Username, Password, and Description. Then click on Add.
- After returning to the Source Code Management Page, click on Credentials and Choose your GitHub Credentials.
- Keep all the other values as default and select the "Build" Tab and inside Goals and options write "clean package" and save the configuration.
Note: The 'clean package' command clears the target directory, Builds the project, and packages the resulting WAR file into the target directory.
- Now, you will get back to the Maven project "hello-world" and click on "Build Now" to build the .war file for your application
- You can go to Workspace > dist folder to see that the .war file is created there.
- war file will be created in /var/lib/jenkins/workspace/hello-world/target/
- Now, SSH into the Jenkins server (Make sure that you are the root user and Install the Tomcat web server)
- Note: (If you are already in Jenkins Server, again SSH is not needed.)
- Follow below steps:
sudo apt update
sudo apt install tomcat9 tomcat9-admin -y
ss -ltn
when you run ss -ltn
command you'll see a list of TCP sockets
that are in a listening state, and the output will include information such as the local address,
port,
and the state of each socket.
sudo systemctl enable tomcat9
Now we need to navigate to server.xml to change the Tomcat port number from 8080 to 9999. (As port number 8080 is already being used by the Jenkins website)
sudo vi /etc/tomcat9/server.xml
(Optional step): If you are unable to open the file then change the permissions by using the below command.
sudo chmod 766 /etc/tomcat9/server.xml
- press esc & Enter ":" and copy paste below code and hit enter
g/8080/s//9999/g
Save the file using ESCAPE+:wq!
- To Verify whether the Port is changed, execute the below Command.
cat /etc/tomcat9/server.xml
(Optional step): If you are unable to open the file then change the permissions by using the below command.
sudo chmod 766 /etc/tomcat9/server.xml
Now restart the system for the changes to take effect
sudo service tomcat9 restart
sudo service tomcat9 status
To exit, press ctrl+c
- Once the Tomcat service restart is successful, go to your web browser and enter Jenkins Server's Public IP address followed by 9999 port.
(Example: http://< Jenkins Public IP >:9999 or http://184.72.112.155:9999)
- Now you can check the Tomcat running on port 9999 on the same machine.
- We need to copy the .war file created in the previous Jenkins build from the Jenkins workspace to tomcat webapps directory to serve the web content
sudo cp -R /var/lib/jenkins/workspace/hello-world/target/hello-world-war-1.0.0.war /var/lib/tomcat9/webapps
The above command is copying a WAR (Web Application Archive)
file from the Jenkins workspace to the Tomcat web apps directory. Let's break down the command:
-
sudo
: Run the command with superuser (root) privileges, as copying files to system directories often requires elevated permissions. -
cp
: The copy command in Linux. -
-R
: Recursive option, used when copying directories. It ensures that the entire directory structure is copied. -
/var/lib/jenkins/workspace/hello-world/target/hello-world-war-1.0.0.war
: Source path, specifying the location of the WAR file in the Jenkins workspace. -
/var/lib/tomcat9/webapps
: Destination path, indicating the Tomcat webapps directory where the WAR file is being copied.
This command assumes that your Jenkins job has built a WAR file named hello-world-war-1.0.0.war
in the specified workspace directory. It then copies this WAR file into the Tomcat webapps directory, allowing Tomcat to deploy and run the web application.
- Once this is done, go to your browser and enter Jenkins Public IP address followed by port 9999 and path (URL: http://< Jenkins Public IP >:9999/hello-world-war-1.0.0/).
- Now, you can see that Tomcat is now serving your web page
- Now, Stop tomcat9 and remove it. Otherwise, it will slow down the Jenkins server.
sudo service tomcat9 stop
sudo apt remove tomcat9 -y
Summary:
- Opening the
Jenkins Web Page
on the browser. - Unlock Jenkins and create an admin user.
- Install plugins, including Maven integration.
- Configure Jenkins to use a specific version of Maven.
- Create a Maven project in Jenkins for the "hello-world" application.
- Configure source code management with Git and GitHub.
- Define build goals and options.
- Build the project and verify the outcome.
- Install and configure Apache Tomcat for serving web applications.
- Deploy the built WAR file to Tomcat.
Objective: This lab focuses on configuring Git WebHooks to automatically trigger Jenkins builds when code changes are pushed to a GitHub repository.
- Go to the Jenkins webpage and choose Manage Jenkins > Plugins
- Go to the Available Tab, Search for GitHub Integration. Select the GitHub Integration Plugin and then on Install (without restart).
- Once the installation is complete, click on Go back to the top page.
- In your hello-world project, Click on Configure.
- Go to Build Triggers and enable the GitHub hook trigger for GITScm polling. Then Save.
- Go to your GitHub website, and inside the hello-world repository > Settings > Webhooks and Click on the Add Webhook.
- Now fill in the details as below.
- http://< jenkins-PublicIP >:8080/github-webhook/ (Example: http://184.72.112.155:8080/github-webhook/)
- Content type: application/JSON
Then, Click on Add Webhook.
- Now, Make a minor change and commit in GitHub's hello-world repository by editing hello.txt file.
- As the source code gets changed, Jenkins gets triggered by the WebHook and starts building the new source code.
- Go to Jenkins, and you can see a build is happening automatically.
- Observe the successful build on the Jenkins page.
Summary:
- Configure Git WebHooks in Jenkins for automatic triggering of builds.
- Create a GitHub WebHook for a specific GitHub repository.
- Make a minor code change in the GitHub repository to trigger a build in Jenkins.
- Verify that Jenkins successfully starts a new build when changes are pushed.
Lab-5: Configuring Docker Machine as Jenkins Slave, build and deploy code in Docker Host as a container
Objective: In this lab, you will set up a Docker container as a Jenkins slave, build a Docker image for a Java web application, and deploy it in a Docker container.
- SSH into docker-server
- Change to the root user
sudo su
- Generate a key-pair
ssh-keygen
- Add the public key to the authorized_keys
cat /root/.ssh/id_rsa.pub
- Copy the contents of the file and paste in authorized_keys
vi /root/.ssh/authorized_keys
- Save the file using
ESCAPE+:wq!
- Go to Jenkin's home page and click on the Manage Jenkins and Nodes.
- Click on New Node in the next window. Give the node name as docker-slave and Select "permanent agent"
- Fill out the details for the node docker-slave as given below.
- The name should be given as docker-slave,
- Remote Root Directory as /home/ubuntu,
- labels to be Slave-Nodes,
- usage to be given as "use this node as much as possible"
- Launch method to be set as "launch agents via SSH".
- In the host section, give the Public IP of the Docker instance.
- For Credentials for this Docker node, click on the dropdown button named Add and then click on Jenkins;
- Then in the next window, in kind select SSH username with private key (give username as root),
- In Private Key Select Enter directly then Copy-Paste the Private Key and then click on Add .
Note: To get the private key, Go to your Docker-server and run below command.
cd /root/.ssh
cat id_rsa
- Copy the entire content, including the first and last lines. Paste it into the space provided for the private key then click on Add.
- Now, In SSH Credentials, choose the newly created root credentials.
- Host Key Verification Strategy Select as "Non Verifying Verification Strategy" and Save it.
- Click on the Add button.
- it's done.
Now In CLI, SSH into your Docker Host and Perform the below steps to create a "Dockerfile" in /home/ubuntu directory.
cd /home/ubuntu
vi Dockerfile
enter the below:
# Pull Base Image
FROM tomcat:8-jre8
# Maintainer
MAINTAINER "CloudThat"
# Copy the war file to the images tomcat path
ADD hello-world-war-1.0.0.war /usr/local/tomcat/webapps/
The Dockerfile you provided is a basic Dockerfile for deploying a Java web application using the Tomcat web server as the base image. Here's what each part of the Dockerfile does:
-
FROM tomcat:8-jre8
: This line specifies the base image for your Docker container. In this case, it uses the official Tomcat 8 image with the Java 8 runtime. This image contains the Tomcat web server and Java runtime environment. -
MAINTAINER "CloudThat"
: This line is a comment and specifies the maintainer or author of the Dockerfile. -
ADD hello-world-war-1.0.0.war /usr/local/tomcat/webapps/
: This line adds your Java web application's WAR file (hello-world-war-1.0.0.war
) to the/usr/local/tomcat/webapps/
directory inside the container. When Tomcat starts, it will automatically deploy the WAR file as a web application.
This Dockerfile is a simple example of how to package a Java web application in a Docker container. It uses an existing Tomcat image as the base, and you're adding your application's WAR file to it. You can further customize this Dockerfile based on your specific requirements, such as adding environment variables, configuring Tomcat, or specifying additional settings for your application.
Once you build this Docker image and run a container based on it, your Java web application should be accessible through Tomcat on port 8080 inside the container, as mentioned in your Jenkins job's post-build steps.
- Go to your Jenkins Home page, click on the drop-down on hello-world project, and select Configure tab.
- In General Tab, Select Restrict where this project can be run and enter Label Expression as Slave-Nodes.
- Go to Post Steps Tab, select "Run only if the build succeeds" then click on Add post-build step select Execute shell from the drop-down and copy paste the below commands in the shell and Save
Execute shell commands in Jenkins:
#!/bin/bash
# Navigate to the Jenkins workspace
cd /home/ubuntu/workspace/hello-world/
# Copy the WAR file to the root directory
cp -f target/hello-world-war-1.0.0.war .
# Stop and remove the existing Docker container (if it exists)
sudo docker stop helloworld-container || true
sudo docker rm helloworld-container || true
# Build the Docker image using the Dockerfile in the /home/ubuntu directory
sudo docker build -t helloworld-image -f /home/ubuntu/Dockerfile .
# Run the Docker container
sudo docker run -d -p 8080:8080 --name helloworld-container helloworld-image
The commands you provided are part of the Jenkins job's post-build steps, and they are responsible for building a Docker image and running a Docker container for your Java web application. Here's a breakdown of what each command does:
-
cd /home/ubuntu/workspace/hello-world/
: Change the working directory to the Jenkin's workspace -
cp -f target/hello-world-war-1.0.0.war .
: Copy the WAR file (presumably the artifact of your Java web application) from the Jenkins workspace to the root directory (~
), where you'll perform the Docker build.
3.sudo docker stop helloworld-container || true
: Stop any existing Docker container with the name "helloworld-container" forcefully if it exists.
-
sudo docker rm helloworld-container || true
: Remove any existing Docker container with the name "helloworld-container" forcefully if it exists. -
sudo docker build -t helloworld-image -f /home/ubuntu/Dockerfile .
: Build a Docker image with the tag "helloworld-image" based on the Dockerfile located in the current directory (.
). The Dockerfile you created earlier specifies how the image should be built. -
sudo docker run -d -p 8080:8080 --name helloworld-container helloworld-image
: Run a Docker container named "helloworld-container" from the "helloworld-image" image. This container will be detached (-d
) and will map port 8080 on the host to port 8080 inside the container.
After running these commands, your Java web application should be deployed inside a Docker container, and it will be accessible on port 8080 of your Docker host.
Make sure that Docker is properly configured on your host, and all the necessary dependencies for your Java web application are included in the WAR file. Additionally, ensure that the Dockerfile is correctly configured to set up your application inside the container.
- Now you can build your hello-world project Either by
- Clicking on "Build Now" or
- By making a small change in Github files.
- Once the build is successful, access the tomcat server page,
To access the Page In Browser Type "http:// < Your Docker Host Public IP >:8080/hello-world-war-1.0.0/" to see the website
Summary:
- Configure a Jenkins slave node ie... named as "docker-slave."
- Configure the slave node to use SSH for communication.
- Set up a Dockerfile to define the Docker image for the Java web application.
- Create a Jenkins job to build and deploy the Java web application in a Docker container.
- Add post-build steps to the Jenkins job to copy the WAR file, build the Docker image, and run a Docker container.
- Trigger the Jenkins job to build and deploy the application in the Docker container.
- Access the deployed web application in the Docker container via the Docker host's public IP.
Once Done, It's time to Clean up the Instances
We can now terminate all the 3 instances and we are Done with All Labs.
Here are some important Git commands and their brief explanations:
-
git init
- Initializes a new Git repository in the current directory.
git init
-
git clone
- Copies a repository from a remote source (like GitHub) to your local machine.
git clone <repository_url>
-
git add
- Adds changes in the working directory to the staging area for the next commit.
git add <file>
-
git commit
- Records changes in the repository with a message describing the changes.
git commit -m "Your commit message"
-
git status
- Shows the status of changes as untracked, modified, or staged.
git status
-
git diff
- Shows the differences between the working directory and the latest commit.
git diff
-
git log
- Displays a log of commits, showing commit messages, authors, dates, and commit hashes.
git log
-
git branch
- Lists existing branches or creates a new branch.
git branch # List branches git branch <branch_name> # Create a new branch
-
git checkout
- Switches to a different branch or restores working files from a specific commit.
git checkout <branch_name> # Switch to a branch git checkout -b <new_branch> # Create and switch to a new branch
-
git merge
- Combines changes from different branches.
git merge <branch_name>
-
git pull
- Fetches changes from a remote repository and integrates them into the current branch.
git pull origin <branch_name>
-
git push
- Uploads local branch commits to the remote repository.
git push origin <branch_name>
-
git remote
- Lists remote repositories that are connected to your local repository.
git remote -v # Show remote repositories with URLs
-
git fetch
- Downloads changes from a remote repository without merging them into your working branch.
git fetch origin
-
git reset
- Resets the current branch to a specific commit, optionally preserving changes in the working directory.
git reset --hard <commit_hash>
These are just a few fundamental Git commands. There are many more, each serving different purposes in the version control process.
Certainly! Here are the official websites and documentation links for some popular DevOps tools:
-
Version Control:
- Git:
- Website: Git
- Documentation: Git Documentation
- Git:
-
Continuous Integration and Continuous Deployment:
- Jenkins:
- Website: Jenkins
- Documentation: Jenkins Documentation
- Travis CI:
- Website: Travis CI
- Documentation: Travis CI Documentation
- Jenkins:
-
Configuration Management:
- Ansible:
- Website: Ansible
- Documentation: Ansible Documentation
- Puppet:
- Website: Puppet
- Documentation: Puppet Documentation
- Ansible:
-
Containerization and Orchestration:
- Docker:
- Website: Docker
- Documentation: Docker Documentation
- Kubernetes:
- Website: Kubernetes
- Documentation: Kubernetes Documentation
- Docker:
-
Infrastructure as Code:
- Terraform:
- Website: Terraform
- Documentation: Terraform Documentation
- Terraform:
-
Monitoring and Logging:
- Prometheus:
- Website: Prometheus
- Documentation: Prometheus Documentation
- ELK Stack (Elasticsearch, Logstash, Kibana):
- Website: Elastic
- Documentation: Elastic Stack Documentation
- Prometheus:
Always check the official websites for the most up-to-date information and documentation. Additionally, many of these tools may have vibrant communities where you can find additional resources, tutorials, and support.
In Linux, you can use the date
command to change the system date and time. Open a terminal and use the following example as a guide:
sudo date MMDDhhmm[[CC]YY][.ss]
Here's a breakdown of the format:
MM
: Month (01-12)DD
: Day (01-31)hh
: Hour (00-23)mm
: Minutes (00-59)CC
: Century (20 for 21st century, 19 for 20th century, etc.)YY
: Year within the centuryss
: Seconds (00-61)
For example, to set the date to November 22, 2023, 15:30:00, you would run:
sudo date 112215302023.00
Make sure to replace the values with the desired date and time components.
After executing the date
command, the system date and time will be updated accordingly.