diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..98a53e9 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,41 @@ +pipeline { + agent any + environment { + BUCKET_NAME = 'project1-joke-s3' + } + + stages { + stage('Clean Old Artifacts') { + steps { + sh 'rm -rf target' + } + } + + stage('Build') { + steps { + sh 'mvn package' + } + } + + stage('Upload Artifact') { + steps { + script { + // Find the WAR file + def artifactName = sh( + script: "cd target && ls WebAppCal-*.war", + returnStdout: true + ).trim() + + // Export artifact name for downstream use (e.g., Ansible) + env.ARTIFACT_NAME = artifactName + + // Upload to S3 + sh """ + aws s3 cp target/${artifactName} s3://${env.BUCKET_NAME}/ + """ + } + } + } + } +} + diff --git a/ansible/ec2.yml b/ansible/ec2.yml new file mode 100644 index 0000000..d98e37b --- /dev/null +++ b/ansible/ec2.yml @@ -0,0 +1,11 @@ +# demo.aws_ec2.yml +plugin: amazon.aws.aws_ec2 + +regions: + - us-east-1 + +groups: + webservers: "'project1-app' in tags.Name" + +hostnames: + - private-ip-address \ No newline at end of file diff --git a/ansible/playbook.yml b/ansible/playbook.yml new file mode 100644 index 0000000..06b9681 --- /dev/null +++ b/ansible/playbook.yml @@ -0,0 +1,19 @@ +--- +- name: Update web servers + hosts: webservers + + tasks: + - name: Get Artifact + amazon.aws.s3_object: + bucket: "{{BUCKET_NAME}}" + object: "{{ARTIFACT_NAME}}" + dest: ~/{{ARTIFACT_NAME}} + mode: get + delegate_to: localhost + + -name: Deploy Artifact to Hosts + ansible.builtin.copy: + src: /{{ ARTIFACT_NAME }} + dest: /home/ec2-user/apache-tomcat/webapps/{{ ARTIFACT_NAME}} + + diff --git a/group_vars/webservers.yml b/group_vars/webservers.yml new file mode 100644 index 0000000..56e3abc --- /dev/null +++ b/group_vars/webservers.yml @@ -0,0 +1,3 @@ +ansible_user: ec2-user +ansible_ssh_private_key_file: ~/.ssh/server-key +ansible_ssh_common_args: "-o StrictHostKeyChecking=no" \ No newline at end of file diff --git a/pom.xml b/pom.xml index 9e1759e..b8c5abb 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.web.cal WebAppCal war - 0.0.6 + 0.0.7 WebAppCal Maven Webapp http://maven.apache.org @@ -21,10 +21,24 @@ 2.5 - - - releases - http://52.204.135.48:8081/nexus/content/repositories/releases - - + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + 17 + 17 + + + + org.apache.maven.plugins + maven-war-plugin + 3.3.2 + + + +