Skip to content

Infrastructure automation with Terraform on AWS ,CI/CD pipeline to host a java web application.

Notifications You must be signed in to change notification settings

dawitanelay/Aws-Devops-deploying-java-application

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Infrastructure automation with Terraform on AWS for CI/CD pipeline to host a java web application.

Objective

The aim of the project is to get hands on experience in CI/CD pipeline and on cloud. By the end of the project, we will have a single terraform repository where you can type terraform apply command and it will do CI/CD pipeline for you.

Pre-requisite

  • AWS account
  • Amazon Machine Image (AMI) Red Hat Enterprise Linux 8.x
  • Terraform required_version = ">= 0.12"

Get start

  1. Install terraform

  2. Git clone

  3. create aws EC2 key pairs

    • jenkins-key.pem
    • ansible-key.pem
    • tomcat-key.pem

4 Provide your private key under Provisioner Connection Settings

  • Provisioner Connection Settings directory of a file

     CI-CD-PipelineOnAws/modules/ansible/instance.tf
     CI-CD-PipelineOnAws/modules/jenkins/instance.tf
     CI-CD-PipelineOnAws/modules/tomcat/instance.tf
    
    connection {
          type        = "ssh"
          host        = self.public_ip 
          user        = "ec2-user" 
          private_key = file("~/key/ansible-key.pem") 
         } 
    
  1. Specify corrrect PATH for file provisioning to excute bash scripte

    • file provisioning directory of a file

      CI-CD-PipelineOnAws/modules/ansible/instance.tf
      CI-CD-PipelineOnAws/modules/jenkins/instance.tf    
      CI-CD-PipelineOnAws/modules/tomcat/instance.tf
      
      provisioner "file" {
        	source     = "~/bash-script/ansible.sh" 
          destination  = "/tmp/ansible.sh" 
            }  
      
  2. cd CI-CD-PipelineOnAws/dev
  3. Export AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY

        $ export AWS_ACCESS_KEY_ID="anaccesskey"
        $ export AWS_SECRET_ACCESS_KEY="asecretkey"
  4. terraform apply

Post-Install Configuration

Jenkins

1 Browse http:your-target-ip:8080
2 Username admin
3 Password Location:/var/lib/jenkins/secrets/initialAdminPassword
4 Change password 
5 Configure java path
6 Create maven project
7 Configure maven path
8 Provide your project git url

Tomcat

1 Browse http:your-target-ip:8080
2 Allow tomcat to login from browser type  #find -name context.xml# 3 context.xml files.
  comment () Value ClassName field on files which are under webap directory. 
3 Restart tomcat -  type tomcatup 
4 Copy the following file under /opt/apache-tomcat-8.5.35/conf/tomcat-user.xml 

    	<role rolename="manager-gui"/> 
	<role rolename="manager-script"/> 
	<role rolename="manager-jmx"/> 
	<role rolename="manager-status"/> 
	<user username="admin" password="admin" roles="manager-gui, manager-script, manager-jmx, manager-status"/> 
	<user username="deployer" password="deployer" roles="manager-script"/> 
	<user username="tomcat" password="root123" roles="manager-gui"/> 	
 	 
5 Restart service and try to login to a tomcat application from the browser use tomcat user with password root123.  

Ansible

1 su - ansadmin  
2 ssh-keygen
3 ssh-copy-id target-ip-address (tomcat-ipaddress)
4 nano /etc/ansible/hosts  add tomcat ip address
5 test using ansible all -m ping
6 write playbooks under /opt/playbooks

About

Infrastructure automation with Terraform on AWS ,CI/CD pipeline to host a java web application.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published