Skip to content

Commit

Permalink
Draft create
Browse files Browse the repository at this point in the history
  • Loading branch information
pomodroizer committed Jul 20, 2020
1 parent b01ca70 commit 502d5f8
Show file tree
Hide file tree
Showing 30 changed files with 787 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
draft.toml
charts/
NOTICE
LICENSE
README.md
27 changes: 27 additions & 0 deletions .helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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
*.png

# known compile time folders
target/
node_modules/
vendor/
78 changes: 78 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
pipeline {
agent {
label "jenkins-python"
}
environment {
ORG = 'mmontalvo'
APP_NAME = 'rest-django-payments'
CHARTMUSEUM_CREDS = credentials('jenkins-x-chartmuseum')
DOCKER_REGISTRY_ORG = 'strong-land-280923'
}
stages {
stage('CI Build and push snapshot') {
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 {
container('python') {
sh "python -m unittest"
sh "export VERSION=$PREVIEW_VERSION && skaffold build -f skaffold.yaml"
sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$PREVIEW_VERSION"
dir('./charts/preview') {
sh "make preview"
sh "jx preview --app $APP_NAME --dir ../.."
}
}
}
}
stage('Build Release') {
when {
branch 'master'
}
steps {
container('python') {

// ensure we're not on a detached head
sh "git checkout master"
sh "git config --global credential.helper store"
sh "jx step git credentials"

// so we can retrieve the version in later steps
sh "echo \$(jx-release-version) > VERSION"
sh "jx step tag --version \$(cat VERSION)"
sh "python -m unittest"
sh "export VERSION=`cat VERSION` && skaffold build -f skaffold.yaml"
sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:\$(cat VERSION)"
}
}
}
stage('Promote to Environments') {
when {
branch 'master'
}
steps {
container('python') {
dir('./charts/rest-django-payments') {
sh "jx step changelog --version v\$(cat ../../VERSION)"

// release the helm chart
sh "jx step helm release"

// promote through all 'Auto' promotion Environments
sh "jx promote -b --all-auto --timeout 1h --version \$(cat ../../VERSION)"
}
}
}
}
}
post {
always {
cleanWs()
}
}
}
4 changes: 4 additions & 0 deletions OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
approvers:
- mmontalvo
reviewers:
- mmontalvo
6 changes: 6 additions & 0 deletions OWNERS_ALIASES
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
aliases:
- mmontalvo
best-approvers:
- mmontalvo
best-reviewers:
- mmontalvo
Empty file added __init__.py
Empty file.
Binary file added __pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added __pycache__/settings.cpython-38.pyc
Binary file not shown.
Binary file added __pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file added __pycache__/wsgi.cpython-38.pyc
Binary file not shown.
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/python.png
name: preview
version: 0.1.0-SNAPSHOT
18 changes: 18 additions & 0 deletions charts/preview/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
OS := $(shell uname)

preview:
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: $(DOCKER_REGISTRY)\/strong-land-280923\/rest-django-payments|" 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
jx step helm build
16 changes: 16 additions & 0 deletions charts/preview/requirements.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# !! File must end with empty line !!
dependencies:
- alias: expose
name: exposecontroller
repository: http://chartmuseum.jenkins-x.io
version: 2.3.92
- alias: cleanup
name: exposecontroller
repository: http://chartmuseum.jenkins-x.io
version: 2.3.92

# !! "alias: preview" must be last entry in dependencies array !!
# !! Place custom dependencies above !!
- alias: preview
name: rest-django-payments
repository: file://../rest-django-payments
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
21 changes: 21 additions & 0 deletions charts/rest-django-payments/.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
4 changes: 4 additions & 0 deletions charts/rest-django-payments/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
description: A Helm chart for Kubernetes
name: rest-django-payments
version: v0.1.0
48 changes: 48 additions & 0 deletions charts/rest-django-payments/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 := rest-django-payments
OS := $(shell uname)
RELEASE_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: $(RELEASE_VERSION)/" Chart.yaml
sed -i "" -e "s/tag:.*/tag: $(RELEASE_VERSION)/" values.yaml
else ifeq ($(OS),Linux)
sed -i -e "s/version:.*/version: $(RELEASE_VERSION)/" Chart.yaml
sed -i -e "s|repository:.*|repository: $(DOCKER_REGISTRY)\/strong-land-280923\/rest-django-payments|" values.yaml
sed -i -e "s/tag:.*/tag: $(RELEASE_VERSION)/" values.yaml
else
echo "platfrom $(OS) not supported to release from"
exit -1
endif
git add --all
git commit -m "release $(RELEASE_VERSION)" --allow-empty # if first release then no verion update is performed
git tag -fa v$(RELEASE_VERSION) -m "Release version $(RELEASE_VERSION)"
git push origin v$(RELEASE_VERSION)
15 changes: 15 additions & 0 deletions charts/rest-django-payments/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

{{- if contains "NodePort" .Values.service.type }}
Get the application URL by running these commands:
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT/login
{{- else if contains "LoadBalancer" .Values.service.type }}
Get the application URL by running these commands:
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get svc -w {{ template "fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.service.externalPort }}
{{- else }}
http://{{ .Release.Name }}.{{ .Values.basedomain }} to access your application
{{- end }}
16 changes: 16 additions & 0 deletions charts/rest-django-payments/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 -}}
85 changes: 85 additions & 0 deletions charts/rest-django-payments/templates/canary.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{{- if .Values.canary.enabled }}
apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
name: {{ template "fullname" . }}
labels:
draft: {{ default "draft-app" .Values.draft }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
provider: istio
targetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ template "fullname" . }}
progressDeadlineSeconds: {{ .Values.canary.progressDeadlineSeconds }}
{{- if .Values.hpa.enabled }}
autoscalerRef:
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
name: {{ template "fullname" . }}
{{- end }}
service:
port: {{ .Values.service.externalPort }}
targetPort: {{ .Values.service.internalPort }}
gateways:
- {{ template "fullname" . }}
hosts:
- {{ .Values.canary.host }}
analysis:
interval: {{ .Values.canary.canaryAnalysis.interval }}
threshold: {{ .Values.canary.canaryAnalysis.threshold }}
maxWeight: {{ .Values.canary.canaryAnalysis.maxWeight }}
stepWeight: {{ .Values.canary.canaryAnalysis.stepWeight }}
metrics:
- name: request-success-rate
threshold: {{ .Values.canary.canaryAnalysis.metrics.requestSuccessRate.threshold }}
interval: {{ .Values.canary.canaryAnalysis.metrics.requestSuccessRate.interval }}
- name: latency
templateRef:
name: latency
thresholdRange:
max: {{ .Values.canary.canaryAnalysis.metrics.requestDuration.threshold }}
interval: {{ .Values.canary.canaryAnalysis.metrics.requestDuration.interval }}

---

apiVersion: flagger.app/v1beta1
kind: MetricTemplate
metadata:
name: latency
spec:
provider:
type: prometheus
address: http://prometheus.istio-system:9090
query: |
histogram_quantile(
0.99,
sum(
rate(
istio_request_duration_milliseconds_bucket{
reporter="destination",
destination_workload_namespace="{{ "{{" }} namespace {{ "}}" }}",
destination_workload=~"{{ "{{" }} target {{ "}}" }}"
}[{{ "{{" }} interval {{ "}}" }}]
)
) by (le)
)
---

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: {{ template "fullname" . }}
spec:
selector:
istio: ingressgateway
servers:
- port:
number: {{ .Values.service.externalPort }}
name: http
protocol: HTTP
hosts:
- {{ .Values.canary.host }}
{{- end }}
Loading

0 comments on commit 502d5f8

Please sign in to comment.