mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-18 13:35:50 +00:00
ECS Deployments LDOP-101 (#13)
* LDOP-218 created ECS Jenkinsfile * LDOP-218 checking if ecs-cli image works properly * LDOP-218 create skeleton for Jenkinsfile * LDOP-118 add warning * complete docker-compose for ECS deployments LDOP-218 * LDOP-218 specify different services per env * LDOP-218 remove previous cluster auto * LDOP-218 add URL output * LDOP-218 typo syntax * LDOP-219 syntax error * LDOP-219 syntax error * LDOP-219 typo * LDOP-219 url testing * LDOP-219 limited duplicates * LDOP-219 add build step * LDOP-219 testing agent scoping * LDOP-219 scoping of agents fix * LDOP-219 add sonar tests add docker build and push * Correct Pivotal Jenkinsfile Build Step to Utilize Nexus * LDOP-219 add docker cred specifications * LDOP-219 add requirements to Jenkinsfile * Add requirements to pivotal Jenkinsfile * small typo * LDOP-219 Remove triple quotes as unneeded
This commit is contained in:
parent
e188715aa5
commit
afa5ecb8a6
3 changed files with 196 additions and 44 deletions
7
ecs-compose.yml
Normal file
7
ecs-compose.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
# Does not support build derivative
|
||||
spring-petclinic:
|
||||
image: liatrio/ecs-spring-petclinic:latest
|
||||
cpu_shares: 100
|
||||
mem_limit: 262144000
|
||||
ports:
|
||||
- "80:8080"
|
135
jenkinsfiles/ecs
Normal file
135
jenkinsfiles/ecs
Normal file
|
@ -0,0 +1,135 @@
|
|||
#!groovy
|
||||
/*
|
||||
* Author:
|
||||
*
|
||||
* Shane MacBride @shanemacbride <shanem@liatrio.com>
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* "DockerHub" Jenkins Credentials
|
||||
* "ECS" Jenkins Credentials
|
||||
* "ecs" AWS EC2 Keypair
|
||||
*
|
||||
*/
|
||||
pipeline {
|
||||
agent none
|
||||
stages {
|
||||
stage('Build') {
|
||||
agent {
|
||||
docker {
|
||||
image 'maven:3.5.0'
|
||||
args '-e INITIAL_ADMIN_USER -e INITIAL_ADMIN_PASSWORD --network=${LDOP_NETWORK_NAME}'
|
||||
}
|
||||
}
|
||||
steps {
|
||||
configFileProvider(
|
||||
[configFile(fileId: 'nexus', variable: 'MAVEN_SETTINGS')]) {
|
||||
sh 'mvn -s $MAVEN_SETTINGS clean deploy -DskipTests=true -B'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Sonar') {
|
||||
agent {
|
||||
docker {
|
||||
image 'sebp/sonar-runner'
|
||||
args '-e SONAR_ACCOUNT_LOGIN -e SONAR_ACCOUNT_PASSWORD -e SONAR_DB_URL -e SONAR_DB_LOGIN -e SONAR_DB_PASSWORD --network=${LDOP_NETWORK_NAME}'
|
||||
}
|
||||
}
|
||||
steps {
|
||||
sh '/opt/sonar-runner-2.4/bin/sonar-runner -e -D sonar.login=${SONAR_ACCOUNT_LOGIN} -D sonar.password=${SONAR_ACCOUNT_PASSWORD} -D sonar.jdbc.url=${SONAR_DB_URL} -D sonar.jdbc.username=${SONAR_DB_LOGIN} -D sonar.jdbc.password=${SONAR_DB_PASSWORD}'
|
||||
}
|
||||
}
|
||||
stage('Docker Build') {
|
||||
agent any
|
||||
steps {
|
||||
sh 'docker build -t liatrio/ecs-spring-petclinic:latest .'
|
||||
}
|
||||
}
|
||||
stage('Docker Push') {
|
||||
agent any
|
||||
steps {
|
||||
withCredentials([usernamePassword(credentialsId: 'DockerHub', passwordVariable: 'dockerPassword', usernameVariable: 'dockerUsername')]){
|
||||
sh "docker login -u ${env.dockerUsername} -p ${env.dockerPassword}"
|
||||
sh 'docker push liatrio/ecs-spring-petclinic:latest'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Create ECS Cluster') {
|
||||
agent {
|
||||
docker {
|
||||
image 'liatrio/ecs-cli'
|
||||
args '-u 0:0'
|
||||
}
|
||||
}
|
||||
steps {
|
||||
withCredentials([usernamePassword(credentialsId: 'ECS', passwordVariable: 'awsSecret', usernameVariable: 'awsAccess')]){
|
||||
sh "ecs-cli configure --region us-west-2 --access-key ${env.awsAccess} --secret-key ${env.awsSecret} --cluster petclinic-cluster"
|
||||
sh "ecs-cli up --force --keypair ecs --capability-iam --size 3 --instance-type t2.micro"
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Deploy to ECS DEV') {
|
||||
agent {
|
||||
docker {
|
||||
image 'liatrio/ecs-cli'
|
||||
args '-u 0:0'
|
||||
}
|
||||
}
|
||||
steps {
|
||||
withCredentials([usernamePassword(credentialsId: 'ECS', passwordVariable: 'awsSecret', usernameVariable: 'awsAccess')]){
|
||||
sh "ecs-cli configure --region us-west-2 --access-key ${env.awsAccess} --secret-key ${env.awsSecret} --cluster petclinic-cluster"
|
||||
sh "ecs-cli compose --project-name spring-petclinic-dev --file ecs-compose.yml up"
|
||||
sh "ecs-cli ps | grep -m 1 dev | awk -F'RUNNING |:' '{print \"DEV URL: http://\"\$2\"/petclinic\"}'"
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Deploy to ECS QA') {
|
||||
agent {
|
||||
docker {
|
||||
image 'liatrio/ecs-cli'
|
||||
args '-u 0:0'
|
||||
}
|
||||
}
|
||||
steps {
|
||||
withCredentials([usernamePassword(credentialsId: 'ECS', passwordVariable: 'awsSecret', usernameVariable: 'awsAccess')]){
|
||||
sh "ecs-cli configure --region us-west-2 --access-key ${env.awsAccess} --secret-key ${env.awsSecret} --cluster petclinic-cluster"
|
||||
sh "ecs-cli compose --project-name spring-petclinic-qa --file ecs-compose.yml up"
|
||||
sh "ecs-cli ps | grep -m 1 qa | awk -F'RUNNING |:' '{print \"QA URL: http://\"\$2\"/petclinic\"}'"
|
||||
input 'Deploy to ECS Production?'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Deploy to ECS PROD') {
|
||||
agent {
|
||||
docker {
|
||||
image 'liatrio/ecs-cli'
|
||||
args '-u 0:0'
|
||||
}
|
||||
}
|
||||
steps {
|
||||
withCredentials([usernamePassword(credentialsId: 'ECS', passwordVariable: 'awsSecret', usernameVariable: 'awsAccess')]){
|
||||
sh "ecs-cli configure --region us-west-2 --access-key ${env.awsAccess} --secret-key ${env.awsSecret} --cluster petclinic-cluster"
|
||||
sh "ecs-cli compose --project-name spring-petclinic-prod --file ecs-compose.yml up"
|
||||
sh "ecs-cli ps | grep -m 1 prod | awk -F'RUNNING |:' '{print \"PROD URL: http://\"\$2\"/petclinic\"}'"
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Output Results') {
|
||||
agent {
|
||||
docker {
|
||||
image 'liatrio/ecs-cli'
|
||||
args '-u 0:0'
|
||||
}
|
||||
}
|
||||
steps {
|
||||
withCredentials([usernamePassword(credentialsId: 'ECS', passwordVariable: 'awsSecret', usernameVariable: 'awsAccess')]){
|
||||
sh "ecs-cli configure --region us-west-2 --access-key ${env.awsAccess} --secret-key ${env.awsSecret} --cluster petclinic-cluster"
|
||||
sh "ecs-cli ps | grep -m 1 dev | awk -F'RUNNING |:' '{print \"DEV URL: http://\"\$2\"/petclinic\"}'"
|
||||
sh "ecs-cli ps | grep -m 1 qa | awk -F'RUNNING |:' '{print \"QA URL: http://\"\$2\"/petclinic\"}'"
|
||||
sh "ecs-cli ps | grep -m 1 prod | awk -F'RUNNING |:' '{print \"PROD URL: http://\"\$2\"/petclinic\"}'"
|
||||
echo "To delete resources allocated run: ecs-cli down --force"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,14 @@
|
|||
#!groovy
|
||||
/*
|
||||
* Author:
|
||||
*
|
||||
* Shane MacBride @shanemacbride <shanem@liatrio.com>
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* "pivotal" Jenkins Credentials
|
||||
*
|
||||
*/
|
||||
pipeline {
|
||||
agent none
|
||||
stages {
|
||||
|
@ -12,7 +22,7 @@ pipeline {
|
|||
steps {
|
||||
configFileProvider(
|
||||
[configFile(fileId: 'nexus', variable: 'MAVEN_SETTINGS')]) {
|
||||
sh 'mvn -s $MAVEN_SETTINGS clean install -DskipTests=true -B'
|
||||
sh 'mvn -s $MAVEN_SETTINGS clean deploy -DskipTests=true -B'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue