diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 5a10269..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,47 +0,0 @@ -pipeline { - agent any - stages { - stage('Checkout') { - steps { - git 'https://github.com/ReyazShaik/java-project-maven-new.git' - } - } - stage('Compile') { - steps { - sh 'mvn compile' - } - } - stage('Test') { - steps { - sh 'mvn test' - } - } - stage('SonarQube Scanning') { - steps { - withSonarQubeEnv('SonarQube') { - sh 'mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar' - } - } - } - stage('Artifacts') { - steps { - sh 'mvn clean package' - } - } - stage('Deploy to Tomcat') { - steps { - deploy adapters: [tomcat9(credentialsId: 'tomcatcreds', path: '', url: 'http://43.205.95.19:8080/')], contextPath: 'myapp', war: '**/*.war' - } - } - stage('Nexus') { - steps { - nexusArtifactUploader artifacts: [[artifactId: 'myapp', classifier: '', file: 'target/myapp.war', type: '.war']], credentialsId: 'nexus', groupId: 'in.reyaz', nexusUrl: '3.6.41.43:8081', nexusVersion: 'nexus3', protocol: 'http', repository: 'hotstar', version: '8.3.3-SNAPSHOT' - } - } - stage('Uploading to S3') { - steps { - s3Upload consoleLogLevel: 'INFO', dontSetBuildResultOnFailure: false, dontWaitForConcurrentBuildCompletion: false, entries: [[bucket: 'jen-project-arti/', excludedFile: '', flatten: false, gzipFiles: false, keepForever: false, managedArtifacts: false, noUploadOnFailure: false, selectedRegion: 'ap-south-1', showDirectlyInBrowser: false, sourceFile: '**/*.war', storageClass: 'STANDARD', uploadFromSlave: false, useServerSideEncryption: true]], pluginFailureResultConstraint: 'FAILURE', profileName: 's3creds', userMetadata: [] - } - } - } -} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d26d816 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,30 @@ +version: '3.8' + +services: + nginx: + build: . + container_name: nginx-lb + ports: + - "80:80" + depends_on: + - backend1 + - backend2 + - backend3 + + backend1: + image: ghcr.io/benc-uk/python-demoapp + container_name: backend1 + expose: + - "5000" + + backend2: + image: ghcr.io/benc-uk/python-demoapp + container_name: backend2 + expose: + - "5001" + + backend3: + image: ghcr.io/benc-uk/python-demoapp + container_name: backend3 + expose: + - "5002" diff --git a/dockercompose.sh b/dockercompose.sh new file mode 100644 index 0000000..1f5db54 --- /dev/null +++ b/dockercompose.sh @@ -0,0 +1,9 @@ +sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + +ls /usr/local/bin/ + +sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose + +sudo chmod +x /usr/local/bin/docker-compose + +docker-compose version diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..f37da02 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,17 @@ +upstream backend { + server backend1:5000; + server backend2:5001; + server backend3:5002; +} + +server { + listen 80; + + location / { + proxy_pass http://backend; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} diff --git a/tomcat.yml b/tomcat.yml new file mode 100644 index 0000000..2720b8b --- /dev/null +++ b/tomcat.yml @@ -0,0 +1,63 @@ +--- +- name: Setup Tomcat + hosts: all + become: yes + + tasks: + + - name: Download tomcat from dlcdn + get_url: + url: "https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.35/bin/apache-tomcat-10.1.35.tar.gz" + dest: "/root/" + + - name: untar the apache file + command: tar -zxvf apache-tomcat-10.1.35.tar.gz + + - name: Rename the tomcat + command: mv apache-tomcat-10.1.35 tomcat + + - name: Install the latest available Java (OpenJDK) + yum: + name: java-17-amazon-corretto + state: present + + - name: Setting the roles in tomcat-users.xml file + template: + src: tomcat-users.xml + dest: /root/tomcat/conf/tomcat-users.xml + + - name: Delete two lines in context.xml + template: + src: context.xml + dest: /root/tomcat/webapps/manager/META-INF/context.xml + + - name: Create Tomcat systemd Service File + copy: + dest: /etc/systemd/system/tomcat.service + content: | + [Unit] + Description=Apache Tomcat Server + After=network.target + + [Service] + User=root + Group=root + Type=forking + Environment="JAVA_HOME=/usr/lib/jvm/jre" + Environment="CATALINA_HOME=/root/tomcat" + ExecStart=/root/tomcat/bin/startup.sh + ExecStop=/root/tomcat/bin/shutdown.sh + Restart=on-failure + + [Install] + WantedBy=multi-user.target + + - name: Reload systemd + systemd: + daemon_reload: yes + + - name: Start tomcat Service + service: + name: tomcat + state: started + enabled: yes diff --git a/tomcatgpt.yml b/tomcatgpt.yml new file mode 100644 index 0000000..9e84f0a --- /dev/null +++ b/tomcatgpt.yml @@ -0,0 +1,77 @@ +--- +- name: Setup Apache Tomcat + hosts: all + become: yes + + tasks: + + - name: Install Java 17 (Amazon Corretto) + yum: + name: java-17-amazon-corretto + state: present + + - name: Download Apache Tomcat + get_url: + url: https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.35/bin/apache-tomcat-10.1.35.tar.gz + dest: /root/apache-tomcat-10.1.35.tar.gz + mode: '0644' + + - name: Extract Apache Tomcat + unarchive: + src: /root/apache-tomcat-10.1.35.tar.gz + dest: /root/ + remote_src: yes + creates: /root/apache-tomcat-10.1.35 + + - name: Rename Tomcat directory + command: mv /root/apache-tomcat-10.1.35 /root/tomcat + args: + creates: /root/tomcat + + - name: Copy tomcat-users.xml + template: + src: tomcat-users.xml + dest: /root/tomcat/conf/tomcat-users.xml + mode: '0644' + + - name: Copy modified context.xml + template: + src: context.xml + dest: /root/tomcat/webapps/manager/META-INF/context.xml + mode: '0644' + + - name: Create Tomcat systemd service + copy: + dest: /etc/systemd/system/tomcat.service + mode: '0644' + content: | + [Unit] + Description=Apache Tomcat Server + After=network.target + + [Service] + Type=forking + User=root + Group=root + + Environment="JAVA_HOME=/usr/lib/jvm/java-17-amazon-corretto" + Environment="CATALINA_HOME=/root/tomcat" + Environment="CATALINA_BASE=/root/tomcat" + + ExecStart=/root/tomcat/bin/startup.sh + ExecStop=/root/tomcat/bin/shutdown.sh + + Restart=on-failure + + [Install] + WantedBy=multi-user.target + + - name: Reload systemd daemon + systemd: + daemon_reload: yes + + - name: Enable and start Tomcat + systemd: + name: tomcat + state: started + enabled: yes