publicando versão funcional openshift template

This commit is contained in:
Alex Baptista 2018-02-25 22:26:10 -03:00
parent 181b5e3ee7
commit 2b52f042be
4 changed files with 237 additions and 49 deletions

View file

@ -1,5 +0,0 @@
FROM docker.io/maven:latest
WORKDIR /
ADD target/spring-petclinic-1.5.1.jar .
EXPOSE 8080
CMD java -jar spring-petclinic-1.5.1.jar

22
Jenkinsfile vendored
View file

@ -1,22 +0,0 @@
node('Slave_AWS'){
stage('Checkout')
{
git 'https://github.com/spring-projects/spring-petclinic.git'
}
stage('Build')
{
//sh 'docker run --rm --name build_maven -v $(pwd):/app docker.io/maven:alpine bash -c "cd app;mvn clean install"'
}
stage('Sonarqube')
{
sh 'docker run --rm --name maven -v $(pwd):/app docker.io/maven:alpine bash -c "cd app; mvn clean install cobertura:cobertura -Dcobertura.report.format=xml sonar:sonar -Dsonar.host.url=http://34.205.24.188:9000"'
}
stage('Unit Test')
{
junit 'target/surefire-reports/*.xml'
}
stage('Archive artifact')
{
archiveArtifacts 'target/spring-petclinic-1.5.1.jar'
}
}

View file

@ -1,22 +0,0 @@
- apiVersion: v1
kind: BuildConfig
metadata:
annotations:
description: Define como empacotar o APP
name: petclinic-docker
spec:
output:
to:
kind: ImageStreamTag
name: petclinic-docker:latest
source:
type: Binary
strategy:
dockerStrategy:
dockerfilePath: Dockerfile
- apiVersion: v1
kind: ImageStream
metadata:
annotations:
description: Acompanha as mudanças na imagem do aplicativo
name: petclinic-docker

View file

@ -0,0 +1,237 @@
apiVersion: v1
kind: Template
metadata:
name: petclinic-web-app
parameters:
- name: APP_NAME
description: The name assigned to all of the application objects defined in this template.
displayName: Application Name
required: true
value: petclinic-web-app
- name: GIT_SOURCE_URL
description: The source URL for the application
displayName: Source URL
required: true
value: https://github.com/alexbaptista/spring-petclinic.git
- name: GIT_SOURCE_REF
description: The source Ref for the application
displayName: Source Ref
required: true
value: master
- description: Github trigger secret. A difficult to guess string encoded as part of the webhook URL. Not encrypted.
displayName: GitHub Webhook Secret
from: '[a-zA-Z0-9]{40}'
generate: expression
name: GITHUB_WEBHOOK_SECRET
required: true
- description: A secret string used to configure the Generic webhook.
displayName: Generic Webhook Secret
from: '[a-zA-Z0-9]{40}'
generate: expression
name: GENERIC_WEBHOOK_SECRET
required: true
objects:
- apiVersion: v1
kind: ImageStream
metadata:
labels:
app: ${APP_NAME}
name: ${APP_NAME}
spec: {}
status:
dockerImageRepository: ""
- apiVersion: v1
kind: BuildConfig
metadata:
annotations:
pipeline.alpha.openshift.io/uses: '[{"name": "${NAME}", "namespace": "", "kind": "DeploymentConfig"}]'
creationTimestamp: null
labels:
name: ${APP_NAME}-pipeline
name: ${APP_NAME}-pipeline
spec:
strategy:
jenkinsPipelineStrategy:
jenkinsfile: |-
try {
timeout(time: 20, unit: 'MINUTES') {
def appName="${APP_NAME}"
def project=""
node {
stage("Initialize") {
project = env.PROJECT_NAME
}
}
node("maven") {
stage("Checkout") {
git url: "${GIT_SOURCE_URL}", branch: "${GIT_SOURCE_REF}"
}
stage("Build JAR") {
sh "mvn clean install"
stash name:"jar", includes:"target/spring-petclinic-1.5.1.jar"
}
}
node {
stage("Build Image") {
unstash name:"jar"
sh "oc start-build ${appName}-docker --from-file=target/spring-petclinic-1.5.1.jar -n ${project}"
openshiftVerifyBuild bldCfg: "${appName}-docker", namespace: project, waitTime: '20', waitUnit: 'min'
}
stage("Deploy") {
openshiftDeploy deploymentConfig: appName, namespace: project
}
}
}
} catch (err) {
echo "in catch block"
echo "Caught: ${err}"
currentBuild.result = 'FAILURE'
throw err
}
type: JenkinsPipeline
triggers:
- github:
secret: "${GITHUB_WEBHOOK_SECRET}"
type: GitHub
- generic:
secret: "${GENERIC_WEBHOOK_SECRET}"
type: Generic
- apiVersion: v1
kind: BuildConfig
metadata:
labels:
app: ${APP_NAME}-docker
name: ${APP_NAME}-docker
spec:
output:
to:
kind: ImageStreamTag
name: ${APP_NAME}:latest
postCommit: {}
resources: {}
runPolicy: Serial
source:
dockerfile: |-
FROM docker.io/maven:alpine
WORKDIR /
ADD spring-petclinic-1.5.1.jar .
EXPOSE 8080
CMD java -jar spring-petclinic-1.5.1.jar
binary:
asFile: spring-petclinic-1.5.1.jar
type: Docker
strategy:
dockerStrategy:
from:
kind: DockerImage
name: docker.io/maven:alpine
type: Docker
triggers: []
- apiVersion: v1
kind: DeploymentConfig
metadata:
labels:
app: ${APP_NAME}
name: ${APP_NAME}
spec:
replicas: 1
selector:
app: ${APP_NAME}
deploymentconfig: ${APP_NAME}
strategy:
rollingParams:
intervalSeconds: 1
maxSurge: 25%
maxUnavailable: 25%
timeoutSeconds: 600
updatePeriodSeconds: 1
type: Rolling
template:
metadata:
labels:
app: ${APP_NAME}
deploymentconfig: ${APP_NAME}
spec:
containers:
- image: ${APP_NAME}:latest
imagePullPolicy: Always
name: ${APP_NAME}
ports:
- containerPort: 8080
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
livenessProbe:
httpGet:
path: /
port: 8080
scheme: HTTP
initialDelaySeconds: 10
timeoutSeconds: 2
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
readinessProbe:
httpGet:
path: /
port: 8080
scheme: HTTP
initialDelaySeconds: 30
timeoutSeconds: 2
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
dnsPolicy: ClusterFirst
restartPolicy: Always
securityContext: {}
terminationGracePeriodSeconds: 30
test: false
triggers:
- type: ConfigChange
- imageChangeParams:
automatic: true
containerNames:
- ${APP_NAME}
from:
kind: ImageStreamTag
name: ${APP_NAME}:latest
type: ImageChange
status: {}
- apiVersion: v1
kind: Service
metadata:
annotations:
openshift.io/generated-by: OpenShiftNewApp
labels:
app: ${APP_NAME}
name: ${APP_NAME}
spec:
ports:
- name: 8080-tcp
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: ${APP_NAME}
deploymentconfig: ${APP_NAME}
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
- apiVersion: v1
kind: Route
metadata:
name: ${APP_NAME}
labels:
app: ${APP_NAME}
spec:
to:
kind: Service
name: ${APP_NAME}
weight: 100
port:
targetPort: 8080-tcp
wildcardPolicy: None