From 4e5db9eef2fb97762fa693f160f0921802b60b24 Mon Sep 17 00:00:00 2001 From: Viktor Farcic Date: Sat, 11 May 2019 23:00:37 +0200 Subject: [PATCH] Draft create --- OWNERS | 4 ++ OWNERS_ALIASES | 6 +++ charts/devops-toolkit/.helmignore | 21 ++++++++ charts/devops-toolkit/Chart.yaml | 5 ++ charts/devops-toolkit/Makefile | 48 +++++++++++++++++ charts/devops-toolkit/README.md | 1 + charts/devops-toolkit/templates/NOTES.txt | 4 ++ charts/devops-toolkit/templates/_helpers.tpl | 16 ++++++ .../devops-toolkit/templates/deployment.yaml | 51 +++++++++++++++++++ charts/devops-toolkit/templates/ksvc.yaml | 41 +++++++++++++++ charts/devops-toolkit/templates/service.yaml | 26 ++++++++++ charts/devops-toolkit/values.yaml | 41 +++++++++++++++ charts/preview/Chart.yaml | 5 ++ charts/preview/Makefile | 18 +++++++ charts/preview/requirements.yaml | 16 ++++++ charts/preview/values.yaml | 22 ++++++++ jenkins-x.yml | 1 + skaffold.yaml | 30 +++++++++++ 18 files changed, 356 insertions(+) create mode 100644 OWNERS create mode 100644 OWNERS_ALIASES create mode 100755 charts/devops-toolkit/.helmignore create mode 100644 charts/devops-toolkit/Chart.yaml create mode 100755 charts/devops-toolkit/Makefile create mode 100755 charts/devops-toolkit/README.md create mode 100755 charts/devops-toolkit/templates/NOTES.txt create mode 100755 charts/devops-toolkit/templates/_helpers.tpl create mode 100755 charts/devops-toolkit/templates/deployment.yaml create mode 100755 charts/devops-toolkit/templates/ksvc.yaml create mode 100755 charts/devops-toolkit/templates/service.yaml create mode 100755 charts/devops-toolkit/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 100755 jenkins-x.yml create mode 100644 skaffold.yaml diff --git a/OWNERS b/OWNERS new file mode 100644 index 0000000..11fd3dc --- /dev/null +++ b/OWNERS @@ -0,0 +1,4 @@ +approvers: +- vfarcic +reviewers: +- vfarcic diff --git a/OWNERS_ALIASES b/OWNERS_ALIASES new file mode 100644 index 0000000..c8deecb --- /dev/null +++ b/OWNERS_ALIASES @@ -0,0 +1,6 @@ +aliases: +- vfarcic +best-approvers: +- vfarcic +best-reviewers: +- vfarcic diff --git a/charts/devops-toolkit/.helmignore b/charts/devops-toolkit/.helmignore new file mode 100755 index 0000000..f0c1319 --- /dev/null +++ b/charts/devops-toolkit/.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/devops-toolkit/Chart.yaml b/charts/devops-toolkit/Chart.yaml new file mode 100644 index 0000000..b92d649 --- /dev/null +++ b/charts/devops-toolkit/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +description: A Helm chart for Kubernetes +icon: https://raw.githubusercontent.com/jenkins-x/jenkins-x-platform/d273e09/images/nodejs.png +name: devops-toolkit +version: 0.1.0-SNAPSHOT diff --git a/charts/devops-toolkit/Makefile b/charts/devops-toolkit/Makefile new file mode 100755 index 0000000..b971fd4 --- /dev/null +++ b/charts/devops-toolkit/Makefile @@ -0,0 +1,48 @@ +CHART_REPO := http://jenkins-x-chartmuseum:8080 +CURRENT=$(pwd) +NAME := devops-toolkit +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)\/vfarcic\/devops-toolkit|" 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/devops-toolkit/README.md b/charts/devops-toolkit/README.md new file mode 100755 index 0000000..83de828 --- /dev/null +++ b/charts/devops-toolkit/README.md @@ -0,0 +1 @@ +# Javascript application \ No newline at end of file diff --git a/charts/devops-toolkit/templates/NOTES.txt b/charts/devops-toolkit/templates/NOTES.txt new file mode 100755 index 0000000..97823be --- /dev/null +++ b/charts/devops-toolkit/templates/NOTES.txt @@ -0,0 +1,4 @@ + +Get the application URL by running these commands: + +kubectl get ingress {{ template "fullname" . }} diff --git a/charts/devops-toolkit/templates/_helpers.tpl b/charts/devops-toolkit/templates/_helpers.tpl new file mode 100755 index 0000000..f0d83d2 --- /dev/null +++ b/charts/devops-toolkit/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/devops-toolkit/templates/deployment.yaml b/charts/devops-toolkit/templates/deployment.yaml new file mode 100755 index 0000000..2e833af --- /dev/null +++ b/charts/devops-toolkit/templates/deployment.yaml @@ -0,0 +1,51 @@ +{{- if .Values.knativeDeploy }} +{{- else }} +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 }} + env: +{{- range $pkey, $pval := .Values.env }} + - name: {{ $pkey }} + value: {{ $pval }} +{{- end }} + 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 }} +{{- end }} \ No newline at end of file diff --git a/charts/devops-toolkit/templates/ksvc.yaml b/charts/devops-toolkit/templates/ksvc.yaml new file mode 100755 index 0000000..c2f9e6c --- /dev/null +++ b/charts/devops-toolkit/templates/ksvc.yaml @@ -0,0 +1,41 @@ +{{- if .Values.knativeDeploy }} +apiVersion: serving.knative.dev/v1alpha1 +kind: Service +metadata: +{{- if .Values.service.name }} + name: {{ .Values.service.name }} +{{- else }} + name: {{ template "fullname" . }} +{{- end }} + labels: + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +spec: + runLatest: + configuration: + revisionTemplate: + spec: + container: + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: +{{- range $pkey, $pval := .Values.env }} + - name: {{ $pkey }} + value: {{ $pval }} +{{- end }} + livenessProbe: + httpGet: + path: {{ .Values.probePath }} + initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.livenessProbe.periodSeconds }} + successThreshold: {{ .Values.livenessProbe.successThreshold }} + timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} + readinessProbe: + httpGet: + path: {{ .Values.probePath }} + periodSeconds: {{ .Values.readinessProbe.periodSeconds }} + successThreshold: {{ .Values.readinessProbe.successThreshold }} + timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} + terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} + resources: +{{ toYaml .Values.resources | indent 12 }} +{{- end }} diff --git a/charts/devops-toolkit/templates/service.yaml b/charts/devops-toolkit/templates/service.yaml new file mode 100755 index 0000000..9321361 --- /dev/null +++ b/charts/devops-toolkit/templates/service.yaml @@ -0,0 +1,26 @@ +{{- if .Values.knativeDeploy }} +{{- else }} +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" . }} +{{- end }} diff --git a/charts/devops-toolkit/values.yaml b/charts/devops-toolkit/values.yaml new file mode 100755 index 0000000..772df16 --- /dev/null +++ b/charts/devops-toolkit/values.yaml @@ -0,0 +1,41 @@ +# 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 + +# define environment variables here as a map of key: value +env: + +# enable this flag to use knative serve to deploy the app +knativeDeploy: false + +service: + name: devops-toolkit + type: ClusterIP + externalPort: 80 + internalPort: 8080 + annotations: + fabric8.io/expose: "true" + fabric8.io/ingress.annotations: "kubernetes.io/ingress.class: nginx" +resources: + limits: + cpu: 400m + memory: 256Mi + requests: + cpu: 200m + memory: 128Mi +probePath: / +livenessProbe: + initialDelaySeconds: 60 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 +readinessProbe: + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 +terminationGracePeriodSeconds: 10 diff --git a/charts/preview/Chart.yaml b/charts/preview/Chart.yaml new file mode 100644 index 0000000..6b68431 --- /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/java.png +name: preview +version: 0.1.0-SNAPSHOT diff --git a/charts/preview/Makefile b/charts/preview/Makefile new file mode 100755 index 0000000..36b0ac0 --- /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)\/vfarcic\/devops-toolkit|" 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 0000000..cb071bb --- /dev/null +++ b/charts/preview/requirements.yaml @@ -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: devops-toolkit + repository: file://../devops-toolkit diff --git a/charts/preview/values.yaml b/charts/preview/values.yaml new file mode 100755 index 0000000..b53ceaa --- /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/jenkins-x.yml b/jenkins-x.yml new file mode 100755 index 0000000..dd66462 --- /dev/null +++ b/jenkins-x.yml @@ -0,0 +1 @@ +buildPack: javascript diff --git a/skaffold.yaml b/skaffold.yaml new file mode 100644 index 0000000..93ea839 --- /dev/null +++ b/skaffold.yaml @@ -0,0 +1,30 @@ +apiVersion: skaffold/v1beta2 +kind: Config +build: + artifacts: + - image: changeme + context: . + docker: {} + tagPolicy: + envTemplate: + template: '{{.DOCKER_REGISTRY}}/vfarcic/devops-toolkit:{{.VERSION}}' + local: {} +deploy: + kubectl: {} +profiles: +- name: dev + build: + artifacts: + - docker: {} + tagPolicy: + envTemplate: + template: '{{.DOCKER_REGISTRY}}/vfarcic/devops-toolkit:{{.DIGEST_HEX}}' + local: {} + deploy: + helm: + releases: + - name: devops-toolkit + chartPath: charts/devops-toolkit + setValueTemplates: + image.repository: '{{.DOCKER_REGISTRY}}/vfarcic/devops-toolkit' + image.tag: '{{.DIGEST_HEX}}'