Skip to content

b-c-v/CI-CD-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

v1.2 CI/CD project

Description:

  • Preparing the environment with Jenkins==>Terraform==>Ansible
  • CI/CD pipeline with Git==>GitHub==>Jenkins==>Maven==>Ansible==>Tomcat&Docker==>DockerHub==>Web Server

To prepare deployment environment, use Jenkins, Terraform, and Ansible, installing them and configuring Jenkins project accordingly. After committing changes to GitHub repository, Jenkins will build and test the application with Maven before transferring it to the Ansible server. There, Ansible will build a Docker image and send it to DockerHub before uploading it to the Docker server and launching it.


1. Preparing the environment for project implementation:

1.1 On your local computer (Ubuntu), download and run the script 1_install_packages_Ubuntu.sh

chmod +x 1_install_packages_Ubuntu.sh
source 1_install_packages_Ubuntu.sh

1.2 Create folder /cicd/ and SSH-key with name "aws"

sudo mkdir /cicd
sudo ssh-keygen -f /cicd/aws
sudo chown jenkins:jenkins /cicd -R

1.3 In Jenkins

1.3.1 Jenkins ==> Manage Jenkins ==> Global Tool Configuration add information where installed:

  • Terraform. Find where it installed:
whereis terraform
  • Ansible. Find where it installed
which ansible

1.3.2 Jenkins ==> Manage Jenkins ==> Manage Credentials ==> (global) ==> Add credentials ==> AWS Credentials Add credentials to connect to AWS (ID: cicd-credentials)

1.3.3 Create Jenkins pipeline job, paste code from Jenkinsfile and run. The process of launching three servers using the Terraform and their configuration using the Ansible will begin.

2. Ansible server (public_2)

2.1 Exchange ssh-key

su *your_user_name* (ansiblecicd)
ssh-copy-id *private_ip_localhost* (private_2) #it's necessary to exchange the SSH-key with the local server on behalf of the created user
ssh-copy-id *private_ip_docker_server* (private_1)

2.2 Login to DockerHub:

docker login

2.3 Copy files to directory (/opt/docker/):


4. Jenkins server (public_0)

4.1 Create trigger to automatically start a job in Jenkins, when some changes are made to the GitHub repository

  • in settings GitHub repository with the project, specify the address of Jenkins-server and type of events to trigger this webhook (http://ip_jenkins_server:8080/github-webhook/)

4.2 Manually configure Jenkins

  • Manage Jenkins ==> Configure System ==> Publish over SSH add private IP address of Ansible-server (private_2), username and created user password.

    A better solution is to use an SSH key

  • Manage Jenkins ==> Global Tool Configuration ==> configure GIT, JDK and Maven

4.3 Create new Item (Maven project)

script to section "Exec command":

ansible-playbook -i/opt/docker/inventory.ini /opt/docker/3.3_playbook_push_image.yml;
sleep 10;
ansible-playbook -i/opt/docker/inventory.ini /opt/docker/3.4_playbook_run_container.yml;

If you type in a link http://ip_docker_server(public_1)/webapp in a browser, you can see

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published