Skip to content

Commit

Permalink
Merge pull request #32 from stakater/remove-hardcoding
Browse files Browse the repository at this point in the history
[STK-158] Remove hardcoding
  • Loading branch information
hazim1093 authored Apr 2, 2018
2 parents 3356023 + d272529 commit dae65f9
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 142 deletions.
169 changes: 84 additions & 85 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,127 +1,126 @@
#!/usr/bin/groovy
@Library('github.com/stakater/fabric8-pipeline-library@fix-branch')
@Library('github.com/stakater/fabric8-pipeline-library@master')

def utils = new io.fabric8.Utils()

String chartPackageName = ""
String chartName = "chart/ingress-monitor-controller"

toolsNode(toolsImage: 'stakater/pipeline-tools:1.5.1') {
container(name: 'tools') {
withCurrentRepo { def repoUrl, def repoName, def repoOwner, def repoBranch ->
String srcDir = WORKSPACE + "/src"
def chartTemplatesDir = WORKSPACE + "/kubernetes/templates/chart"
// TODO: fetch repo name dynamically
def chartDir = WORKSPACE + "/kubernetes/chart/ingress-monitor-controller"
def kubernetesDir = WORKSPACE + "/kubernetes"

def chartTemplatesDir = kubernetesDir + "/templates/chart"
def chartDir = kubernetesDir + "/chart"
def manifestsDir = kubernetesDir + "/manifests"
// TODO: fetch repo name dynamically
def dockerImage = "stakater/ingress-monitor-controller";

def dockerImage = repoOwner.toLowerCase() + "/" + repoName.toLowerCase()
def dockerImageVersion = ""

// Slack variables
def slackChannel = "${env.SLACK_CHANNEL}"
def slackWebHookURL = "${env.SLACK_WEBHOOK_URL}"

def git = new io.stakater.vc.Git()
def helm = new io.stakater.charts.Helm()
def common = new io.stakater.Common()
def chartManager = new io.stakater.charts.ChartManager()

stage('Download Dependencies') {
sh """
cd ${srcDir}
glide update
cp -r ./vendor/* /go/src/
"""
}

if (utils.isCI()) {
stage('CI: Test') {
def docker = new io.stakater.containers.Docker()
def stakaterCommands = new io.stakater.StakaterCommands()
def slack = new io.stakater.notifications.Slack()
try {
stage('Download Dependencies') {
sh """
cd ${srcDir}
go test
glide update
cp -r ./vendor/* /go/src/
"""
}
stage('CI: Publish Dev Image') {

stage('Run Tests') {
sh """
cd ${srcDir}
go build -o ../out/ingressmonitorcontroller
cd ..
docker build -t docker.io/${dockerImage}:dev .
docker push docker.io/${dockerImage}:dev
go test
"""
}
} else if (utils.isCD()) {
stage('CD: Build') {

stage('Build Binary') {
sh """
cd ${srcDir}
go test
go build -o ../out/ingressmonitorcontroller
go build -o ..out/${repoName.toLowerCase()}
"""
}

stage('CD: Tag and Push') {
print "Generating New Version"
sh """
cd ${WORKSPACE}
VERSION=\$(jx-release-version --gh-owner=${repoOwner} --gh-repository=${repoName})
echo "VERSION := \${VERSION}" > Makefile
"""
if (utils.isCI()) {
stage('CI: Publish Dev Image') {
dockerImageVersion = stakaterCommands.getBranchedVersion("${env.BUILD_NUMBER}")
docker.buildImageWithTag(dockerImage, dockerImageVersion)
docker.pushTag(dockerImage, dockerImageVersion)
}
} else if (utils.isCD()) {
stage('CD: Tag and Push') {
print "Generating New Version"
def version = common.shOutput("jx-release-version --gh-owner=${repoOwner} --gh-repository=${repoName}")
dockerImageVersion = version
sh """
echo "VERSION := ${version}" > Makefile
"""

sh """
export VERSION=${version}
export DOCKER_IMAGE=${dockerImage}
gotplenv ${chartTemplatesDir}/Chart.yaml.tmpl > ${chartDir}/${repoName}/Chart.yaml
gotplenv ${chartTemplatesDir}/values.yaml.tmpl > ${chartDir}/${repoName}/values.yaml
def version = new io.stakater.Common().shOutput """
cd ${WORKSPACE}
helm template ${chartDir}/${repoName} -x templates/deployment.yaml > ${manifestsDir}/deployment.yaml
helm template ${chartDir}/${repoName} -x templates/configmap.yaml > ${manifestsDir}/configmap.yaml
helm template ${chartDir}/${repoName} -x templates/rbac.yaml > ${manifestsDir}/rbac.yaml
"""

chmod 600 /root/.ssh-git/ssh-key > /dev/null
eval `ssh-agent -s` > /dev/null
ssh-add /root/.ssh-git/ssh-key > /dev/null
git.commitChanges(WORKSPACE, "Bump Version to ${version}")

jx-release-version --gh-owner=${repoOwner} --gh-repository=${repoName}
"""
print "Pushing Tag ${version} to Git"
git.createTagAndPush(WORKSPACE, version)
git.createRelease(version)

sh """
export VERSION=${version}
export DOCKER_IMAGE=${dockerImage}
gotplenv ${chartTemplatesDir}/Chart.yaml.tmpl > ${chartDir}/Chart.yaml
gotplenv ${chartTemplatesDir}/values.yaml.tmpl > ${chartDir}/values.yaml
helm template ${chartDir} -x templates/deployment.yaml > ${manifestsDir}/deployment.yaml
helm template ${chartDir} -x templates/configmap.yaml > ${manifestsDir}/configmap.yaml
helm template ${chartDir} -x templates/rbac.yaml > ${manifestsDir}/rbac.yaml
"""
print "Pushing Tag ${version} to DockerHub"
docker.buildImageWithTag(dockerImage, "latest")
docker.tagImage(dockerImage, "latest", version)
docker.pushTag(dockerImage, version)
docker.pushTag(dockerImage, "latest")
}

git.commitChanges(WORKSPACE, "Bump Version to ${version}")
stage('Chart: Init Helm') {
helm.init(true)
}

print "Pushing Tag ${version} to Git"
sh """
cd ${WORKSPACE}
chmod 600 /root/.ssh-git/ssh-key
eval `ssh-agent -s`
ssh-add /root/.ssh-git/ssh-key
git tag ${version}
git push --tags
"""
stage('Chart: Prepare') {
helm.lint(chartDir, repoName)
chartPackageName = helm.package(chartDir, repoName)
}

print "Pushing Tag ${version} to DockerHub"
sh """
cd ${WORKSPACE}
docker build -t docker.io/${dockerImage}:${version} .
docker tag docker.io/${dockerImage}:${version} docker.io/${dockerImage}:latest
docker push docker.io/${dockerImage}:${version}
docker push docker.io/${dockerImage}:latest
"""
}

stage('Chart: Init Helm') {
helm.init(true)
stage('Chart: Upload') {
String cmUsername = common.getEnvValue('CHARTMUSEUM_USERNAME')
String cmPassword = common.getEnvValue('CHARTMUSEUM_PASSWORD')
chartManager.uploadToChartMuseum(chartDir, repoName, chartPackageName, cmUsername, cmPassword)
}
}
}
catch(e) {
slack.sendDefaultFailureNotification(slackWebHookURL, slackChannel, [slack.createErrorField(e)])

def commentMessage = "Yikes! You better fix it before anyone else finds out! [Build ${env.BUILD_NUMBER}](${env.BUILD_URL}) has Failed!"
git.addCommentToPullRequest(commentMessage)

stage('Chart: Prepare') {
helm.lint(kubernetesDir, chartName)
chartPackageName = helm.package(kubernetesDir, chartName)
}
throw e
}
stage('Notify') {
def dockerImageWithTag = "${dockerImage}:${dockerImageVersion}"
slack.sendDefaultSuccessNotification(slackWebHookURL, slackChannel, [slack.createDockerImageField(dockerImageWithTag)])

stage('Chart: Upload') {
String cmUsername = common.getEnvValue('CHARTMUSEUM_USERNAME')
String cmPassword = common.getEnvValue('CHARTMUSEUM_PASSWORD')
chartManager.uploadToChartMuseum(kubernetesDir, chartName, chartPackageName, cmUsername, cmPassword)
}
def commentMessage = "Image is available for testing. `docker pull ${dockerImageWithTag}`"
git.addCommentToPullRequest(commentMessage)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION := 0.2.13
VERSION := 0.2.21
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

13 changes: 13 additions & 0 deletions kubernetes/chart/IngressMonitorController/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated from /kubernetes/templates/chart/Chart.yaml.tmpl

apiVersion: v1
name: IngressMonitorController
description: IngressMonitorController chart that runs on kubernetes
version: 0.2.21
keywords:
- IngressMonitorController
- kubernetes
home: https://github.com/stakater/IngressMonitorController
maintainers:
- name: Stakater
email: [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
annotations:
fabric8.io/target-platform: kubernetes
labels:
app: {{ template "fullname" . }}
app: {{ template "name" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: {{ .Release.Name | quote }}
heritage: {{ .Release.Service | quote }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
annotations:
configmap.fabric8.io/update-on-change: {{ template "name" . }}
labels:
app: {{ template "fullname" . }}
app: {{ template "name" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: {{ .Release.Name | quote }}
heritage: {{ .Release.Service | quote }}
Expand All @@ -18,7 +18,7 @@ spec:
annotations:
configmap.fabric8.io/update-on-change: {{ template "name" . }}
labels:
app: {{ template "fullname" . }}
app: {{ template "name" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: {{ .Release.Name | quote }}
heritage: {{ .Release.Service | quote }}
Expand All @@ -36,7 +36,7 @@ spec:
imagePullPolicy: {{ .Values.ingressMonitorController.image.pullPolicy }}
name: {{ template "name" . }}
volumeMounts:
- mountPath: /etc/ingress-monitor-controller
- mountPath: /etc/IngressMonitorController
name: config-volume
serviceAccountName: {{ template "name" . }}
volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
kind: ServiceAccount
metadata:
labels:
app: {{ template "fullname" . }}
app: {{ template "name" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: {{ .Release.Name | quote }}
heritage: {{ .Release.Service | quote }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ kubernetes:
ingressMonitorController:
namespace: default
image:
name: stakater/ingress-monitor-controller
tag: "0.2.13"
name: stakater/ingressmonitorcontroller
tag: "0.2.21"
pullPolicy: IfNotPresent
providers:
- name: UptimeRobot
Expand All @@ -16,5 +16,5 @@ ingressMonitorController:
alertContacts: some-alert-contacts

enableMonitorDeletion: true
configFilePath: /etc/ingress-monitor-controller/config.yaml
configFilePath: /etc/IngressMonitorController/config.yaml
monitorNameTemplate: "{{.Namespace}}-{{.IngressName}}"
13 changes: 0 additions & 13 deletions kubernetes/chart/ingress-monitor-controller/Chart.yaml

This file was deleted.

10 changes: 5 additions & 5 deletions kubernetes/manifests/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
---
# Source: ingress-monitor-controller/templates/configmap.yaml
# Source: IngressMonitorController/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
annotations:
fabric8.io/target-platform: kubernetes
labels:
app: RELEASE-NAME-ingress-monitor-controller
chart: "ingress-monitor-controller-0.2.13"
app: IngressMonitorController
chart: "IngressMonitorController-0.2.21"
release: "RELEASE-NAME"
heritage: "Tiller"
project: ingress-monitor-controller
name: ingress-monitor-controller
project: IngressMonitorController
name: IngressMonitorController
data:
config.yaml: |-
providers:
Expand Down
32 changes: 16 additions & 16 deletions kubernetes/manifests/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
---
# Source: ingress-monitor-controller/templates/deployment.yaml
# Source: IngressMonitorController/templates/deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
configmap.fabric8.io/update-on-change: ingress-monitor-controller
configmap.fabric8.io/update-on-change: IngressMonitorController
labels:
app: RELEASE-NAME-ingress-monitor-controller
chart: "ingress-monitor-controller-0.2.13"
app: IngressMonitorController
chart: "IngressMonitorController-0.2.21"
release: "RELEASE-NAME"
heritage: "Tiller"
project: ingress-monitor-controller
name: ingress-monitor-controller
project: IngressMonitorController
name: IngressMonitorController
spec:
replicas: 1
revisionHistoryLimit: 2
template:
metadata:
annotations:
configmap.fabric8.io/update-on-change: ingress-monitor-controller
configmap.fabric8.io/update-on-change: IngressMonitorController
labels:
app: RELEASE-NAME-ingress-monitor-controller
chart: "ingress-monitor-controller-0.2.13"
app: IngressMonitorController
chart: "IngressMonitorController-0.2.21"
release: "RELEASE-NAME"
heritage: "Tiller"
project: ingress-monitor-controller
project: IngressMonitorController
spec:
containers:
- env:
Expand All @@ -33,15 +33,15 @@ spec:
fieldRef:
fieldPath: metadata.namespace
- name: CONFIG_FILE_PATH
value: /etc/ingress-monitor-controller/config.yaml
image: "stakater/ingress-monitor-controller:0.2.13"
value: /etc/IngressMonitorController/config.yaml
image: "stakater/ingressmonitorcontroller:0.2.21"
imagePullPolicy: IfNotPresent
name: ingress-monitor-controller
name: IngressMonitorController
volumeMounts:
- mountPath: /etc/ingress-monitor-controller
- mountPath: /etc/IngressMonitorController
name: config-volume
serviceAccountName: ingress-monitor-controller
serviceAccountName: IngressMonitorController
volumes:
- configMap:
name: ingress-monitor-controller
name: IngressMonitorController
name: config-volume
Loading

0 comments on commit dae65f9

Please sign in to comment.