diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000000..21ef6944ab4 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,51 @@ +pipeline{ + agent any + tools { + maven 'Maven' + } + environment { + DOCKERHUB_CREDENTIALS=credentials('dockerhub-token') + DOCKERUSER="banina" + } + 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('Cleanup') { + steps{ + sh "docker rmi $DOCKERUSER/spring-petclinic:${BUILD_NUMBER}-dev" + } + } + stage('CleanWorkSpace'){ + steps { + cleanWs() + } + } + } + post { + always { + sh 'docker logout' + } + } +} \ 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"]