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

Add infrastructure stage #10

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
501138c
Add jenkinsfile (#1)
AndrewBanin Jan 25, 2022
c3412ce
Create deploy-docker.yml
AndrewBanin Feb 9, 2022
3d67cb2
Create dev.inv
AndrewBanin Feb 9, 2022
011bcb3
Added Dockerfile to containarized the application (#2)
AndrewBanin Feb 10, 2022
52cd153
dockerfile modified
AndrewBanin Feb 10, 2022
b0cb254
Added add-infrastructure1.yml
AndrewBanin Feb 22, 2022
c7506d3
Added add-infrastructure1.yml
AndrewBanin Feb 22, 2022
553a47a
Added add-infrastructure1.yml
AndrewBanin Feb 22, 2022
70d7509
Added add-infrastructure1.yml
AndrewBanin Feb 22, 2022
3205407
Added add-infrastructure1.yml
AndrewBanin Feb 23, 2022
db194de
Added add-infrastructure1.yml
AndrewBanin Feb 23, 2022
d6419ce
Added add-infrastructure1.yml
AndrewBanin Feb 23, 2022
b8fa57b
Added add-infrastructure1.yml
AndrewBanin Feb 23, 2022
d8bc348
Added add-infrastructure1.yml
AndrewBanin Feb 24, 2022
aab685c
Added add-infrastructure1.yml
AndrewBanin Feb 24, 2022
21e95dd
Added add-infrastructure1.yml
AndrewBanin Feb 24, 2022
cdd0edb
Added add-infrastructure1.yml
AndrewBanin Mar 3, 2022
1b3b883
Added add-infrastructure1.yml
AndrewBanin Mar 8, 2022
c4a1ece
Added add-infrastructure1.yml
AndrewBanin Mar 8, 2022
f144377
Added add-infrastructure1.yml
AndrewBanin Mar 10, 2022
4ff142e
Added add-infrastructure1.yml
AndrewBanin Mar 10, 2022
9b126a7
Added add-infrastructure1.yml
AndrewBanin Apr 12, 2022
30e722a
Added add-infrastructure1.yml
AndrewBanin Apr 12, 2022
92b48d6
Added add-infrastructure1.yml
AndrewBanin Apr 12, 2022
7f5c8ad
Access keys changed
AndrewBanin May 25, 2022
a4dffed
added Access keys
AndrewBanin May 25, 2022
52944ed
add-infrastructure-stage and aws credentials remove
AndrewBanin May 25, 2022
21a5033
add-infrastructure-stage and aws access removed
AndrewBanin May 25, 2022
852d32b
abcd
AndrewBanin May 25, 2022
539d096
modify jenkinsfile
AndrewBanin May 25, 2022
928ba43
modify jenkinsfile
AndrewBanin May 25, 2022
553c6c3
updated jenkinsfile
AndrewBanin Jun 2, 2022
1634ace
updated jenkinsfile
AndrewBanin Jun 2, 2022
f22d9cc
updated jenkinsfile
AndrewBanin Jun 2, 2022
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
51 changes: 51 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -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'
}
}
}
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"]