Skip to content

Commit

Permalink
Draft create
Browse files Browse the repository at this point in the history
  • Loading branch information
rawlingsj committed Mar 19, 2018
1 parent 18e449d commit 893abe1
Show file tree
Hide file tree
Showing 18 changed files with 366 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Dockerfile
draft.toml
charts/
NOTICE
LICENSE
README.md
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM scratch
EXPOSE 8080
ENTRYPOINT ["/golang-http-demo"]
COPY ./bin/ /
98 changes: 98 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
pipeline {
agent {
label "jenkins-go"
}
environment {
ORG = 'rawlingsj'
APP_NAME = 'golang-http-demo'
GIT_PROVIDER = 'github.com'
GIT_CREDS = credentials('jenkins-x-git')
CHARTMUSEUM_CREDS = credentials('jenkins-x-chartmuseum')
GIT_USERNAME = "$GIT_CREDS_USR"
GIT_API_TOKEN = "$GIT_CREDS_PSW"
}
stages {
stage('CI Build and push snapshpt') {
when {
branch 'PR-*'
}
environment {
PREVIEW_VERSION = "0.0.0-SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER"
PREVIEW_NAMESPACE = "$APP_NAME-$BRANCH_NAME".toLowerCase()
HELM_RELEASE = "$PREVIEW_NAMESPACE".toLowerCase()
}
steps {

dir ('/home/jenkins/go/src/github.com/rawlingsj/golang-http-demo') {
checkout scm
container('go') {
sh "make preview"

}
}
dir ('/home/jenkins/go/src/github.com/rawlingsj/golang-http-demo/charts/preview') {
container('go') {
sh "make linux"

sh "docker build -t \$JENKINS_X_DOCKER_REGISTRY_SERVICE_HOST:\$JENKINS_X_DOCKER_REGISTRY_SERVICE_PORT/$ORG/$APP_NAME:$PREVIEW_VERSION ."
sh "docker push \$JENKINS_X_DOCKER_REGISTRY_SERVICE_HOST:\$JENKINS_X_DOCKER_REGISTRY_SERVICE_PORT/$ORG/$APP_NAME:$PREVIEW_VERSION"

sh "jx preview --app $APP_NAME --dir ../.."
}
}
}
}
stage('Build Release') {
when {
branch 'master'
}
steps {
container('go') {
dir ('/home/jenkins/go/src/github.com/rawlingsj/golang-http-demo') {
checkout scm
// so we can retrieve the version in later steps
sh "echo \$(jx-release-version) > VERSION"
}
dir ('/home/jenkins/go/src/github.com/rawlingsj/golang-http-demo/charts/golang-http-demo') {
// ensure we're not on a detached head
sh "git checkout master"
// until we switch to the new kubernetes / jenkins credential implementation use git credentials store
sh "git config --global credential.helper store"

sh "make tag"
}
dir ('/home/jenkins/go/src/github.com/rawlingsj/golang-http-demo') {
container('go') {
sh "make build"
sh "docker build -t \$JENKINS_X_DOCKER_REGISTRY_SERVICE_HOST:\$JENKINS_X_DOCKER_REGISTRY_SERVICE_PORT/$ORG/$APP_NAME:\$(cat VERSION) ."
sh "docker push \$JENKINS_X_DOCKER_REGISTRY_SERVICE_HOST:\$JENKINS_X_DOCKER_REGISTRY_SERVICE_PORT/$ORG/$APP_NAME:\$(cat VERSION)"
}
}
}
}
}
stage('Promote to Environments') {
when {
branch 'master'
}
steps {
dir ('/home/jenkins/go/src/github.com/rawlingsj/golang-http-demo/charts/golang-http-demo') {
container('go') {
sh 'jx step changelog --version \$(cat ../../VERSION)'

// release the helm chart
sh 'make release'

// promote through all 'Auto' promotion Environments
sh 'jx promote -b --all-auto --timeout 1h --version \$(cat ../../VERSION)'
}
}
}
}
}
post {
always {
cleanWs()
}
}
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SHELL := /bin/bash
GO := GO15VENDOREXPERIMENT=1 go
NAME := REPLACE_ME_APP_NAME
NAME := golang-http-demo
OS := $(shell uname)
MAIN_GO := hello.go
ROOT_PACKAGE := $(GIT_PROVIDER)/$(ORG)/$(NAME)
Expand Down
9 changes: 9 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License:

Copyright (C) 2011-2015 Heroku, Inc.

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.
21 changes: 21 additions & 0 deletions charts/golang-http-demo/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
5 changes: 5 additions & 0 deletions charts/golang-http-demo/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
description: A Helm chart for Kubernetes
icon: https://raw.githubusercontent.com/jenkins-x/jenkins-x-platform/d273e09/images/go.png
name: golang-http-demo
version: 0.1.0-SNAPSHOT
48 changes: 48 additions & 0 deletions charts/golang-http-demo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
CHART_REPO := http://jenkins-x-chartmuseum:8080
CURRENT=$(pwd)
NAME := golang-http-demo
OS := $(shell uname)
VERSION := $(shell cat ../../VERSION)

build: clean
rm -rf requirements.lock
helm dependency build
helm lint

install: clean build
helm install . --name ${NAME}

upgrade: clean build
helm upgrade ${NAME} .

delete:
helm delete --purge ${NAME}

clean:
rm -rf charts
rm -rf ${NAME}*.tgz

release: clean
helm dependency build
helm lint
helm init --client-only
helm package .
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
rm -rf ${NAME}*.tgz%

tag:
ifeq ($(OS),Darwin)
sed -i "" -e "s/version:.*/version: $(VERSION)/" Chart.yaml
sed -i "" -e "s/tag: .*/tag: $(VERSION)/" values.yaml
else ifeq ($(OS),Linux)
sed -i -e "s/version:.*/version: $(VERSION)/" Chart.yaml
sed -i -e "s/repository: .*/repository: $(JENKINS_X_DOCKER_REGISTRY_SERVICE_HOST):$(JENKINS_X_DOCKER_REGISTRY_SERVICE_PORT)\/$(ORG)\/$(NAME)/" values.yaml
sed -i -e "s/tag: .*/tag: $(VERSION)/" values.yaml
else
echo "platfrom $(OS) not supported to tag with"
exit -1
endif
git add --all
git commit -m "release $(VERSION)" --allow-empty # if first release then no verion update is performed
git tag -fa v$(VERSION) -m "Release version $(VERSION)"
git push origin v$(VERSION)
1 change: 1 addition & 0 deletions charts/golang-http-demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# golang application
4 changes: 4 additions & 0 deletions charts/golang-http-demo/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

Get the application URL by running these commands:

kubectl get ingress {{ template "fullname" . }}
16 changes: 16 additions & 0 deletions charts/golang-http-demo/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
39 changes: 39 additions & 0 deletions charts/golang-http-demo/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "fullname" . }}
labels:
draft: {{ default "draft-app" .Values.draft }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
replicas: {{ .Values.replicaCount }}
template:
metadata:
labels:
draft: {{ default "draft-app" .Values.draft }}
app: {{ template "fullname" . }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: {{ .Values.service.internalPort }}
livenessProbe:
httpGet:
path: {{ .Values.probePath }}
port: {{ .Values.service.internalPort }}
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
successThreshold: {{ .Values.livenessProbe.successThreshold }}
timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
readinessProbe:
httpGet:
path: {{ .Values.probePath }}
port: {{ .Values.service.internalPort }}
periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
successThreshold: {{ .Values.readinessProbe.successThreshold }}
timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
resources:
{{ toYaml .Values.resources | indent 12 }}
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
19 changes: 19 additions & 0 deletions charts/golang-http-demo/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "fullname" . }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
{{- if .Values.service.annotations }}
annotations:
{{ toYaml .Values.service.annotations | indent 4 }}
{{- end }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.externalPort }}
targetPort: {{ .Values.service.internalPort }}
protocol: TCP
name: {{ .Values.service.name }}
selector:
app: {{ template "fullname" . }}
33 changes: 33 additions & 0 deletions charts/golang-http-demo/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Default values for node projects.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image:
repository: draft
tag: dev
pullPolicy: IfNotPresent
service:
name: golang-http-demo
type: ClusterIP
externalPort: 80
internalPort: 8080
annotations:
fabric8.io/expose: "true"
resources:
limits:
cpu: 100m
memory: 256Mi
requests:
cpu: 80m
memory: 128Mi
probePath: /
livenessProbe:
initialDelaySeconds: 60
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
readinessProbe:
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
terminationGracePeriodSeconds: 10
5 changes: 5 additions & 0 deletions charts/preview/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
description: A Helm chart for Kubernetes
icon: https://raw.githubusercontent.com/jenkins-x/jenkins-x-platform/master/images/go.png
name: preview
version: 0.1.0-SNAPSHOT
22 changes: 22 additions & 0 deletions charts/preview/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
OS := $(shell uname)

preview:
helm init --client-only
helm repo add chartmuseum http://jenkins-x-chartmuseum:8080
helm repo add chartmuseum https://chartmuseum.build.cd.jenkins-x.io
ifeq ($(OS),Darwin)
sed -i "" -e "s/version:.*/version: $(PREVIEW_VERSION)/" Chart.yaml
sed -i "" -e "s/version:.*/version: $(PREVIEW_VERSION)/" ../*/Chart.yaml
sed -i "" -e "s/tag: .*/tag: $(PREVIEW_VERSION)/" values.yaml
else ifeq ($(OS),Linux)
sed -i -e "s/version:.*/version: $(PREVIEW_VERSION)/" Chart.yaml
sed -i -e "s/version:.*/version: $(PREVIEW_VERSION)/" ../*/Chart.yaml
sed -i -e "s/repository: .*/repository: $(JENKINS_X_DOCKER_REGISTRY_SERVICE_HOST):$(JENKINS_X_DOCKER_REGISTRY_SERVICE_PORT)\/$(ORG)\/$(APP_NAME)/" values.yaml
sed -i -e "s/tag: .*/tag: $(PREVIEW_VERSION)/" values.yaml
else
echo "platfrom $(OS) not supported to release from"
exit -1
endif
echo " version: $(PREVIEW_VERSION)" >> requirements.yaml
helm dependency build
helm lint
13 changes: 13 additions & 0 deletions charts/preview/requirements.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

dependencies:
- alias: expose
name: exposecontroller
repository: https://chartmuseum.build.cd.jenkins-x.io
version: 2.3.55
- alias: cleanup
name: exposecontroller
repository: https://chartmuseum.build.cd.jenkins-x.io
version: 2.3.55
- alias: preview
name: golang-http-demo
repository: file://../golang-http-demo
22 changes: 22 additions & 0 deletions charts/preview/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

expose:
Annotations:
helm.sh/hook: post-install,post-upgrade
helm.sh/hook-delete-policy: hook-succeeded
config:
exposer: Ingress
http: true
tlsacme: false

cleanup:
Args:
- --cleanup
Annotations:
helm.sh/hook: pre-delete
helm.sh/hook-delete-policy: hook-succeeded

preview:
image:
repository:
tag:
pullPolicy: IfNotPresent

0 comments on commit 893abe1

Please sign in to comment.