Skip to content

Commit f8a6215

Browse files
committed
Draft create
1 parent 1ea325c commit f8a6215

File tree

17 files changed

+359
-0
lines changed

17 files changed

+359
-0
lines changed

.dockerignore

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

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM openjdk:8-jdk-alpine
2+
ENV PORT 8080
3+
EXPOSE 8080
4+
COPY target/*.jar /opt/app.jar
5+
WORKDIR /opt
6+
CMD ["java", "-jar", "app.jar"]

Jenkinsfile

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
pipeline {
2+
agent {
3+
label "jenkins-maven"
4+
}
5+
environment {
6+
ORG = 'jenkinsx'
7+
APP_NAME = 'docker-kubernetes-hello-world'
8+
GIT_CREDS = credentials('jenkins-x-git')
9+
CHARTMUSEUM_CREDS = credentials('jenkins-x-chartmuseum')
10+
GIT_USERNAME = "$GIT_CREDS_USR"
11+
GIT_API_TOKEN = "$GIT_CREDS_PSW"
12+
}
13+
stages {
14+
stage('CI Build and push snapshot') {
15+
when {
16+
branch 'PR-*'
17+
}
18+
environment {
19+
PREVIEW_VERSION = "0.0.0-SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER"
20+
PREVIEW_NAMESPACE = "$APP_NAME-$BRANCH_NAME".toLowerCase()
21+
HELM_RELEASE = "$PREVIEW_NAMESPACE".toLowerCase()
22+
}
23+
steps {
24+
container('maven') {
25+
sh "mvn versions:set -DnewVersion=$PREVIEW_VERSION"
26+
sh "mvn install"
27+
sh "docker build -t \$JENKINS_X_DOCKER_REGISTRY_SERVICE_HOST:\$JENKINS_X_DOCKER_REGISTRY_SERVICE_PORT/$ORG/$APP_NAME:$PREVIEW_VERSION ."
28+
sh "docker push \$JENKINS_X_DOCKER_REGISTRY_SERVICE_HOST:\$JENKINS_X_DOCKER_REGISTRY_SERVICE_PORT/$ORG/$APP_NAME:$PREVIEW_VERSION"
29+
}
30+
31+
dir ('./charts/preview') {
32+
container('maven') {
33+
sh "make preview"
34+
sh "jx preview --app $APP_NAME --dir ../.."
35+
}
36+
}
37+
}
38+
}
39+
stage('Build Release') {
40+
when {
41+
branch 'master'
42+
}
43+
steps {
44+
container('maven') {
45+
// ensure we're not on a detached head
46+
sh "git checkout master"
47+
// until we switch to the new kubernetes / jenkins credential implementation use git credentials store
48+
sh "git config --global credential.helper store"
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/docker-kubernetes-hello-world') {
54+
container('maven') {
55+
sh "make tag"
56+
}
57+
}
58+
container('maven') {
59+
sh 'mvn clean deploy'
60+
61+
sh "docker build -t \$JENKINS_X_DOCKER_REGISTRY_SERVICE_HOST:\$JENKINS_X_DOCKER_REGISTRY_SERVICE_PORT/$ORG/$APP_NAME:\$(cat VERSION) ."
62+
sh "docker push \$JENKINS_X_DOCKER_REGISTRY_SERVICE_HOST:\$JENKINS_X_DOCKER_REGISTRY_SERVICE_PORT/$ORG/$APP_NAME:\$(cat VERSION)"
63+
}
64+
}
65+
}
66+
stage('Promote to Environments') {
67+
when {
68+
branch 'master'
69+
}
70+
steps {
71+
dir ('./charts/docker-kubernetes-hello-world') {
72+
container('maven') {
73+
sh 'jx step changelog --version \$(cat ../../VERSION)'
74+
75+
// release the helm chart
76+
sh 'make release'
77+
78+
// promote through all 'Auto' promotion Environments
79+
sh 'jx promote -b --all-auto --timeout 1h --version \$(cat ../../VERSION)'
80+
}
81+
}
82+
}
83+
}
84+
}
85+
post {
86+
always {
87+
cleanWs()
88+
}
89+
}
90+
}

NOTICE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License:
2+
3+
Copyright (C) 2011-2015 Heroku, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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
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: docker-kubernetes-hello-world
5+
version: 0.1.0-SNAPSHOT
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
CHART_REPO := http://jenkins-x-chartmuseum:8080
2+
CURRENT=$(pwd)
3+
NAME := docker-kubernetes-hello-world
4+
OS := $(shell uname)
5+
RELEASE_VERSION := $(shell cat ../../VERSION)
6+
7+
build: clean
8+
rm -rf requirements.lock
9+
helm dependency build
10+
helm lint
11+
12+
install: clean build
13+
helm install . --name ${NAME}
14+
15+
upgrade: clean build
16+
helm upgrade ${NAME} .
17+
18+
delete:
19+
helm delete --purge ${NAME}
20+
21+
clean:
22+
rm -rf charts
23+
rm -rf ${NAME}*.tgz
24+
25+
release: clean
26+
helm dependency build
27+
helm lint
28+
helm init --client-only
29+
helm package .
30+
curl --fail -u $(CHARTMUSEUM_CREDS_USR):$(CHARTMUSEUM_CREDS_PSW) --data-binary "@$(NAME)-$(shell sed -n 's/^version: //p' Chart.yaml).tgz" $(CHART_REPO)/api/charts
31+
rm -rf ${NAME}*.tgz%
32+
33+
tag:
34+
ifeq ($(OS),Darwin)
35+
sed -i "" -e "s/version:.*/version: $(RELEASE_VERSION)/" Chart.yaml
36+
sed -i "" -e "s/tag: .*/tag: $(RELEASE_VERSION)/" values.yaml
37+
else ifeq ($(OS),Linux)
38+
sed -i -e "s/version:.*/version: $(RELEASE_VERSION)/" Chart.yaml
39+
sed -i -e "s/repository: .*/repository: $(JENKINS_X_DOCKER_REGISTRY_SERVICE_HOST):$(JENKINS_X_DOCKER_REGISTRY_SERVICE_PORT)\/$(ORG)\/$(APP_NAME)/" values.yaml
40+
sed -i -e "s/tag: .*/tag: $(RELEASE_VERSION)/" values.yaml
41+
else
42+
echo "platfrom $(OS) not supported to release from"
43+
exit -1
44+
endif
45+
git add --all
46+
git commit -m "release $(RELEASE_VERSION)" --allow-empty # if first release then no verion update is performed
47+
git tag -fa v$(RELEASE_VERSION) -m "Release version $(RELEASE_VERSION)"
48+
git push origin v$(RELEASE_VERSION)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Java application
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
Get the application URL by running these commands:
3+
4+
kubectl get ingress {{ template "fullname" . }}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{{/* vim: set filetype=mustache: */}}
2+
{{/*
3+
Expand the name of the chart.
4+
*/}}
5+
{{- define "name" -}}
6+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7+
{{- end -}}
8+
9+
{{/*
10+
Create a default fully qualified app name.
11+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12+
*/}}
13+
{{- define "fullname" -}}
14+
{{- $name := default .Chart.Name .Values.nameOverride -}}
15+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
16+
{{- end -}}

0 commit comments

Comments
 (0)