Skip to content

Commit 585c835

Browse files
author
Jean-Philippe Briend
committed
Draft create
1 parent 2630ce0 commit 585c835

18 files changed

Lines changed: 428 additions & 0 deletions

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
draft.toml
2+
charts/
3+
NOTICE
4+
LICENSE
5+
README.md

.helmignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*~
18+
# Various IDEs
19+
.project
20+
.idea/
21+
*.tmproj
22+
*.png
23+
24+
# known compile time folders
25+
target/
26+
node_modules/
27+
vendor/

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM openjdk:8-jdk-slim
2+
ENV PORT 8080
3+
ENV CLASSPATH /opt/lib
4+
EXPOSE 8080
5+
6+
# copy pom.xml and wildcards to avoid this command failing if there's no target/lib directory
7+
COPY pom.xml target/lib* /opt/lib/
8+
9+
# NOTE we assume there's only 1 jar in the target dir
10+
# but at least this means we don't have to guess the name
11+
# we could do with a better way to know the name - or to always create an app.jar or something
12+
COPY target/*.jar /opt/app.jar
13+
WORKDIR /opt
14+
CMD ["java", "-jar", "app.jar"]

Jenkinsfile

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
pipeline {
2+
agent {
3+
label "jenkins-maven"
4+
}
5+
environment {
6+
ORG = 'cloudbeers'
7+
APP_NAME = 'wordsmith-api'
8+
CHARTMUSEUM_CREDS = credentials('jenkins-x-chartmuseum')
9+
}
10+
stages {
11+
stage('CI Build and push snapshot') {
12+
when {
13+
branch 'PR-*'
14+
}
15+
environment {
16+
PREVIEW_VERSION = "0.0.0-SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER"
17+
PREVIEW_NAMESPACE = "$APP_NAME-$BRANCH_NAME".toLowerCase()
18+
HELM_RELEASE = "$PREVIEW_NAMESPACE".toLowerCase()
19+
}
20+
steps {
21+
container('maven') {
22+
sh "mvn versions:set -DnewVersion=$PREVIEW_VERSION"
23+
sh "mvn install"
24+
sh 'export VERSION=$PREVIEW_VERSION && skaffold build -f skaffold.yaml'
25+
26+
27+
sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$PREVIEW_VERSION"
28+
}
29+
30+
dir ('./charts/preview') {
31+
container('maven') {
32+
sh "make preview"
33+
sh "jx preview --app $APP_NAME --dir ../.."
34+
}
35+
}
36+
}
37+
}
38+
stage('Build Release') {
39+
when {
40+
branch 'master'
41+
}
42+
steps {
43+
container('maven') {
44+
// ensure we're not on a detached head
45+
sh "git checkout master"
46+
sh "git config --global credential.helper store"
47+
48+
sh "jx step git credentials"
49+
// so we can retrieve the version in later steps
50+
sh "echo \$(jx-release-version) > VERSION"
51+
sh "mvn versions:set -DnewVersion=\$(cat VERSION)"
52+
}
53+
dir ('./charts/wordsmith-api') {
54+
container('maven') {
55+
sh "make tag"
56+
}
57+
}
58+
container('maven') {
59+
sh 'mvn clean deploy'
60+
61+
sh 'export VERSION=`cat VERSION` && skaffold build -f skaffold.yaml'
62+
63+
64+
sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:\$(cat VERSION)"
65+
}
66+
}
67+
}
68+
stage('Promote to Environments') {
69+
when {
70+
branch 'master'
71+
}
72+
steps {
73+
dir ('./charts/wordsmith-api') {
74+
container('maven') {
75+
sh 'jx step changelog --version v\$(cat ../../VERSION)'
76+
77+
// release the helm chart
78+
sh 'jx step helm release'
79+
80+
// promote through all 'Auto' promotion Environments
81+
sh 'jx promote -b --all-auto --timeout 1h --version \$(cat ../../VERSION)'
82+
}
83+
}
84+
}
85+
}
86+
}
87+
post {
88+
always {
89+
cleanWs()
90+
}
91+
failure {
92+
input """Pipeline failed.
93+
We will keep the build pod around to help you diagnose any failures.
94+
95+
Select Proceed or Abort to terminate the build pod"""
96+
}
97+
}
98+
}

charts/preview/Chart.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v1
2+
description: A Helm chart for Kubernetes
3+
icon: https://raw.githubusercontent.com/jenkins-x/jenkins-x-platform/master/images/java.png
4+
name: preview
5+
version: 0.1.0-SNAPSHOT

charts/preview/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
OS := $(shell uname)
2+
3+
preview:
4+
ifeq ($(OS),Darwin)
5+
sed -i "" -e "s/version:.*/version: $(PREVIEW_VERSION)/" Chart.yaml
6+
sed -i "" -e "s/version:.*/version: $(PREVIEW_VERSION)/" ../*/Chart.yaml
7+
sed -i "" -e "s/tag: .*/tag: $(PREVIEW_VERSION)/" values.yaml
8+
else ifeq ($(OS),Linux)
9+
sed -i -e "s/version:.*/version: $(PREVIEW_VERSION)/" Chart.yaml
10+
sed -i -e "s/version:.*/version: $(PREVIEW_VERSION)/" ../*/Chart.yaml
11+
sed -i -e "s|repository: .*|repository: $(DOCKER_REGISTRY)\/cloudbeers\/wordsmith-api|" values.yaml
12+
sed -i -e "s/tag: .*/tag: $(PREVIEW_VERSION)/" values.yaml
13+
else
14+
echo "platfrom $(OS) not supported to release from"
15+
exit -1
16+
endif
17+
echo " version: $(PREVIEW_VERSION)" >> requirements.yaml
18+
jx step helm build

charts/preview/requirements.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
dependencies:
3+
- alias: expose
4+
name: exposecontroller
5+
repository: https://chartmuseum.build.cd.jenkins-x.io
6+
version: 2.3.56
7+
- alias: cleanup
8+
name: exposecontroller
9+
repository: https://chartmuseum.build.cd.jenkins-x.io
10+
version: 2.3.56
11+
- alias: preview
12+
name: wordsmith-api
13+
repository: file://../wordsmith-api

charts/preview/values.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
expose:
3+
Annotations:
4+
helm.sh/hook: post-install,post-upgrade
5+
helm.sh/hook-delete-policy: hook-succeeded
6+
config:
7+
exposer: Ingress
8+
http: true
9+
tlsacme: false
10+
11+
cleanup:
12+
Args:
13+
- --cleanup
14+
Annotations:
15+
helm.sh/hook: pre-delete
16+
helm.sh/hook-delete-policy: hook-succeeded
17+
18+
preview:
19+
image:
20+
repository:
21+
tag:
22+
pullPolicy: IfNotPresent

charts/wordsmith-api/.helmignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*~
18+
# Various IDEs
19+
.project
20+
.idea/
21+
*.tmproj

charts/wordsmith-api/Chart.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v1
2+
description: A Helm chart for Kubernetes
3+
icon: https://raw.githubusercontent.com/jenkins-x/jenkins-x-platform/master/images/java.png
4+
name: wordsmith-api
5+
version: 0.1.0-SNAPSHOT

0 commit comments

Comments
 (0)