Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean #12

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions Jenkinsfile-Release-CI
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
65 changes: 65 additions & 0 deletions Jenkinsfile-master
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
81 changes: 81 additions & 0 deletions add-infrastructure1.yml
Original file line number Diff line number Diff line change
@@ -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






28 changes: 28 additions & 0 deletions deploy-docker.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions dev.inv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[dev]
172.31.22.111 ansible_ubuntu
3 changes: 3 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM openjdk:8-alpine
COPY target/*.jar /spring-petclinic.jar
ENTRYPOINT ["java","-jar","spring-petclinic.jar"]