Skip to content

Commit 7931e76

Browse files
raffisTyrion85
andauthored
added build pipeline & helm chart DK-1665 (#1)
* added build pipeline & helm chart * Changes to roles * Handle mongodbdatabase conflicts Co-authored-by: tyrion85 <tyrion85@gmail.com>
1 parent 9b76b48 commit 7931e76

23 files changed

+1175
-6
lines changed

Jenkinsfile

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import java.util.regex.Pattern
2+
import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
3+
4+
podTemplate(label: 'kubedb',
5+
containers: [
6+
containerTemplate(
7+
name: 'golang',
8+
image: 'bitnami/golang:1.13',
9+
ttyEnabled: true
10+
),
11+
containerTemplate(
12+
name: 'docker',
13+
image: 'docker:latest',
14+
ttyEnabled: true
15+
),
16+
containerTemplate(
17+
name: 'helm',
18+
command: '/bin/ash',
19+
image: 'alpine/helm:latest',
20+
ttyEnabled: true
21+
),
22+
],
23+
volumes: [
24+
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
25+
]
26+
) {
27+
node ('kubedb') {
28+
ansiColor("xterm") {
29+
stage('checkout') {
30+
checkout(scm)
31+
32+
container('docker') {
33+
dockerAuth()
34+
}
35+
}
36+
37+
stage("build") {
38+
container('golang') {
39+
sh 'make all'
40+
}
41+
42+
container('helm') {
43+
sh 'helm lint chart/kubedb'
44+
}
45+
}
46+
47+
stage("publish") {
48+
if (!env.TAG_NAME) {
49+
echo "skip packaging for no tagged release"
50+
} else {
51+
def (_,major,minor,patch,group,label,build) = (env.TAG_NAME =~ /^v(\d{1,3})\.(\d{1,3})\.(\d{1,3})(?:(-([A-Za-z0-9]+)))?$/)[0]
52+
53+
if (!major && !minor && !patch) {
54+
throw new Exception("Invalid tag detected, requires semantic version")
55+
}
56+
57+
version = "$major.$minor.$patch$group"
58+
59+
container('docker') {
60+
sh "docker build . -t nexus.doodle.com:5000/devops/kubedb:${env.TAG_NAME}"
61+
sh "docker push nexus.doodle.com:5000/devops/kubedb:${env.TAG_NAME}"
62+
}
63+
64+
container('helm') {
65+
bumpChartVersion(version)
66+
bumpImageVersion(env.TAG_NAME)
67+
68+
tgz="kubedb-${version}.tgz"
69+
sh "helm package chart/kubedb"
70+
71+
}
72+
73+
container('golang') {
74+
if (label) {
75+
publish(tgz, "helm-staging")
76+
} else {
77+
publish(tgz, "helm-staging")
78+
publish(tgz, "helm-production")
79+
}
80+
}
81+
}
82+
}
83+
}
84+
}
85+
}
86+
87+
void dockerAuth() {
88+
// nexus repository
89+
withCredentials([[
90+
$class : 'UsernamePasswordMultiBinding',
91+
credentialsId : 'nexus',
92+
usernameVariable: 'NEXUS_USER',
93+
passwordVariable: 'NEXUS_PASSWORD'
94+
]]) {
95+
sh "docker login nexus.doodle.com:5000 -u ${env.NEXUS_USER} -p ${env.NEXUS_PASSWORD}"
96+
}
97+
98+
// docker hub
99+
withCredentials([[
100+
$class : 'UsernamePasswordMultiBinding',
101+
credentialsId : 'dockerhub',
102+
usernameVariable: 'DOCKERHUB_USER',
103+
passwordVariable: 'DOCKERHUB_PASSWORD'
104+
]]) {
105+
sh "docker login -u ${env.DOCKERHUB_USER} -p ${env.DOCKERHUB_PASSWORD}"
106+
}
107+
}
108+
109+
def bumpImageVersion(String version) {
110+
echo "Update image tag"
111+
def valuesFile = "./chart/kubedb/values.yaml"
112+
def valuesData = readYaml file: valuesFile
113+
valuesData.image.tag = version
114+
115+
sh "rm $valuesFile"
116+
writeYaml file: valuesFile, data: valuesData
117+
}
118+
119+
def bumpChartVersion(String version) {
120+
// Bump chart version
121+
echo "Update chart version"
122+
def chartFile = "./chart/kubedb/Chart.yaml"
123+
def chartData = readYaml file: chartFile
124+
chartData.version = version
125+
chartData.appVersion = version
126+
127+
sh "rm $chartFile"
128+
writeYaml file: chartFile, data: chartData
129+
}
130+
131+
def publish(String tgz, String repository) {
132+
echo "Push chart ${tgz} to helm repository ${repository}"
133+
134+
withCredentials([[
135+
$class : 'UsernamePasswordMultiBinding',
136+
credentialsId : 'nexus',
137+
usernameVariable: 'NEXUS_USER',
138+
passwordVariable: 'NEXUS_PASSWORD'
139+
]]) {
140+
sh "curl -u \"${env.NEXUS_USER}:${env.NEXUS_PASSWORD}\" https://nexus.doodle.com/repository/${repository}/ --upload-file $tgz --fail"
141+
}
142+
}

chart/kubedb/Chart.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v2
2+
appVersion: 0.0.0
3+
description: A kubernetes controller to deploy databases
4+
home: https://github.com/DoodleScheduling/kubedb
5+
keywords:
6+
- kubernetes-controller
7+
- mongodb
8+
- postgresql
9+
- vault
10+
name: kubedb
11+
sources:
12+
- https://github.com/DoodleScheduling/kubedb
13+
version: 0.0.0

chart/kubedb/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# kubedb helm chart
2+
3+
Installs the [kubedb](https://github.com/DoodleScheduling/kubedb).
4+
5+
## Installing the Chart
6+
7+
To install the chart with the release name `kubedb`:
8+
9+
```console
10+
helm upgrade --install kubedb chart/kubedb
11+
```
12+
13+
This command deploys the kubedb with the default configuration. The [configuration](#configuration) section lists the parameters that can be configured during installation.
14+
15+
## Using the Chart
16+
17+
The chart comes with a ServiceMonitor for use with the [Prometheus Operator](https://github.com/helm/charts/tree/master/stable/prometheus-operator).
18+
If you're not using the Prometheus Operator, you can disable the ServiceMonitor by setting `serviceMonitor.enabled` to `false` and instead
19+
populate the `podAnnotations` as below:
20+
21+
```yaml
22+
podAnnotations:
23+
prometheus.io/scrape: "true"
24+
prometheus.io/port: "metrics"
25+
prometheus.io/path: "/metrics"
26+
```
27+
28+
## Configuration
29+
30+
See Customizing the Chart Before Installing. To see all configurable options with detailed comments, visit the chart's values.yaml, or run the configuration command:
31+
32+
```sh
33+
$ helm show values kubedb/kubedb
34+
```
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
2+
---
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
controller-gen.kubebuilder.io/version: v0.2.5
8+
creationTimestamp: null
9+
name: mongodbdatabases.infra.doodle.com
10+
spec:
11+
group: infra.doodle.com
12+
names:
13+
kind: MongoDBDatabase
14+
listKind: MongoDBDatabaseList
15+
plural: mongodbdatabases
16+
singular: mongodbdatabase
17+
scope: Namespaced
18+
subresources:
19+
status: {}
20+
validation:
21+
openAPIV3Schema:
22+
description: MongoDBDatabase is the Schema for the mongodbs API
23+
properties:
24+
apiVersion:
25+
description: 'APIVersion defines the versioned schema of this representation
26+
of an object. Servers should convert recognized schemas to the latest
27+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
28+
type: string
29+
kind:
30+
description: 'Kind is a string value representing the REST resource this
31+
object represents. Servers may infer this from the endpoint the client
32+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
33+
type: string
34+
metadata:
35+
type: object
36+
spec:
37+
description: 'MongoDBDatabaseSpec defines the desired state of MongoDBDatabase
38+
IMPORTANT: Run "make" to regenerate code after modifying this file'
39+
properties:
40+
credentials:
41+
items:
42+
properties:
43+
username:
44+
type: string
45+
vault:
46+
properties:
47+
host:
48+
type: string
49+
path:
50+
type: string
51+
secretField:
52+
type: string
53+
useAvailable:
54+
type: boolean
55+
userField:
56+
type: string
57+
required:
58+
- host
59+
- path
60+
- secretField
61+
- useAvailable
62+
- userField
63+
type: object
64+
required:
65+
- username
66+
- vault
67+
type: object
68+
type: array
69+
databaseName:
70+
type: string
71+
hostName:
72+
type: string
73+
rootAuthDatabase:
74+
type: string
75+
rootSecretLookup:
76+
properties:
77+
field:
78+
type: string
79+
name:
80+
type: string
81+
namespace:
82+
type: string
83+
required:
84+
- field
85+
- name
86+
- namespace
87+
type: object
88+
rootUsername:
89+
type: string
90+
required:
91+
- credentials
92+
- databaseName
93+
- hostName
94+
- rootSecretLookup
95+
type: object
96+
status:
97+
description: 'MongoDBDatabaseStatus defines the observed state of MongoDBDatabase
98+
IMPORTANT: Run "make" to regenerate code after modifying this file'
99+
properties:
100+
credentials:
101+
items:
102+
properties:
103+
message:
104+
type: string
105+
status:
106+
type: string
107+
username:
108+
type: string
109+
required:
110+
- message
111+
- status
112+
- username
113+
type: object
114+
type: array
115+
database:
116+
properties:
117+
host:
118+
type: string
119+
message:
120+
type: string
121+
name:
122+
type: string
123+
rootAuthDatabase:
124+
type: string
125+
rootSecretLookup:
126+
properties:
127+
field:
128+
type: string
129+
name:
130+
type: string
131+
namespace:
132+
type: string
133+
required:
134+
- field
135+
- name
136+
- namespace
137+
type: object
138+
rootUsername:
139+
type: string
140+
status:
141+
type: string
142+
required:
143+
- host
144+
- message
145+
- name
146+
- rootAuthDatabase
147+
- rootSecretLookup
148+
- rootUsername
149+
- status
150+
type: object
151+
lastUpdateTime:
152+
format: date-time
153+
type: string
154+
required:
155+
- credentials
156+
- database
157+
- lastUpdateTime
158+
type: object
159+
type: object
160+
version: v1beta1
161+
versions:
162+
- name: v1beta1
163+
served: true
164+
storage: true
165+
status:
166+
acceptedNames:
167+
kind: ""
168+
plural: ""
169+
conditions: []
170+
storedVersions: []

0 commit comments

Comments
 (0)