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 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 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/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 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 diff --git a/dockerfile b/dockerfile new file mode 100644 index 00000000000..09ebd3058f9 --- /dev/null +++ b/dockerfile @@ -0,0 +1,3 @@ +FROM openjdk:8-alpine +COPY target/*.jar /spring-petclinic.jar +ENTRYPOINT ["java","-jar","spring-petclinic.jar"]