From d7174ab53bb0f4823f903f050389559888763efe Mon Sep 17 00:00:00 2001 From: wileyj Date: Mon, 12 Nov 2018 15:03:34 -0500 Subject: [PATCH] Draft create --- .helmignore | 27 ++++++ Jenkinsfile | 90 +++++++++++++++++++ OWNERS | 4 + OWNERS_ALIASES | 6 ++ charts/blockstack-core/.helmignore | 21 +++++ charts/blockstack-core/Chart.yaml | 4 + charts/blockstack-core/Makefile | 48 ++++++++++ charts/blockstack-core/templates/NOTES.txt | 15 ++++ charts/blockstack-core/templates/_helpers.tpl | 16 ++++ .../blockstack-core/templates/deployment.yaml | 27 ++++++ charts/blockstack-core/templates/ingress.yaml | 17 ++++ charts/blockstack-core/templates/service.yaml | 23 +++++ charts/blockstack-core/values.yaml | 25 ++++++ charts/preview/Chart.yaml | 5 ++ charts/preview/Makefile | 18 ++++ charts/preview/requirements.yaml | 13 +++ charts/preview/values.yaml | 22 +++++ detect | 10 +++ skaffold.yaml | 31 +++++++ 19 files changed, 422 insertions(+) create mode 100644 .helmignore create mode 100644 Jenkinsfile create mode 100644 OWNERS create mode 100644 OWNERS_ALIASES create mode 100755 charts/blockstack-core/.helmignore create mode 100644 charts/blockstack-core/Chart.yaml create mode 100755 charts/blockstack-core/Makefile create mode 100755 charts/blockstack-core/templates/NOTES.txt create mode 100755 charts/blockstack-core/templates/_helpers.tpl create mode 100755 charts/blockstack-core/templates/deployment.yaml create mode 100755 charts/blockstack-core/templates/ingress.yaml create mode 100755 charts/blockstack-core/templates/service.yaml create mode 100755 charts/blockstack-core/values.yaml create mode 100644 charts/preview/Chart.yaml create mode 100755 charts/preview/Makefile create mode 100755 charts/preview/requirements.yaml create mode 100755 charts/preview/values.yaml create mode 100644 detect create mode 100644 skaffold.yaml diff --git a/.helmignore b/.helmignore new file mode 100644 index 0000000000..747e6e94a3 --- /dev/null +++ b/.helmignore @@ -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/ \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000000..10635cbc9e --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,90 @@ +pipeline { + agent { + label "jenkins-python" + } + environment { + ORG = 'blockstack' + APP_NAME = 'blockstack-core' + CHARTMUSEUM_CREDS = credentials('jenkins-x-chartmuseum') + } + 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') { + container('python') { + 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" + } + dir ('./charts/blockstack-core') { + container('python') { + sh "make tag" + } + } + container('python') { + 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 { + dir ('./charts/blockstack-core') { + container('python') { + 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() + } + } + } diff --git a/OWNERS b/OWNERS new file mode 100644 index 0000000000..a53ff49854 --- /dev/null +++ b/OWNERS @@ -0,0 +1,4 @@ +approvers: +- wileyj +reviewers: +- wileyj diff --git a/OWNERS_ALIASES b/OWNERS_ALIASES new file mode 100644 index 0000000000..64878ec1bd --- /dev/null +++ b/OWNERS_ALIASES @@ -0,0 +1,6 @@ +aliases: +- wileyj +best-approvers: +- wileyj +best-reviewers: +- wileyj diff --git a/charts/blockstack-core/.helmignore b/charts/blockstack-core/.helmignore new file mode 100755 index 0000000000..f0c1319444 --- /dev/null +++ b/charts/blockstack-core/.helmignore @@ -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 diff --git a/charts/blockstack-core/Chart.yaml b/charts/blockstack-core/Chart.yaml new file mode 100644 index 0000000000..d0953d37eb --- /dev/null +++ b/charts/blockstack-core/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: A Helm chart for Kubernetes +name: blockstack-core +version: v0.1.0 diff --git a/charts/blockstack-core/Makefile b/charts/blockstack-core/Makefile new file mode 100755 index 0000000000..61e3a36b38 --- /dev/null +++ b/charts/blockstack-core/Makefile @@ -0,0 +1,48 @@ +CHART_REPO := http://jenkins-x-chartmuseum:8080 +CURRENT=$(pwd) +NAME := blockstack-core +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)\/blockstack\/blockstack-core|" 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) diff --git a/charts/blockstack-core/templates/NOTES.txt b/charts/blockstack-core/templates/NOTES.txt new file mode 100755 index 0000000000..da948fa278 --- /dev/null +++ b/charts/blockstack-core/templates/NOTES.txt @@ -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 }} diff --git a/charts/blockstack-core/templates/_helpers.tpl b/charts/blockstack-core/templates/_helpers.tpl new file mode 100755 index 0000000000..f0d83d2edb --- /dev/null +++ b/charts/blockstack-core/templates/_helpers.tpl @@ -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 -}} diff --git a/charts/blockstack-core/templates/deployment.yaml b/charts/blockstack-core/templates/deployment.yaml new file mode 100755 index 0000000000..149520a1a6 --- /dev/null +++ b/charts/blockstack-core/templates/deployment.yaml @@ -0,0 +1,27 @@ +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" . }} +{{- if .Values.podAnnotations }} + annotations: +{{ toYaml .Values.podAnnotations | indent 8 }} +{{- end }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - containerPort: {{ .Values.service.internalPort }} + resources: +{{ toYaml .Values.resources | indent 12 }} diff --git a/charts/blockstack-core/templates/ingress.yaml b/charts/blockstack-core/templates/ingress.yaml new file mode 100755 index 0000000000..974e6f66af --- /dev/null +++ b/charts/blockstack-core/templates/ingress.yaml @@ -0,0 +1,17 @@ +{{- if .Values.ingress.enabled -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ template "fullname" . }} + labels: + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +spec: + rules: + - host: {{ .Release.Name }}.{{ .Values.basedomain }} + http: + paths: + - path: / + backend: + serviceName: {{ template "fullname" . }} + servicePort: {{ .Values.service.externalPort }} +{{- end -}} diff --git a/charts/blockstack-core/templates/service.yaml b/charts/blockstack-core/templates/service.yaml new file mode 100755 index 0000000000..8d27389483 --- /dev/null +++ b/charts/blockstack-core/templates/service.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +kind: Service +metadata: +{{- if .Values.service.name }} + name: {{ .Values.service.name }} +{{- else }} + name: {{ template "fullname" . }} +{{- end }} + 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: http + selector: + app: {{ template "fullname" . }} diff --git a/charts/blockstack-core/values.yaml b/charts/blockstack-core/values.yaml new file mode 100755 index 0000000000..926bbb8162 --- /dev/null +++ b/charts/blockstack-core/values.yaml @@ -0,0 +1,25 @@ +# Default values for python. +# 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: blockstack-core + type: ClusterIP + externalPort: 80 + internalPort: 8080 + annotations: + fabric8.io/expose: "true" + fabric8.io/ingress.annotations: "kubernetes.io/ingress.class: nginx" +resources: + limits: + cpu: 100m + memory: 128Mi + requests: + cpu: 100m + memory: 128Mi +ingress: + enabled: false diff --git a/charts/preview/Chart.yaml b/charts/preview/Chart.yaml new file mode 100644 index 0000000000..35e5bd86ab --- /dev/null +++ b/charts/preview/Chart.yaml @@ -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 diff --git a/charts/preview/Makefile b/charts/preview/Makefile new file mode 100755 index 0000000000..ebf47d2267 --- /dev/null +++ b/charts/preview/Makefile @@ -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)\/blockstack\/blockstack-core|" 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 diff --git a/charts/preview/requirements.yaml b/charts/preview/requirements.yaml new file mode 100755 index 0000000000..a2542d5872 --- /dev/null +++ b/charts/preview/requirements.yaml @@ -0,0 +1,13 @@ + +dependencies: +- alias: expose + name: exposecontroller + repository: https://chartmuseum.build.cd.jenkins-x.io + version: 2.3.56 +- alias: cleanup + name: exposecontroller + repository: https://chartmuseum.build.cd.jenkins-x.io + version: 2.3.56 +- alias: preview + name: blockstack-core + repository: file://../blockstack-core diff --git a/charts/preview/values.yaml b/charts/preview/values.yaml new file mode 100755 index 0000000000..b53ceaa574 --- /dev/null +++ b/charts/preview/values.yaml @@ -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 \ No newline at end of file diff --git a/detect b/detect new file mode 100644 index 0000000000..129443d516 --- /dev/null +++ b/detect @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +BUILD_DIR=$1 + +# Exit early if app is clearly not Python. +if [ ! -f $BUILD_DIR/requirements.txt ] && [ ! -f $BUILD_DIR/setup.py ] && [ ! -f $BUILD_DIR/Pipfile ]; then + exit 1 +fi + +echo Python diff --git a/skaffold.yaml b/skaffold.yaml new file mode 100644 index 0000000000..03ecb15b90 --- /dev/null +++ b/skaffold.yaml @@ -0,0 +1,31 @@ +apiVersion: skaffold/v1alpha2 +kind: Config +build: + tagPolicy: + envTemplate: + template: "{{.DOCKER_REGISTRY}}/blockstack/blockstack-core:{{.VERSION}}" + artifacts: + - imageName: changeme + workspace: . + docker: {} + local: {} +deploy: + kubectl: + manifests: +profiles: +- name: dev + build: + tagPolicy: + envTemplate: + template: "{{.DOCKER_REGISTRY}}/blockstack/blockstack-core:{{.DIGEST_HEX}}" + artifacts: + - docker: {} + local: {} + deploy: + helm: + releases: + - name: blockstack-core + chartPath: charts/blockstack-core + setValueTemplates: + image.repository: "{{.DOCKER_REGISTRY}}/blockstack/blockstack-core" + image.tag: "{{.DIGEST_HEX}}"