mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-22 15:25:49 +00:00
Polishing during review
This commit is contained in:
parent
f8c219e32a
commit
9963f6307d
6 changed files with 33 additions and 66 deletions
63
Jenkinsfile
vendored
63
Jenkinsfile
vendored
|
@ -1,37 +1,35 @@
|
||||||
#!groovy
|
#!groovy
|
||||||
|
|
||||||
// "Constants"
|
// "Constants"
|
||||||
String getCesBuildLibVersion() { '1.44.3' }
|
String getApplication() {"spring-petclinic-plain" }
|
||||||
String getCesBuildLibRepo() { 'https://github.com/cloudogu/ces-build-lib/' }
|
|
||||||
String getScmManagerCredentials() { 'scmm-user' }
|
String getScmManagerCredentials() { 'scmm-user' }
|
||||||
String getConfigRepositoryUrl() { "http://scmm-scm-manager:9091/scm/repo/cluster/gitops" }
|
String getConfigRepositoryUrl() { "http://scmm-scm-manager:9091/scm/repo/cluster/gitops" }
|
||||||
String getConfigRepositoryPRUrl() { 'http://scmm-scm-manager:9091/scm/api/v2/pull-requests/cluster/gitops' }
|
String getConfigRepositoryPRUrl() { 'http://scmm-scm-manager:9091/scm/api/v2/pull-requests/cluster/gitops' }
|
||||||
|
// The docker daemon cant use the k8s service name, because it is not running inside the cluster
|
||||||
String getDockerRegistryBaseUrl() { "localhost:9092" }
|
String getDockerRegistryBaseUrl() { "localhost:9092" }
|
||||||
|
String getCesBuildLibVersion() { '1.44.3' }
|
||||||
|
String getCesBuildLibRepo() { 'https://github.com/cloudogu/ces-build-lib/' }
|
||||||
|
|
||||||
|
cesBuildLib = library(identifier: "ces-build-lib@${cesBuildLibVersion}",
|
||||||
|
retriever: modernSCM([$class: 'GitSCMSource', remote: cesBuildLibRepo])
|
||||||
|
).com.cloudogu.ces.cesbuildlib
|
||||||
|
|
||||||
properties([
|
properties([
|
||||||
// Don't run concurrent builds, because the ITs use the same port causing random failures on concurrent builds.
|
// Don't run concurrent builds, because the ITs use the same port causing random failures on concurrent builds.
|
||||||
disableConcurrentBuilds()
|
disableConcurrentBuilds()
|
||||||
])
|
])
|
||||||
|
|
||||||
cesBuilbLib = library(identifier: "ces-build-lib@${cesBuildLibVersion}",
|
|
||||||
retriever: modernSCM([$class: 'GitSCMSource', remote: cesBuildLibRepo])
|
|
||||||
).com.cloudogu.ces.cesbuildlib
|
|
||||||
def git = cesBuilbLib.Git.new(this, scmManagerCredentials)
|
|
||||||
|
|
||||||
node {
|
node {
|
||||||
|
|
||||||
mvn = cesBuilbLib.MavenWrapper.new(this)
|
mvn = cesBuildLib.MavenWrapper.new(this)
|
||||||
|
|
||||||
application = "spring-petclinic-plain"
|
|
||||||
|
|
||||||
catchError {
|
catchError {
|
||||||
|
|
||||||
stage('Checkout') {
|
stage('Checkout') {
|
||||||
checkout scm
|
checkout scm
|
||||||
git.clean('')
|
cesBuildLib.Git.new(this).clean('')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
stage('Build') {
|
stage('Build') {
|
||||||
mvn 'clean package -DskipTests'
|
mvn 'clean package -DskipTests'
|
||||||
|
|
||||||
|
@ -44,16 +42,10 @@ node {
|
||||||
mvn "${jacoco}:prepare-agent test ${jacoco}:report"
|
mvn "${jacoco}:prepare-agent test ${jacoco}:report"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
stage('Integration Test') {
|
stage('Integration Test') {
|
||||||
mvn "${jacoco}:prepare-agent-integration failsafe:integration-test failsafe:verify ${jacoco}:report-integration"
|
mvn "${jacoco}:prepare-agent-integration failsafe:integration-test failsafe:verify ${jacoco}:report-integration"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
stage('Static Code Analysis') {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
String imageName = ""
|
String imageName = ""
|
||||||
stage('Docker') {
|
stage('Docker') {
|
||||||
String imageTag = createImageTag()
|
String imageTag = createImageTag()
|
||||||
|
@ -61,8 +53,7 @@ node {
|
||||||
mvn "spring-boot:build-image -DskipTests -Dspring-boot.build-image.imageName=${imageName}"
|
mvn "spring-boot:build-image -DskipTests -Dspring-boot.build-image.imageName=${imageName}"
|
||||||
|
|
||||||
if (isBuildSuccessful()) {
|
if (isBuildSuccessful()) {
|
||||||
def docker = cesBuilbLib.Docker.new(this)
|
def docker = cesBuildLib.Docker.new(this)
|
||||||
// The docker daemon cant use the k8s service name, because it is not running inside the cluster
|
|
||||||
docker.withRegistry("http://${dockerRegistryBaseUrl}") {
|
docker.withRegistry("http://${dockerRegistryBaseUrl}") {
|
||||||
def image = docker.image(imageName)
|
def image = docker.image(imageName)
|
||||||
image.push()
|
image.push()
|
||||||
|
@ -87,6 +78,8 @@ node {
|
||||||
]
|
]
|
||||||
|
|
||||||
pushToConfigRepo(gitopsConfig)
|
pushToConfigRepo(gitopsConfig)
|
||||||
|
} else {
|
||||||
|
echo 'Skipping deploy, because build not successful'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,16 +90,18 @@ node {
|
||||||
|
|
||||||
String pushToConfigRepo(Map gitopsConfig) {
|
String pushToConfigRepo(Map gitopsConfig) {
|
||||||
|
|
||||||
def git = cesBuilbLib.Git.new(this, scmManagerCredentials)
|
def git = cesBuildLib.Git.new(this, scmManagerCredentials)
|
||||||
def applicationRepo = GitRepo.create(git)
|
|
||||||
def changesOnGitOpsRepo = ''
|
def changesOnGitOpsRepo = ''
|
||||||
|
|
||||||
|
// Query and store info about application repo before cloning into gitops repo
|
||||||
|
def applicationRepo = GitRepo.create(git)
|
||||||
|
|
||||||
|
// Display that Jenkins made the GitOps commits not the application repo author
|
||||||
git.committerName = 'Jenkins'
|
git.committerName = 'Jenkins'
|
||||||
git.committerEmail = 'jenkins@cloudogu.com'
|
git.committerEmail = 'jenkins@cloudogu.com'
|
||||||
|
|
||||||
def configRepoTempDir = '.configRepoTempDir'
|
def configRepoTempDir = '.configRepoTempDir'
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
dir(configRepoTempDir) {
|
dir(configRepoTempDir) {
|
||||||
|
@ -130,12 +125,6 @@ String pushToConfigRepo(Map gitopsConfig) {
|
||||||
sh "rm -rf ${configRepoTempDir}"
|
sh "rm -rf ${configRepoTempDir}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (changesOnGitOpsRepo) {
|
|
||||||
// with GitOps we can only add a deployment marker for staging yet
|
|
||||||
// addDeploymentAnnotationToGrafana("staging")
|
|
||||||
}
|
|
||||||
|
|
||||||
return changesOnGitOpsRepo
|
return changesOnGitOpsRepo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,10 +162,6 @@ String createApplicationForStageAndPushToBranch(String stage, String branch, Git
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Reflect build parameters in commit message used for GitOps.
|
|
||||||
* This is meant to bring more transparency into GitOps repo.
|
|
||||||
*/
|
|
||||||
String createApplicationCommitMessage(def git, def applicationRepo) {
|
String createApplicationCommitMessage(def git, def applicationRepo) {
|
||||||
String issueIds = (applicationRepo.commitMessage =~ /#\d*/).collect { "${it} " }.join('')
|
String issueIds = (applicationRepo.commitMessage =~ /#\d*/).collect { "${it} " }.join('')
|
||||||
|
|
||||||
|
@ -188,12 +173,8 @@ String createApplicationCommitMessage(def git, def applicationRepo) {
|
||||||
return message
|
return message
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Reflect build parameters version name.
|
|
||||||
* This is meant to support GitOps PR reviewers to avoid releasing versions not meant for production.
|
|
||||||
*/
|
|
||||||
String createImageTag() {
|
String createImageTag() {
|
||||||
def git = cesBuilbLib.Git.new(this)
|
def git = cesBuildLib.Git.new(this)
|
||||||
String branch = git.simpleBranchName
|
String branch = git.simpleBranchName
|
||||||
String branchSuffix = ""
|
String branchSuffix = ""
|
||||||
|
|
||||||
|
@ -236,9 +217,7 @@ void createPullRequest(Map gitopsConfig) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String application
|
/** Queries and stores info about current repo and HEAD commit */
|
||||||
def cesBuilbLib
|
|
||||||
|
|
||||||
class GitRepo {
|
class GitRepo {
|
||||||
|
|
||||||
static GitRepo create(git) {
|
static GitRepo create(git) {
|
||||||
|
@ -261,3 +240,5 @@ class GitRepo {
|
||||||
final String commitMessage
|
final String commitMessage
|
||||||
final String repositoryUrl
|
final String repositoryUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def cesBuildLib
|
||||||
|
|
12
README.md
12
README.md
|
@ -1,12 +1,6 @@
|
||||||
# Spring PetClinic Sample Application (Cloudogu Ecosystem)
|
# Spring PetClinic Sample Application for cloudogu/k8s-gitops-playground
|
||||||
|
|
||||||
This is the well-known spring sample application petclinic that has been extended to be a showcase for the Cloudogu
|
This is the well-known spring sample application petclinic that has been extended to be a showcase for GitOps.
|
||||||
EcoSystem. See [demo.cloudogu.net](https://cloudogu.com/en/#demo).
|
See [cloudogu/k8s-gitops-playground](https://github.com/cloudogu/k8s-gitops-playground).
|
||||||
|
|
||||||
We extended it by
|
|
||||||
|
|
||||||
* a [Smeagol Wiki](https://github.com/cloudogu/smeagol) (see [Home.md](docs/Home.md))
|
|
||||||
* an [integration test](src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerITCase.java) (run with failsafe plugin, see [pom.xml](pom.xml))
|
|
||||||
* a Jenkinsfile for building, testing and SonarQube analysis.
|
|
||||||
|
|
||||||
For more details on petclinic, see also [original spring petclinci readme.md](readme-petclinic.md).
|
For more details on petclinic, see also [original spring petclinci readme.md](readme-petclinic.md).
|
||||||
|
|
|
@ -5,6 +5,9 @@ metadata:
|
||||||
namespace: production
|
namespace: production
|
||||||
spec:
|
spec:
|
||||||
replicas: 1
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: spring-petclinic-plain
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
|
@ -15,9 +18,4 @@ spec:
|
||||||
image: localhost:9092/petclinic-plain:1
|
image: localhost:9092/petclinic-plain:1
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8080
|
- containerPort: 8080
|
||||||
env:
|
name: http
|
||||||
- name: SOME_ENV
|
|
||||||
value: "Some Value 12345"
|
|
||||||
selector:
|
|
||||||
matchLabels:
|
|
||||||
app: spring-petclinic-plain
|
|
||||||
|
|
|
@ -9,8 +9,6 @@ spec:
|
||||||
type: LoadBalancer
|
type: LoadBalancer
|
||||||
ports:
|
ports:
|
||||||
- port: 9094
|
- port: 9094
|
||||||
targetPort: 8080
|
|
||||||
protocol: TCP
|
|
||||||
name: http
|
name: http
|
||||||
selector:
|
selector:
|
||||||
app: spring-petclinic-plain
|
app: spring-petclinic-plain
|
||||||
|
|
|
@ -5,6 +5,9 @@ metadata:
|
||||||
namespace: staging
|
namespace: staging
|
||||||
spec:
|
spec:
|
||||||
replicas: 1
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: spring-petclinic-plain
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
|
@ -15,9 +18,4 @@ spec:
|
||||||
image: localhost:9092/petclinic-plain:1
|
image: localhost:9092/petclinic-plain:1
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8080
|
- containerPort: 8080
|
||||||
env:
|
name: http
|
||||||
- name: SOME_ENV
|
|
||||||
value: "Some Value 12345"
|
|
||||||
selector:
|
|
||||||
matchLabels:
|
|
||||||
app: spring-petclinic-plain
|
|
||||||
|
|
|
@ -9,8 +9,6 @@ spec:
|
||||||
type: LoadBalancer
|
type: LoadBalancer
|
||||||
ports:
|
ports:
|
||||||
- port: 9093
|
- port: 9093
|
||||||
targetPort: 8080
|
|
||||||
protocol: TCP
|
|
||||||
name: http
|
name: http
|
||||||
selector:
|
selector:
|
||||||
app: spring-petclinic-plain
|
app: spring-petclinic-plain
|
||||||
|
|
Loading…
Reference in a new issue