From 501138cc47554834d097b0a459f761eefa73a37e Mon Sep 17 00:00:00 2001 From: AndrewBanin <60724426+AndrewBanin@users.noreply.github.com> Date: Mon, 24 Jan 2022 21:41:52 -0500 Subject: [PATCH 1/9] Add jenkinsfile (#1) * Added empty Jenkinsfile * Modified Jenkinsfile * Modified Jenkinsfile1 * Modified Jenkinsfile2 * Modified jenkinsfile3 * Modified jenkinsfile4 * Modified jenkinsfile5 * Modified jenkinsfile5 * Modified jenkinsfile5 * Modified jenkinsfile5 * Modified jenkinsfile5 * Modified jenkinsfile5 * Modified jenkinsfile5 * Modified jenkinsfile5 * Modified jenkinsfile5 * Modified jenkinsfile5 * Modified jenkinsfile5 * Modified jenkinsfile5 --- Jenkinsfile | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000000..df5f6ffc29f --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,24 @@ +pipeline{ + agent any + tools { + maven 'Maven' + } + + stages{ + stage('CONTINOUSDOWNLOAD'){ + steps{ + git credentialsId: 'Github_Token', + url: 'https://github.com/AndrewBanin/spring-petclinic.git' + } + + } + + stage('Maven Build'){ + steps{ + sh "mvn clean package" + } + } + } +} + + From c3412ce4800d296db3dd7faf64595da2166b8ffa Mon Sep 17 00:00:00 2001 From: AndrewBanin <60724426+AndrewBanin@users.noreply.github.com> Date: Wed, 9 Feb 2022 00:02:55 -0500 Subject: [PATCH 2/9] Create deploy-docker.yml --- deploy-docker.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 deploy-docker.yml diff --git a/deploy-docker.yml b/deploy-docker.yml new file mode 100644 index 00000000000..6d05e036c23 --- /dev/null +++ b/deploy-docker.yml @@ -0,0 +1,28 @@ +--- +- hosts: dev + become: True + tasks: + - name: Install python pip + yum: + name: python-pip + state: present + - name: Install docker + yum: + name: docker + state: present + - name: start docker + service: + name: docker + state: started + enabled: yes + - name: Install docker-py python module + pip: + name: docker-py + state: present + - name: Start the container + docker_container: + name: spring-clinic + image: "banina/spring-clinic:{{DOCKER_TAG}}" + state: started + published_ports: + - 0.0.0.0:8080:8080 From 3d67cb23be85a235aa9e290d814f0ff0ad666fed Mon Sep 17 00:00:00 2001 From: AndrewBanin <60724426+AndrewBanin@users.noreply.github.com> Date: Wed, 9 Feb 2022 00:25:46 -0500 Subject: [PATCH 3/9] Create dev.inv --- dev.inv | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 dev.inv diff --git a/dev.inv b/dev.inv new file mode 100644 index 00000000000..b91bf60f2e5 --- /dev/null +++ b/dev.inv @@ -0,0 +1,2 @@ +[dev] +172.31.22.111 ansible_ubuntu From 011bcb3e954d874745d0b80ab20baa434d1948fd Mon Sep 17 00:00:00 2001 From: AndrewBanin <60724426+AndrewBanin@users.noreply.github.com> Date: Wed, 9 Feb 2022 22:37:27 -0500 Subject: [PATCH 4/9] Added Dockerfile to containarized the application (#2) * Modified jenkinsfile6 * Modified jenkinsfile6 * add dockerfile * add dockerfile * add dockerfile * add dockerfile * add dockerfile * add dockerfile * add dockerfile * add dockerfile * add dockerfile * add dockerfile * add dockerfile * add dockerfile * add dockerfile * add dockerfile * add dockerfile * add dockerfile * add dockerfile * add dockerfile * add dockerfile * add dockerfile * add dockerfile * add dockerfile --- Jenkinsfile | 52 ++++++++++++++++++++++++++++++++++++++++------------ dockerfile | 3 +++ 2 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 dockerfile diff --git a/Jenkinsfile b/Jenkinsfile index df5f6ffc29f..30a65f4a243 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,22 +3,50 @@ pipeline{ tools { maven 'Maven' } - + environment { + DOCKERHUB_CREDENTIALS=credentials('docker-jenkins-connect') + DOCKERUSER="banina" + } stages{ - stage('CONTINOUSDOWNLOAD'){ - steps{ - git credentialsId: 'Github_Token', - url: 'https://github.com/AndrewBanin/spring-petclinic.git' - } - - } - stage('Maven Build'){ steps{ sh "mvn clean package" - } + } } - } -} + stage('Docker Build Petclinic') { + + steps { + sh 'docker build -t $DOCKERUSER/spring-petclinic:${BUILD_NUMBER}-dev .' + } + } + stage('Login to Docker HUB') { + + steps { + sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin' + } + } + stage('Push') { + steps { + sh 'docker push $DOCKERUSER/spring-petclinic:${BUILD_NUMBER}-dev' + } + } + stage('Cleanup') { + steps{ + sh "docker rmi $DOCKERUSER/spring-petclinic:${BUILD_NUMBER}-dev" + } + } + stage('CleanWorkSpace'){ + steps { + cleanWs() + } + } + } + post { + always { + sh 'docker logout' + } + } + +} diff --git a/dockerfile b/dockerfile new file mode 100644 index 00000000000..7d9479d2dfc --- /dev/null +++ b/dockerfile @@ -0,0 +1,3 @@ +FROM openjdk:11 +COPY target/*.jar /spring-petclinic.jar +CMD ["java", ""-jar" , "spring-petclinic.jar"] From 40cec2000a75536082c2a1df0d5cb4aca5f708d6 Mon Sep 17 00:00:00 2001 From: AndrewBanin <60724426+AndrewBanin@users.noreply.github.com> Date: Wed, 13 Apr 2022 21:49:36 -0400 Subject: [PATCH 5/9] Adding sleep stage and Instance IP address. (#3) * dockerfile modified * Added add-infrastructure1.yml * Added add-infrastructure1.yml * Added add-infrastructure1.yml * Added add-infrastructure1.yml * Added add-infrastructure1.yml * Added add-infrastructure1.yml * Added add-infrastructure1.yml * Added add-infrastructure1.yml * Added add-infrastructure1.yml * Added add-infrastructure1.yml * Added add-infrastructure1.yml * Added add-infrastructure1.yml * Added add-infrastructure1.yml * Added add-infrastructure1.yml * Added add-infrastructure1.yml * Added add-infrastructure1.yml * Added add-infrastructure1.yml * Added add-infrastructure1.yml * Added add-infrastructure1.yml --- Jenkinsfile | 25 ++++++++++++- add-infrastructure1.yml | 81 +++++++++++++++++++++++++++++++++++++++++ dockerfile | 4 +- 3 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 add-infrastructure1.yml diff --git a/Jenkinsfile b/Jenkinsfile index 30a65f4a243..214708c8881 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,6 +6,9 @@ pipeline{ environment { DOCKERHUB_CREDENTIALS=credentials('docker-jenkins-connect') DOCKERUSER="banina" + AWS_ACCESS_KEY_ID=credentials('aws-access-key') + AWS_SECRET_ACCESS_KEY=credentials('aws-secret-key') + AWS_DEFAULT_REGION=('us-east-1') } stages{ stage('Maven Build'){ @@ -32,6 +35,22 @@ pipeline{ sh 'docker push $DOCKERUSER/spring-petclinic:${BUILD_NUMBER}-dev' } } + stage('cloudformation') { + steps{ + sh"aws cloudformation create-stack --stack-name spring-petclinic-${BUILD_NUMBER} --template-body file://add-infrastructure1.yml --region 'us-east-1' --parameters ParameterKey=KeyName,ParameterValue=cloudformation ParameterKey=ServerName,ParameterValue=spring-petclinic-${BUILD_NUMBER}" + } + } + stage('WaitingforInstancetoComeup'){ + steps{ + sh"sleep 2m" + } + } + stage('GetInstanceIP') { + steps{ + springIP = $(sh "aws ec2 describe-instances --filters Name=tag:Name,Values='spring-petclinic-${BUILD_NUMBER}' --query 'Reservations[].Instances[].PublicIpAddress' --output text") + sh "echo ${springIP}" + } + } stage('Cleanup') { steps{ sh "docker rmi $DOCKERUSER/spring-petclinic:${BUILD_NUMBER}-dev" @@ -48,5 +67,9 @@ pipeline{ sh 'docker logout' } } - } + + + + + diff --git a/add-infrastructure1.yml b/add-infrastructure1.yml new file mode 100644 index 00000000000..de9e91ab476 --- /dev/null +++ b/add-infrastructure1.yml @@ -0,0 +1,81 @@ +AWSTemplateFormatVersion: 2010-09-09 +Description: >- + Provision AWS::EC2::Instance to test the petclinic application +Parameters: + KeyName: + Description: Name of an existing EC2 KeyPair to enable SSH access to the instance + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: must be the name of an existing EC2 KeyPair. + InstanceType: + Description: WebServer EC2 instance type + Type: String + Default: t2.micro + ConstraintDescription: must be a valid EC2 instance type. + AmiId: + Description: Amazon EC2 AMI + Type: String + Default: ami-0ff8a91507f77f867 + SSHLocation: + Description: The IP address range that can be used to SSH to the EC2 instances + Type: String + MinLength: '9' + MaxLength: '18' + Default: 0.0.0.0/0 + AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})' + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + ServerName: + Description: The name of my instance + Type: String + Default: dockerhost +Resources: + Dockerhost: + Type: 'AWS::EC2::Instance' + Properties: + InstanceType: !Ref InstanceType + SecurityGroups: + - !Ref InstanceSecurityGroup + KeyName: !Ref KeyName + ImageId: !Ref AmiId + Tags: + - Key: Name + Value: !Ref ServerName + UserData: + !Base64 | + #!/bin/bash + sudo yum update -y + sudo amazon-linux-extras install docker -y + sudo systemctl start docker + sudo usermod -a -G docker ec2-user + sudo systemctl enable docker + curl -L https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker-compose + sudo systemctl restart docker + InstanceSecurityGroup: + Type: 'AWS::EC2::SecurityGroup' + Properties: + GroupDescription: Enable SSH access via port 22 + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: '22' + ToPort: '22' + CidrIp: !Ref SSHLocation +Outputs: + InstanceId: + Description: InstanceId of the newly created EC2 instance + Value: !Ref Dockerhost + AZ: + Description: Availability Zone of the newly created EC2 instance + Value: !GetAtt + - Dockerhost + - AvailabilityZone + PublicIP: + Description: Public IP address of the newly created EC2 instance + Value: !GetAtt + - Dockerhost + - PublicIp + + + + + + diff --git a/dockerfile b/dockerfile index 7d9479d2dfc..09ebd3058f9 100644 --- a/dockerfile +++ b/dockerfile @@ -1,3 +1,3 @@ -FROM openjdk:11 +FROM openjdk:8-alpine COPY target/*.jar /spring-petclinic.jar -CMD ["java", ""-jar" , "spring-petclinic.jar"] +ENTRYPOINT ["java","-jar","spring-petclinic.jar"] From c802f47712b7bb009c8f1417dc905847f4c8f69b Mon Sep 17 00:00:00 2001 From: banina Date: Sat, 15 Oct 2022 00:07:15 -0400 Subject: [PATCH 6/9] added a jenkinsfile-master to build a master CI --- Jenkinsfile | 75 ---------------------------------------------- Jenkinsfile-master | 65 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 75 deletions(-) delete mode 100644 Jenkinsfile create mode 100644 Jenkinsfile-master diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 214708c8881..00000000000 --- a/Jenkinsfile +++ /dev/null @@ -1,75 +0,0 @@ -pipeline{ - agent any - tools { - maven 'Maven' - } - environment { - DOCKERHUB_CREDENTIALS=credentials('docker-jenkins-connect') - DOCKERUSER="banina" - AWS_ACCESS_KEY_ID=credentials('aws-access-key') - AWS_SECRET_ACCESS_KEY=credentials('aws-secret-key') - AWS_DEFAULT_REGION=('us-east-1') - } - stages{ - stage('Maven Build'){ - steps{ - sh "mvn clean package" - } - } - stage('Docker Build Petclinic') { - - steps { - sh 'docker build -t $DOCKERUSER/spring-petclinic:${BUILD_NUMBER}-dev .' - } - } - stage('Login to Docker HUB') { - - steps { - sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin' - } - } - - stage('Push') { - - steps { - sh 'docker push $DOCKERUSER/spring-petclinic:${BUILD_NUMBER}-dev' - } - } - stage('cloudformation') { - steps{ - sh"aws cloudformation create-stack --stack-name spring-petclinic-${BUILD_NUMBER} --template-body file://add-infrastructure1.yml --region 'us-east-1' --parameters ParameterKey=KeyName,ParameterValue=cloudformation ParameterKey=ServerName,ParameterValue=spring-petclinic-${BUILD_NUMBER}" - } - } - stage('WaitingforInstancetoComeup'){ - steps{ - sh"sleep 2m" - } - } - stage('GetInstanceIP') { - steps{ - springIP = $(sh "aws ec2 describe-instances --filters Name=tag:Name,Values='spring-petclinic-${BUILD_NUMBER}' --query 'Reservations[].Instances[].PublicIpAddress' --output text") - sh "echo ${springIP}" - } - } - stage('Cleanup') { - steps{ - sh "docker rmi $DOCKERUSER/spring-petclinic:${BUILD_NUMBER}-dev" - } - } - stage('CleanWorkSpace'){ - steps { - cleanWs() - } - } - } - post { - always { - sh 'docker logout' - } - } -} - - - - - diff --git a/Jenkinsfile-master b/Jenkinsfile-master new file mode 100644 index 00000000000..e76224d7d72 --- /dev/null +++ b/Jenkinsfile-master @@ -0,0 +1,65 @@ +pipeline{ + agent any + tools { + maven 'maven' + } + environment { + DOCKERHUB_CREDENTIALS=credentials('Jenkins_Docker-token') + DOCKERUSER="banina" + // AWS_ACCESS_KEY_ID=credentials('aws-access-id') + // AWS_SECRET_ACCESS_KEY=credentials('aws-secret-id') + // AWS_DEFAULT_REGION=('us-east-1') + } + stages{ + stage('Maven Build'){ + steps{ + sh "mvn clean package" + } + } + stage('Docker Build Petclinic') { + + steps { + sh 'docker build -t $DOCKERUSER/spring-petclinic:${BUILD_NUMBER} .' + } + } + stage('Login to Docker HUB') { + + steps { + sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin' + } + } + + stage('Push Docker Image to Container Registry') { + + steps { + sh 'docker push $DOCKERUSER/spring-petclinic:${BUILD_NUMBER}' + sh 'docker tag $DOCKERUSER/spring-petclinic:${BUILD_NUMBER} $DOCKERUSER/spring-petclinic:latest' + sh 'docker push $DOCKERUSER/spring-petclinic:latest' + } + } + // stage('cloudformation') { + // steps{ + // sh"aws cloudformation create-stack --stack-name spring-petclinic-${BUILD_NUMBER} --template-body file://infrastructure.yaml --region 'us-east-1' --parameters ParameterKey=KeyName,ParameterValue=cloudformation ParameterKey=ServerName,ParameterValue=spring-petclinic-${BUILD_NUMBER}" + // } + // } + // stage('WaitingForInstanceToComeUp') { + // steps{ + // sh ' sleep 2m' + // } + // } + // stage('GetInstanceIP') { + // steps{ + // springIP = $(sh "aws ec2 describe-instances --filters Name=tag:Name,Values='spring-petclinic-${BUILD_NUMBER}' --query 'Reservations[].Instances[].PublicIpAddress' --output text") + // sh "echo ${springIP}" + // } + // } + } + post { + always { + sh 'docker logout' + sh 'docker rmi $DOCKERUSER/spring-petclinic:${BUILD_NUMBER}' + sh 'docker rmi $DOCKERUSER/spring-petclinic:latest' + cleanWs() + } + } +} \ No newline at end of file From f00884c2a33e55515f9c30dcd4c791ed66c12417 Mon Sep 17 00:00:00 2001 From: banina Date: Mon, 17 Oct 2022 21:13:27 -0400 Subject: [PATCH 7/9] Node1 added to jenkinsfile. --- Jenkinsfile-master | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile-master b/Jenkinsfile-master index e76224d7d72..beb2c2f5aee 100644 --- a/Jenkinsfile-master +++ b/Jenkinsfile-master @@ -1,5 +1,5 @@ pipeline{ - agent any + agent Node1 tools { maven 'maven' } From 0e120cddbcf532561ab474acfb7b14cade8bdfa9 Mon Sep 17 00:00:00 2001 From: banina Date: Mon, 17 Oct 2022 21:23:57 -0400 Subject: [PATCH 8/9] Node1 added to jenkinsfile. --- Jenkinsfile-master | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile-master b/Jenkinsfile-master index beb2c2f5aee..e76224d7d72 100644 --- a/Jenkinsfile-master +++ b/Jenkinsfile-master @@ -1,5 +1,5 @@ pipeline{ - agent Node1 + agent any tools { maven 'maven' } From 5a350f742b345ca6e619b9c86c6aea56b91058db Mon Sep 17 00:00:00 2001 From: banina Date: Mon, 17 Oct 2022 21:53:47 -0400 Subject: [PATCH 9/9] Added Jenkinsfile-Release-CI. --- Jenkinsfile-Release-CI | 68 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Jenkinsfile-Release-CI diff --git a/Jenkinsfile-Release-CI b/Jenkinsfile-Release-CI new file mode 100644 index 00000000000..5a54b8dc641 --- /dev/null +++ b/Jenkinsfile-Release-CI @@ -0,0 +1,68 @@ +pipeline{ + agent any + tools { + maven 'maven' + } + parameters { + string(name: "RELEASE_VERSION_NO", + defaultValue: "", + description: "Release version number" + ) + } + environment { + DOCKERHUB_CREDENTIALS=credentials('Jenkins_Docker-token') + DOCKERUSER="banina" + // AWS_ACCESS_KEY_ID=credentials('aws-access-id') + // AWS_SECRET_ACCESS_KEY=credentials('aws-secret-id') + // AWS_DEFAULT_REGION=('us-east-1') + } + stages{ + stage('Maven Build'){ + steps{ + sh "mvn clean package" + } + } + stage('Docker Build Petclinic') { + + steps { + sh 'docker build -t $DOCKERUSER/spring-petclinic:${RELEASE_VERSION_NO} .' + } + } + stage('Login to Docker HUB') { + + steps { + sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin' + } + } + + stage('Push Docker Image to Container Registry') { + + steps { + sh 'docker push $DOCKERUSER/spring-petclinic:${RELEASE_VERSION_NO}' + } + } + // stage('cloudformation') { + // steps{ + // sh"aws cloudformation create-stack --stack-name spring-petclinic-${BUILD_NUMBER} --template-body file://infrastructure.yaml --region 'us-east-1' --parameters ParameterKey=KeyName,ParameterValue=cloudformation ParameterKey=ServerName,ParameterValue=spring-petclinic-${BUILD_NUMBER}" + // } + // } + // stage('WaitingForInstanceToComeUp') { + // steps{ + // sh ' sleep 2m' + // } + // } + // stage('GetInstanceIP') { + // steps{ + // springIP = $(sh "aws ec2 describe-instances --filters Name=tag:Name,Values='spring-petclinic-${BUILD_NUMBER}' --query 'Reservations[].Instances[].PublicIpAddress' --output text") + // sh "echo ${springIP}" + // } + // } + } + post { + always { + sh 'docker logout' + sh 'docker rmi $DOCKERUSER/spring-petclinic:${RELEASE_VERSION_NO}' + cleanWs() + } + } +} \ No newline at end of file