From cdf1983abc9b1e6e1989cabf3295a2f2450f89b7 Mon Sep 17 00:00:00 2001 From: Viktor Farcic Date: Sat, 4 Apr 2020 20:50:38 +0200 Subject: [PATCH 1/7] Draft create --- charts/go-demo-6/Makefile | 2 +- charts/golang/.helmignore | 21 ++++++ charts/golang/Chart.yaml | 5 ++ charts/golang/Makefile | 48 +++++++++++++ charts/golang/README.md | 1 + charts/golang/templates/NOTES.txt | 4 ++ charts/golang/templates/_helpers.tpl | 16 +++++ charts/golang/templates/canary.yaml | 85 ++++++++++++++++++++++ charts/golang/templates/deployment.yaml | 59 +++++++++++++++ charts/golang/templates/hpa.yaml | 25 +++++++ charts/golang/templates/ingress.yaml | 32 +++++++++ charts/golang/templates/ksvc.yaml | 41 +++++++++++ charts/golang/templates/service.yaml | 26 +++++++ charts/golang/values.yaml | 95 +++++++++++++++++++++++++ charts/preview/Makefile | 2 +- skaffold.yaml | 2 +- 16 files changed, 461 insertions(+), 3 deletions(-) create mode 100755 charts/golang/.helmignore create mode 100644 charts/golang/Chart.yaml create mode 100755 charts/golang/Makefile create mode 100755 charts/golang/README.md create mode 100755 charts/golang/templates/NOTES.txt create mode 100755 charts/golang/templates/_helpers.tpl create mode 100755 charts/golang/templates/canary.yaml create mode 100755 charts/golang/templates/deployment.yaml create mode 100755 charts/golang/templates/hpa.yaml create mode 100755 charts/golang/templates/ingress.yaml create mode 100755 charts/golang/templates/ksvc.yaml create mode 100755 charts/golang/templates/service.yaml create mode 100755 charts/golang/values.yaml diff --git a/charts/go-demo-6/Makefile b/charts/go-demo-6/Makefile index 065274768..cd4638010 100755 --- a/charts/go-demo-6/Makefile +++ b/charts/go-demo-6/Makefile @@ -36,7 +36,7 @@ ifeq ($(OS),Darwin) 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: $(DOCKER_REGISTRY)\/devops-26\/$(NAME)|" values.yaml + sed -i -e "s|repository:.*|repository: $(DOCKER_REGISTRY)\/devops-27\/$(NAME)|" values.yaml sed -i -e "s/tag:.*/tag: $(VERSION)/" values.yaml else echo "platfrom $(OS) not supported to tag with" diff --git a/charts/golang/.helmignore b/charts/golang/.helmignore new file mode 100755 index 000000000..f0c131944 --- /dev/null +++ b/charts/golang/.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/golang/Chart.yaml b/charts/golang/Chart.yaml new file mode 100644 index 000000000..7943cde02 --- /dev/null +++ b/charts/golang/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/go.png +name: golang +version: 0.1.0-SNAPSHOT diff --git a/charts/golang/Makefile b/charts/golang/Makefile new file mode 100755 index 000000000..cd4638010 --- /dev/null +++ b/charts/golang/Makefile @@ -0,0 +1,48 @@ +CHART_REPO := http://jenkins-x-chartmuseum:8080 +CURRENT=$(pwd) +NAME := go-demo-6 +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: $(DOCKER_REGISTRY)\/devops-27\/$(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) diff --git a/charts/golang/README.md b/charts/golang/README.md new file mode 100755 index 000000000..627fc3ddf --- /dev/null +++ b/charts/golang/README.md @@ -0,0 +1 @@ +# golang application \ No newline at end of file diff --git a/charts/golang/templates/NOTES.txt b/charts/golang/templates/NOTES.txt new file mode 100755 index 000000000..97823be26 --- /dev/null +++ b/charts/golang/templates/NOTES.txt @@ -0,0 +1,4 @@ + +Get the application URL by running these commands: + +kubectl get ingress {{ template "fullname" . }} diff --git a/charts/golang/templates/_helpers.tpl b/charts/golang/templates/_helpers.tpl new file mode 100755 index 000000000..f0d83d2ed --- /dev/null +++ b/charts/golang/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/golang/templates/canary.yaml b/charts/golang/templates/canary.yaml new file mode 100755 index 000000000..c65b13116 --- /dev/null +++ b/charts/golang/templates/canary.yaml @@ -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 }} diff --git a/charts/golang/templates/deployment.yaml b/charts/golang/templates/deployment.yaml new file mode 100755 index 000000000..1507ef6c2 --- /dev/null +++ b/charts/golang/templates/deployment.yaml @@ -0,0 +1,59 @@ +{{- if .Values.knativeDeploy }} +{{- else }} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "fullname" . }} + labels: + draft: {{ default "draft-app" .Values.draft }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +spec: + selector: + matchLabels: + app: {{ template "fullname" . }} +{{- if .Values.hpa.enabled }} +{{- else }} + replicas: {{ .Values.replicaCount }} +{{- end }} + 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: {{ quote $pval }} +{{- end }} + envFrom: +{{ toYaml .Values.envFrom | indent 10 }} + 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 }} diff --git a/charts/golang/templates/hpa.yaml b/charts/golang/templates/hpa.yaml new file mode 100755 index 000000000..1c03eb4c9 --- /dev/null +++ b/charts/golang/templates/hpa.yaml @@ -0,0 +1,25 @@ +{{- if .Values.hpa.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ template "fullname" . }} + labels: + draft: {{ default "draft-app" .Values.draft }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ template "fullname" . }} + minReplicas: {{ .Values.hpa.minReplicas }} + maxReplicas: {{ .Values.hpa.maxReplicas }} + metrics: + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.hpa.cpuTargetAverageUtilization }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.hpa.memoryTargetAverageUtilization }} +{{- end }} \ No newline at end of file diff --git a/charts/golang/templates/ingress.yaml b/charts/golang/templates/ingress.yaml new file mode 100755 index 000000000..df6e15aea --- /dev/null +++ b/charts/golang/templates/ingress.yaml @@ -0,0 +1,32 @@ +{{- if and (.Values.jxRequirements.ingress.domain) (not .Values.knativeDeploy) }} +apiVersion: {{ .Values.jxRequirements.ingress.apiVersion }} +kind: Ingress +metadata: + annotations: + kubernetes.io/ingress.class: nginx +{{- if .Values.ingress.annotations }} +{{ toYaml .Values.ingress.annotations | indent 4 }} +{{- end }} +{{- if .Values.jxRequirements.ingress.annotations }} +{{ toYaml .Values.jxRequirements.ingress.annotations | indent 4 }} +{{- end }} + name: {{ .Values.service.name }} +spec: + rules: + - host: {{ .Values.service.name }}{{ .Values.jxRequirements.ingress.namespaceSubDomain }}{{ .Values.jxRequirements.ingress.domain }} + http: + paths: + - backend: + serviceName: {{ .Values.service.name }} + servicePort: 80 +{{- if .Values.jxRequirements.ingress.tls.enabled }} + tls: + - hosts: + - {{ .Values.service.name }}{{ .Values.jxRequirements.ingress.namespaceSubDomain }}{{ .Values.jxRequirements.ingress.domain }} +{{- if .Values.jxRequirements.ingress.tls.production }} + secretName: "tls-{{ .Values.jxRequirements.ingress.domain | replace "." "-" }}-p" +{{- else }} + secretName: "tls-{{ .Values.jxRequirements.ingress.domain | replace "." "-" }}-s" +{{- end }} +{{- end }} +{{- end }} diff --git a/charts/golang/templates/ksvc.yaml b/charts/golang/templates/ksvc.yaml new file mode 100755 index 000000000..d37fb3f82 --- /dev/null +++ b/charts/golang/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: {{ quote $pval }} +{{- end }} + livenessProbe: + httpGet: + path: {{ .Values.probePath }} + initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.livenessProbe.periodSeconds }} + successThreshold: {{ .Values.livenessProbe.successThreshold }} + timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} + readinessProbe: + failureThreshold: {{ .Values.readinessProbe.failureThreshold }} + httpGet: + path: {{ .Values.probePath }} + periodSeconds: {{ .Values.readinessProbe.periodSeconds }} + successThreshold: {{ .Values.readinessProbe.successThreshold }} + timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} + resources: +{{ toYaml .Values.resources | indent 14 }} +{{- end }} diff --git a/charts/golang/templates/service.yaml b/charts/golang/templates/service.yaml new file mode 100755 index 000000000..9a2a4c758 --- /dev/null +++ b/charts/golang/templates/service.yaml @@ -0,0 +1,26 @@ +{{- if or .Values.knativeDeploy .Values.canary.enabled }} +{{- 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/golang/values.yaml b/charts/golang/values.yaml new file mode 100755 index 000000000..6f5042d71 --- /dev/null +++ b/charts/golang/values.yaml @@ -0,0 +1,95 @@ +# Default values for Go 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 + +# HorizontalPodAutoscaler +hpa: + enabled: false + minReplicas: 2 + maxReplicas: 6 + cpuTargetAverageUtilization: 80 + memoryTargetAverageUtilization: 80 + +# Canary deployments +# If enabled, Istio v1.5+ and Flagger need to be installed in the cluster +canary: + enabled: false + progressDeadlineSeconds: 60 + canaryAnalysis: + interval: "1m" + threshold: 5 + maxWeight: 60 + stepWeight: 20 + # WARNING: Canary deployments will fail and rollback if there is no traffic that will generate the below specified metrics. + metrics: + requestSuccessRate: + threshold: 99 + interval: "1m" + requestDuration: + threshold: 1000 + interval: "1m" + # The host is using Istio Gateway and is currently not auto-generated + # Please overwrite the `canary.host` in `values.yaml` in each environment repository (e.g., staging, production) + host: acme.com + +service: + name: go-demo-6 + 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: 256Mi + requests: + cpu: 80m + memory: 128Mi +probePath: / +livenessProbe: + initialDelaySeconds: 60 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 +readinessProbe: + failureThreshold: 1 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 + + +# custom ingress annotations on this service +ingress: + annotations: +# kubernetes.io/ingress.class: nginx + +# values we use from the `jx-requirements.yml` file if we are using helmfile and helm 3 +jxRequirements: + ingress: + domain: "" + externalDNS: false + namespaceSubDomain: -jx. + tls: + email: "" + enabled: false + production: false + + # For Kubernetes v1.14+, use 'networking.k8s.io/v1beta1' + apiVersion: "extensions/v1beta1" + + # shared ingress annotations on all services + annotations: + # kubernetes.io/ingress.class: nginx diff --git a/charts/preview/Makefile b/charts/preview/Makefile index 7663503a3..50e87820a 100755 --- a/charts/preview/Makefile +++ b/charts/preview/Makefile @@ -8,7 +8,7 @@ ifeq ($(OS),Darwin) 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)\/devops-26\/go-demo-6|" values.yaml + sed -i -e "s|repository:.*|repository: $(DOCKER_REGISTRY)\/devops-27\/go-demo-6|" values.yaml sed -i -e "s/tag:.*/tag: $(PREVIEW_VERSION)/" values.yaml else echo "platfrom $(OS) not supported to release from" diff --git a/skaffold.yaml b/skaffold.yaml index 7eaa482fe..96a727a72 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -2,7 +2,7 @@ apiVersion: skaffold/v1beta2 kind: Config build: artifacts: - - image: devops-26/go-demo-6 + - image: devops-27/go-demo-6 context: . docker: {} tagPolicy: From a2dc00a2647051ea004f1e53497781ff517c3eda Mon Sep 17 00:00:00 2001 From: Viktor Farcic Date: Tue, 28 Apr 2020 13:36:04 +0200 Subject: [PATCH 2/7] Draft create --- charts/go-demo-6/Makefile | 2 +- charts/preview/Makefile | 2 +- skaffold.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/charts/go-demo-6/Makefile b/charts/go-demo-6/Makefile index 065274768..8b188822e 100755 --- a/charts/go-demo-6/Makefile +++ b/charts/go-demo-6/Makefile @@ -36,7 +36,7 @@ ifeq ($(OS),Darwin) 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: $(DOCKER_REGISTRY)\/devops-26\/$(NAME)|" values.yaml + sed -i -e "s|repository:.*|repository: $(DOCKER_REGISTRY)\/jx-demo-project\/$(NAME)|" values.yaml sed -i -e "s/tag:.*/tag: $(VERSION)/" values.yaml else echo "platfrom $(OS) not supported to tag with" diff --git a/charts/preview/Makefile b/charts/preview/Makefile index 7663503a3..854fe395f 100755 --- a/charts/preview/Makefile +++ b/charts/preview/Makefile @@ -8,7 +8,7 @@ ifeq ($(OS),Darwin) 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)\/devops-26\/go-demo-6|" values.yaml + sed -i -e "s|repository:.*|repository: $(DOCKER_REGISTRY)\/jx-demo-project\/go-demo-6|" values.yaml sed -i -e "s/tag:.*/tag: $(PREVIEW_VERSION)/" values.yaml else echo "platfrom $(OS) not supported to release from" diff --git a/skaffold.yaml b/skaffold.yaml index 7eaa482fe..614ca504a 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -2,7 +2,7 @@ apiVersion: skaffold/v1beta2 kind: Config build: artifacts: - - image: devops-26/go-demo-6 + - image: jx-demo-project/go-demo-6 context: . docker: {} tagPolicy: From 7ae7ae5180b812865ac07f2e50161315c8254382 Mon Sep 17 00:00:00 2001 From: Viktor Farcic Date: Tue, 28 Apr 2020 15:20:57 +0200 Subject: [PATCH 3/7] Multi-architecture --- jenkins-x.yml | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/jenkins-x.yml b/jenkins-x.yml index 880cd6f8a..504a7442d 100755 --- a/jenkins-x.yml +++ b/jenkins-x.yml @@ -1,10 +1,31 @@ buildPack: go pipelineConfig: + env: + - name: CODECOV_TOKEN + valueFrom: + secretKeyRef: + key: token + name: codecov pipelines: pullRequest: build: preSteps: - - command: make unittest + - name: unit-tests + command: make unittest + - name: code-coverage + command: codecov.sh + agent: + image: vfarcic/codecov promote: steps: - - command: ADDRESS=`jx get preview --current 2>&1` make functest + - name: rollout + command: | + NS=`echo jx-$REPO_OWNER-go-demo-6-$BRANCH_NAME | tr '[:upper:]' '[:lower:]'` + sleep 15 + kubectl -n $NS rollout status deployment preview-preview --timeout 3m + - name: functional-tests + command: ADDRESS=`jx get preview --current 2>&1` make functest + # This is new + overrides: + - pipeline: release + From 59818367122bfb0b17a79bc579ad3aff3b71c4e5 Mon Sep 17 00:00:00 2001 From: Viktor Farcic Date: Tue, 28 Apr 2020 15:23:27 +0200 Subject: [PATCH 4/7] Multi-architecture --- jenkins-x.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/jenkins-x.yml b/jenkins-x.yml index 504a7442d..d98c07305 100755 --- a/jenkins-x.yml +++ b/jenkins-x.yml @@ -25,7 +25,16 @@ pipelineConfig: kubectl -n $NS rollout status deployment preview-preview --timeout 3m - name: functional-tests command: ADDRESS=`jx get preview --current 2>&1` make functest - # This is new overrides: - pipeline: release + # This is new + stage: build + # This is new + release: + promote: + steps: + - name: rollout + command: | + sleep 30 + kubectl -n jx-staging rollout status deployment jx-go-demo-6 --timeout 3m From 3e6aad4ea4a073a4c381381eb43fb7db08eb4a63 Mon Sep 17 00:00:00 2001 From: Viktor Farcic Date: Mon, 18 May 2020 15:38:04 +0200 Subject: [PATCH 5/7] Draft create --- .dockerignore | 13 +++ .helmignore | 27 ++++++ Dockerfile | 4 + Makefile | 62 ++++++++++++++ OWNERS | 4 + OWNERS_ALIASES | 6 ++ charts/go-demo-6/.helmignore | 21 +++++ charts/go-demo-6/Chart.yaml | 5 ++ charts/go-demo-6/Makefile | 48 +++++++++++ charts/go-demo-6/README.md | 1 + charts/go-demo-6/templates/NOTES.txt | 4 + charts/go-demo-6/templates/_helpers.tpl | 16 ++++ charts/go-demo-6/templates/canary.yaml | 85 +++++++++++++++++++ charts/go-demo-6/templates/deployment.yaml | 59 ++++++++++++++ charts/go-demo-6/templates/hpa.yaml | 25 ++++++ charts/go-demo-6/templates/ingress.yaml | 32 ++++++++ charts/go-demo-6/templates/ksvc.yaml | 41 ++++++++++ charts/go-demo-6/templates/service.yaml | 26 ++++++ charts/go-demo-6/values.yaml | 95 ++++++++++++++++++++++ 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 | 28 +++++++ watch.sh | 6 ++ 26 files changed, 670 insertions(+) create mode 100644 .dockerignore create mode 100644 .helmignore create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 OWNERS create mode 100644 OWNERS_ALIASES create mode 100755 charts/go-demo-6/.helmignore create mode 100644 charts/go-demo-6/Chart.yaml create mode 100755 charts/go-demo-6/Makefile create mode 100755 charts/go-demo-6/README.md create mode 100755 charts/go-demo-6/templates/NOTES.txt create mode 100755 charts/go-demo-6/templates/_helpers.tpl create mode 100755 charts/go-demo-6/templates/canary.yaml create mode 100755 charts/go-demo-6/templates/deployment.yaml create mode 100755 charts/go-demo-6/templates/hpa.yaml create mode 100755 charts/go-demo-6/templates/ingress.yaml create mode 100755 charts/go-demo-6/templates/ksvc.yaml create mode 100755 charts/go-demo-6/templates/service.yaml create mode 100755 charts/go-demo-6/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 create mode 100644 watch.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..1a8077fd6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +draft.toml +target/classes +target/generated-sources +target/generated-test-sources +target/maven-archiver +target/maven-status +target/surefire-reports +target/test-classes +target/*.original +charts/ +NOTICE +LICENSE +README.md \ No newline at end of file diff --git a/.helmignore b/.helmignore new file mode 100644 index 000000000..747e6e94a --- /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/Dockerfile b/Dockerfile new file mode 100644 index 000000000..f96718806 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM scratch +EXPOSE 8080 +ENTRYPOINT ["/go-demo-6"] +COPY ./bin/ / \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..37b34fe23 --- /dev/null +++ b/Makefile @@ -0,0 +1,62 @@ +SHELL := /bin/bash +GO := GO15VENDOREXPERIMENT=1 go +NAME := go-demo-6 +OS := $(shell uname) +MAIN_GO := main.go +ROOT_PACKAGE := $(GIT_PROVIDER)/vfarcic/$(NAME) +GO_VERSION := $(shell $(GO) version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/') +PACKAGE_DIRS := $(shell $(GO) list ./... | grep -v /vendor/) +PKGS := $(shell go list ./... | grep -v /vendor | grep -v generated) +BUILDFLAGS := '' +CGO_ENABLED = 0 +VENDOR_DIR=vendor + +all: build + +check: fmt build test + +build: + CGO_ENABLED=$(CGO_ENABLED) $(GO) build -ldflags $(BUILDFLAGS) -o bin/$(NAME) $(MAIN_GO) + +test: + CGO_ENABLED=$(CGO_ENABLED) $(GO) test $(PACKAGE_DIRS) -test.v + +full: $(PKGS) + +install: + GOBIN=${GOPATH}/bin $(GO) install -ldflags $(BUILDFLAGS) $(MAIN_GO) + +fmt: + @FORMATTED=`$(GO) fmt $(PACKAGE_DIRS)` + @([[ ! -z "$(FORMATTED)" ]] && printf "Fixed unformatted files:\n$(FORMATTED)") || true + +clean: + rm -rf build release + +linux: + CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 $(GO) build -ldflags $(BUILDFLAGS) -o bin/$(NAME) $(MAIN_GO) + +.PHONY: release clean + +FGT := $(GOPATH)/bin/fgt +$(FGT): + go get github.com/GeertJohan/fgt + +GOLINT := $(GOPATH)/bin/golint +$(GOLINT): + go get github.com/golang/lint/golint + +$(PKGS): $(GOLINT) $(FGT) + @echo "LINTING" + @$(FGT) $(GOLINT) $(GOPATH)/src/$@/*.go + @echo "VETTING" + @go vet -v $@ + @echo "TESTING" + @go test -v $@ + +.PHONY: lint +lint: vendor | $(PKGS) $(GOLINT) # ❷ + @cd $(BASE) && ret=0 && for pkg in $(PKGS); do \ + test -z "$$($(GOLINT) $$pkg | tee /dev/stderr)" || ret=1 ; \ + done ; exit $$ret + diff --git a/OWNERS b/OWNERS new file mode 100644 index 000000000..11fd3dc6f --- /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 000000000..c8deecb16 --- /dev/null +++ b/OWNERS_ALIASES @@ -0,0 +1,6 @@ +aliases: +- vfarcic +best-approvers: +- vfarcic +best-reviewers: +- vfarcic diff --git a/charts/go-demo-6/.helmignore b/charts/go-demo-6/.helmignore new file mode 100755 index 000000000..f0c131944 --- /dev/null +++ b/charts/go-demo-6/.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/go-demo-6/Chart.yaml b/charts/go-demo-6/Chart.yaml new file mode 100644 index 000000000..238ed7b12 --- /dev/null +++ b/charts/go-demo-6/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/go.png +name: go-demo-6 +version: 0.1.0-SNAPSHOT diff --git a/charts/go-demo-6/Makefile b/charts/go-demo-6/Makefile new file mode 100755 index 000000000..77af017d8 --- /dev/null +++ b/charts/go-demo-6/Makefile @@ -0,0 +1,48 @@ +CHART_REPO := http://jenkins-x-chartmuseum:8080 +CURRENT=$(pwd) +NAME := go-demo-6 +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: $(DOCKER_REGISTRY)\/vfarcic\/$(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) diff --git a/charts/go-demo-6/README.md b/charts/go-demo-6/README.md new file mode 100755 index 000000000..627fc3ddf --- /dev/null +++ b/charts/go-demo-6/README.md @@ -0,0 +1 @@ +# golang application \ No newline at end of file diff --git a/charts/go-demo-6/templates/NOTES.txt b/charts/go-demo-6/templates/NOTES.txt new file mode 100755 index 000000000..97823be26 --- /dev/null +++ b/charts/go-demo-6/templates/NOTES.txt @@ -0,0 +1,4 @@ + +Get the application URL by running these commands: + +kubectl get ingress {{ template "fullname" . }} diff --git a/charts/go-demo-6/templates/_helpers.tpl b/charts/go-demo-6/templates/_helpers.tpl new file mode 100755 index 000000000..f0d83d2ed --- /dev/null +++ b/charts/go-demo-6/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/go-demo-6/templates/canary.yaml b/charts/go-demo-6/templates/canary.yaml new file mode 100755 index 000000000..c65b13116 --- /dev/null +++ b/charts/go-demo-6/templates/canary.yaml @@ -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 }} diff --git a/charts/go-demo-6/templates/deployment.yaml b/charts/go-demo-6/templates/deployment.yaml new file mode 100755 index 000000000..1507ef6c2 --- /dev/null +++ b/charts/go-demo-6/templates/deployment.yaml @@ -0,0 +1,59 @@ +{{- if .Values.knativeDeploy }} +{{- else }} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "fullname" . }} + labels: + draft: {{ default "draft-app" .Values.draft }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +spec: + selector: + matchLabels: + app: {{ template "fullname" . }} +{{- if .Values.hpa.enabled }} +{{- else }} + replicas: {{ .Values.replicaCount }} +{{- end }} + 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: {{ quote $pval }} +{{- end }} + envFrom: +{{ toYaml .Values.envFrom | indent 10 }} + 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 }} diff --git a/charts/go-demo-6/templates/hpa.yaml b/charts/go-demo-6/templates/hpa.yaml new file mode 100755 index 000000000..1c03eb4c9 --- /dev/null +++ b/charts/go-demo-6/templates/hpa.yaml @@ -0,0 +1,25 @@ +{{- if .Values.hpa.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ template "fullname" . }} + labels: + draft: {{ default "draft-app" .Values.draft }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ template "fullname" . }} + minReplicas: {{ .Values.hpa.minReplicas }} + maxReplicas: {{ .Values.hpa.maxReplicas }} + metrics: + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.hpa.cpuTargetAverageUtilization }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.hpa.memoryTargetAverageUtilization }} +{{- end }} \ No newline at end of file diff --git a/charts/go-demo-6/templates/ingress.yaml b/charts/go-demo-6/templates/ingress.yaml new file mode 100755 index 000000000..df6e15aea --- /dev/null +++ b/charts/go-demo-6/templates/ingress.yaml @@ -0,0 +1,32 @@ +{{- if and (.Values.jxRequirements.ingress.domain) (not .Values.knativeDeploy) }} +apiVersion: {{ .Values.jxRequirements.ingress.apiVersion }} +kind: Ingress +metadata: + annotations: + kubernetes.io/ingress.class: nginx +{{- if .Values.ingress.annotations }} +{{ toYaml .Values.ingress.annotations | indent 4 }} +{{- end }} +{{- if .Values.jxRequirements.ingress.annotations }} +{{ toYaml .Values.jxRequirements.ingress.annotations | indent 4 }} +{{- end }} + name: {{ .Values.service.name }} +spec: + rules: + - host: {{ .Values.service.name }}{{ .Values.jxRequirements.ingress.namespaceSubDomain }}{{ .Values.jxRequirements.ingress.domain }} + http: + paths: + - backend: + serviceName: {{ .Values.service.name }} + servicePort: 80 +{{- if .Values.jxRequirements.ingress.tls.enabled }} + tls: + - hosts: + - {{ .Values.service.name }}{{ .Values.jxRequirements.ingress.namespaceSubDomain }}{{ .Values.jxRequirements.ingress.domain }} +{{- if .Values.jxRequirements.ingress.tls.production }} + secretName: "tls-{{ .Values.jxRequirements.ingress.domain | replace "." "-" }}-p" +{{- else }} + secretName: "tls-{{ .Values.jxRequirements.ingress.domain | replace "." "-" }}-s" +{{- end }} +{{- end }} +{{- end }} diff --git a/charts/go-demo-6/templates/ksvc.yaml b/charts/go-demo-6/templates/ksvc.yaml new file mode 100755 index 000000000..d37fb3f82 --- /dev/null +++ b/charts/go-demo-6/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: {{ quote $pval }} +{{- end }} + livenessProbe: + httpGet: + path: {{ .Values.probePath }} + initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.livenessProbe.periodSeconds }} + successThreshold: {{ .Values.livenessProbe.successThreshold }} + timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} + readinessProbe: + failureThreshold: {{ .Values.readinessProbe.failureThreshold }} + httpGet: + path: {{ .Values.probePath }} + periodSeconds: {{ .Values.readinessProbe.periodSeconds }} + successThreshold: {{ .Values.readinessProbe.successThreshold }} + timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} + resources: +{{ toYaml .Values.resources | indent 14 }} +{{- end }} diff --git a/charts/go-demo-6/templates/service.yaml b/charts/go-demo-6/templates/service.yaml new file mode 100755 index 000000000..9a2a4c758 --- /dev/null +++ b/charts/go-demo-6/templates/service.yaml @@ -0,0 +1,26 @@ +{{- if or .Values.knativeDeploy .Values.canary.enabled }} +{{- 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/go-demo-6/values.yaml b/charts/go-demo-6/values.yaml new file mode 100755 index 000000000..6f5042d71 --- /dev/null +++ b/charts/go-demo-6/values.yaml @@ -0,0 +1,95 @@ +# Default values for Go 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 + +# HorizontalPodAutoscaler +hpa: + enabled: false + minReplicas: 2 + maxReplicas: 6 + cpuTargetAverageUtilization: 80 + memoryTargetAverageUtilization: 80 + +# Canary deployments +# If enabled, Istio v1.5+ and Flagger need to be installed in the cluster +canary: + enabled: false + progressDeadlineSeconds: 60 + canaryAnalysis: + interval: "1m" + threshold: 5 + maxWeight: 60 + stepWeight: 20 + # WARNING: Canary deployments will fail and rollback if there is no traffic that will generate the below specified metrics. + metrics: + requestSuccessRate: + threshold: 99 + interval: "1m" + requestDuration: + threshold: 1000 + interval: "1m" + # The host is using Istio Gateway and is currently not auto-generated + # Please overwrite the `canary.host` in `values.yaml` in each environment repository (e.g., staging, production) + host: acme.com + +service: + name: go-demo-6 + 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: 256Mi + requests: + cpu: 80m + memory: 128Mi +probePath: / +livenessProbe: + initialDelaySeconds: 60 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 +readinessProbe: + failureThreshold: 1 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 + + +# custom ingress annotations on this service +ingress: + annotations: +# kubernetes.io/ingress.class: nginx + +# values we use from the `jx-requirements.yml` file if we are using helmfile and helm 3 +jxRequirements: + ingress: + domain: "" + externalDNS: false + namespaceSubDomain: -jx. + tls: + email: "" + enabled: false + production: false + + # For Kubernetes v1.14+, use 'networking.k8s.io/v1beta1' + apiVersion: "extensions/v1beta1" + + # shared ingress annotations on all services + annotations: + # kubernetes.io/ingress.class: nginx diff --git a/charts/preview/Chart.yaml b/charts/preview/Chart.yaml new file mode 100644 index 000000000..d5b379cf2 --- /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/go.png +name: preview +version: 0.1.0-SNAPSHOT diff --git a/charts/preview/Makefile b/charts/preview/Makefile new file mode 100755 index 000000000..c8d4e60cd --- /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\/go-demo-6|" 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 000000000..54957ae67 --- /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: go-demo-6 + repository: file://../go-demo-6 diff --git a/charts/preview/values.yaml b/charts/preview/values.yaml new file mode 100755 index 000000000..b53ceaa57 --- /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 000000000..a121a198e --- /dev/null +++ b/jenkins-x.yml @@ -0,0 +1 @@ +buildPack: go diff --git a/skaffold.yaml b/skaffold.yaml new file mode 100644 index 000000000..83c8be6df --- /dev/null +++ b/skaffold.yaml @@ -0,0 +1,28 @@ +apiVersion: skaffold/v1beta2 +kind: Config +build: + artifacts: + - image: vfarcic/go-demo-6 + context: . + docker: {} + tagPolicy: + envTemplate: + template: '{{.DOCKER_REGISTRY}}/{{.IMAGE_NAME}}:{{.VERSION}}' + local: {} +deploy: + kubectl: {} +profiles: +- name: dev + build: + tagPolicy: + envTemplate: + template: '{{.DOCKER_REGISTRY}}/{{.IMAGE_NAME}}:{{.DIGEST_HEX}}' + local: {} + deploy: + helm: + releases: + - name: go-demo-6 + chartPath: charts/go-demo-6 + setValueTemplates: + image.repository: '{{.DOCKER_REGISTRY}}/{{.IMAGE_NAME}}' + image.tag: '{{.DIGEST_HEX}}' diff --git a/watch.sh b/watch.sh new file mode 100644 index 000000000..679dc7073 --- /dev/null +++ b/watch.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +# watch the go files and continously deploy the service +make linux +skaffold run -p dev +reflex -r "\.go$" -- bash -c 'make linux && skaffold run -p dev' From 19996ff403092412f9c12deb8eab8d34b7838746 Mon Sep 17 00:00:00 2001 From: Viktor Farcic Date: Mon, 18 May 2020 15:39:34 +0200 Subject: [PATCH 6/7] JX Workshop --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index fcd89a90d..264dfdd37 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,4 @@ git merge orig git push ``` + From 88b12cbd3851bdfedcdcd2d0fd4aabe1426701f7 Mon Sep 17 00:00:00 2001 From: Viktor Farcic Date: Mon, 18 May 2020 17:20:49 +0200 Subject: [PATCH 7/7] Draft create --- .dockerignore | 13 +++ .helmignore | 27 ++++++ Dockerfile | 4 + Makefile | 62 ++++++++++++++ OWNERS | 4 + OWNERS_ALIASES | 6 ++ charts/go-demo-6/.helmignore | 21 +++++ charts/go-demo-6/Chart.yaml | 5 ++ charts/go-demo-6/Makefile | 48 +++++++++++ charts/go-demo-6/README.md | 1 + charts/go-demo-6/templates/NOTES.txt | 4 + charts/go-demo-6/templates/_helpers.tpl | 16 ++++ charts/go-demo-6/templates/canary.yaml | 85 +++++++++++++++++++ charts/go-demo-6/templates/deployment.yaml | 59 ++++++++++++++ charts/go-demo-6/templates/hpa.yaml | 25 ++++++ charts/go-demo-6/templates/ingress.yaml | 32 ++++++++ charts/go-demo-6/templates/ksvc.yaml | 41 ++++++++++ charts/go-demo-6/templates/service.yaml | 26 ++++++ charts/go-demo-6/values.yaml | 95 ++++++++++++++++++++++ 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 | 28 +++++++ watch.sh | 6 ++ 26 files changed, 670 insertions(+) create mode 100644 .dockerignore create mode 100644 .helmignore create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 OWNERS create mode 100644 OWNERS_ALIASES create mode 100755 charts/go-demo-6/.helmignore create mode 100644 charts/go-demo-6/Chart.yaml create mode 100755 charts/go-demo-6/Makefile create mode 100755 charts/go-demo-6/README.md create mode 100755 charts/go-demo-6/templates/NOTES.txt create mode 100755 charts/go-demo-6/templates/_helpers.tpl create mode 100755 charts/go-demo-6/templates/canary.yaml create mode 100755 charts/go-demo-6/templates/deployment.yaml create mode 100755 charts/go-demo-6/templates/hpa.yaml create mode 100755 charts/go-demo-6/templates/ingress.yaml create mode 100755 charts/go-demo-6/templates/ksvc.yaml create mode 100755 charts/go-demo-6/templates/service.yaml create mode 100755 charts/go-demo-6/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 create mode 100644 watch.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..1a8077fd6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +draft.toml +target/classes +target/generated-sources +target/generated-test-sources +target/maven-archiver +target/maven-status +target/surefire-reports +target/test-classes +target/*.original +charts/ +NOTICE +LICENSE +README.md \ No newline at end of file diff --git a/.helmignore b/.helmignore new file mode 100644 index 000000000..747e6e94a --- /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/Dockerfile b/Dockerfile new file mode 100644 index 000000000..f96718806 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM scratch +EXPOSE 8080 +ENTRYPOINT ["/go-demo-6"] +COPY ./bin/ / \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..37b34fe23 --- /dev/null +++ b/Makefile @@ -0,0 +1,62 @@ +SHELL := /bin/bash +GO := GO15VENDOREXPERIMENT=1 go +NAME := go-demo-6 +OS := $(shell uname) +MAIN_GO := main.go +ROOT_PACKAGE := $(GIT_PROVIDER)/vfarcic/$(NAME) +GO_VERSION := $(shell $(GO) version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/') +PACKAGE_DIRS := $(shell $(GO) list ./... | grep -v /vendor/) +PKGS := $(shell go list ./... | grep -v /vendor | grep -v generated) +BUILDFLAGS := '' +CGO_ENABLED = 0 +VENDOR_DIR=vendor + +all: build + +check: fmt build test + +build: + CGO_ENABLED=$(CGO_ENABLED) $(GO) build -ldflags $(BUILDFLAGS) -o bin/$(NAME) $(MAIN_GO) + +test: + CGO_ENABLED=$(CGO_ENABLED) $(GO) test $(PACKAGE_DIRS) -test.v + +full: $(PKGS) + +install: + GOBIN=${GOPATH}/bin $(GO) install -ldflags $(BUILDFLAGS) $(MAIN_GO) + +fmt: + @FORMATTED=`$(GO) fmt $(PACKAGE_DIRS)` + @([[ ! -z "$(FORMATTED)" ]] && printf "Fixed unformatted files:\n$(FORMATTED)") || true + +clean: + rm -rf build release + +linux: + CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 $(GO) build -ldflags $(BUILDFLAGS) -o bin/$(NAME) $(MAIN_GO) + +.PHONY: release clean + +FGT := $(GOPATH)/bin/fgt +$(FGT): + go get github.com/GeertJohan/fgt + +GOLINT := $(GOPATH)/bin/golint +$(GOLINT): + go get github.com/golang/lint/golint + +$(PKGS): $(GOLINT) $(FGT) + @echo "LINTING" + @$(FGT) $(GOLINT) $(GOPATH)/src/$@/*.go + @echo "VETTING" + @go vet -v $@ + @echo "TESTING" + @go test -v $@ + +.PHONY: lint +lint: vendor | $(PKGS) $(GOLINT) # ❷ + @cd $(BASE) && ret=0 && for pkg in $(PKGS); do \ + test -z "$$($(GOLINT) $$pkg | tee /dev/stderr)" || ret=1 ; \ + done ; exit $$ret + diff --git a/OWNERS b/OWNERS new file mode 100644 index 000000000..11fd3dc6f --- /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 000000000..c8deecb16 --- /dev/null +++ b/OWNERS_ALIASES @@ -0,0 +1,6 @@ +aliases: +- vfarcic +best-approvers: +- vfarcic +best-reviewers: +- vfarcic diff --git a/charts/go-demo-6/.helmignore b/charts/go-demo-6/.helmignore new file mode 100755 index 000000000..f0c131944 --- /dev/null +++ b/charts/go-demo-6/.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/go-demo-6/Chart.yaml b/charts/go-demo-6/Chart.yaml new file mode 100644 index 000000000..238ed7b12 --- /dev/null +++ b/charts/go-demo-6/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/go.png +name: go-demo-6 +version: 0.1.0-SNAPSHOT diff --git a/charts/go-demo-6/Makefile b/charts/go-demo-6/Makefile new file mode 100755 index 000000000..77af017d8 --- /dev/null +++ b/charts/go-demo-6/Makefile @@ -0,0 +1,48 @@ +CHART_REPO := http://jenkins-x-chartmuseum:8080 +CURRENT=$(pwd) +NAME := go-demo-6 +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: $(DOCKER_REGISTRY)\/vfarcic\/$(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) diff --git a/charts/go-demo-6/README.md b/charts/go-demo-6/README.md new file mode 100755 index 000000000..627fc3ddf --- /dev/null +++ b/charts/go-demo-6/README.md @@ -0,0 +1 @@ +# golang application \ No newline at end of file diff --git a/charts/go-demo-6/templates/NOTES.txt b/charts/go-demo-6/templates/NOTES.txt new file mode 100755 index 000000000..97823be26 --- /dev/null +++ b/charts/go-demo-6/templates/NOTES.txt @@ -0,0 +1,4 @@ + +Get the application URL by running these commands: + +kubectl get ingress {{ template "fullname" . }} diff --git a/charts/go-demo-6/templates/_helpers.tpl b/charts/go-demo-6/templates/_helpers.tpl new file mode 100755 index 000000000..f0d83d2ed --- /dev/null +++ b/charts/go-demo-6/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/go-demo-6/templates/canary.yaml b/charts/go-demo-6/templates/canary.yaml new file mode 100755 index 000000000..c65b13116 --- /dev/null +++ b/charts/go-demo-6/templates/canary.yaml @@ -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 }} diff --git a/charts/go-demo-6/templates/deployment.yaml b/charts/go-demo-6/templates/deployment.yaml new file mode 100755 index 000000000..1507ef6c2 --- /dev/null +++ b/charts/go-demo-6/templates/deployment.yaml @@ -0,0 +1,59 @@ +{{- if .Values.knativeDeploy }} +{{- else }} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "fullname" . }} + labels: + draft: {{ default "draft-app" .Values.draft }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +spec: + selector: + matchLabels: + app: {{ template "fullname" . }} +{{- if .Values.hpa.enabled }} +{{- else }} + replicas: {{ .Values.replicaCount }} +{{- end }} + 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: {{ quote $pval }} +{{- end }} + envFrom: +{{ toYaml .Values.envFrom | indent 10 }} + 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 }} diff --git a/charts/go-demo-6/templates/hpa.yaml b/charts/go-demo-6/templates/hpa.yaml new file mode 100755 index 000000000..1c03eb4c9 --- /dev/null +++ b/charts/go-demo-6/templates/hpa.yaml @@ -0,0 +1,25 @@ +{{- if .Values.hpa.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ template "fullname" . }} + labels: + draft: {{ default "draft-app" .Values.draft }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ template "fullname" . }} + minReplicas: {{ .Values.hpa.minReplicas }} + maxReplicas: {{ .Values.hpa.maxReplicas }} + metrics: + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.hpa.cpuTargetAverageUtilization }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.hpa.memoryTargetAverageUtilization }} +{{- end }} \ No newline at end of file diff --git a/charts/go-demo-6/templates/ingress.yaml b/charts/go-demo-6/templates/ingress.yaml new file mode 100755 index 000000000..df6e15aea --- /dev/null +++ b/charts/go-demo-6/templates/ingress.yaml @@ -0,0 +1,32 @@ +{{- if and (.Values.jxRequirements.ingress.domain) (not .Values.knativeDeploy) }} +apiVersion: {{ .Values.jxRequirements.ingress.apiVersion }} +kind: Ingress +metadata: + annotations: + kubernetes.io/ingress.class: nginx +{{- if .Values.ingress.annotations }} +{{ toYaml .Values.ingress.annotations | indent 4 }} +{{- end }} +{{- if .Values.jxRequirements.ingress.annotations }} +{{ toYaml .Values.jxRequirements.ingress.annotations | indent 4 }} +{{- end }} + name: {{ .Values.service.name }} +spec: + rules: + - host: {{ .Values.service.name }}{{ .Values.jxRequirements.ingress.namespaceSubDomain }}{{ .Values.jxRequirements.ingress.domain }} + http: + paths: + - backend: + serviceName: {{ .Values.service.name }} + servicePort: 80 +{{- if .Values.jxRequirements.ingress.tls.enabled }} + tls: + - hosts: + - {{ .Values.service.name }}{{ .Values.jxRequirements.ingress.namespaceSubDomain }}{{ .Values.jxRequirements.ingress.domain }} +{{- if .Values.jxRequirements.ingress.tls.production }} + secretName: "tls-{{ .Values.jxRequirements.ingress.domain | replace "." "-" }}-p" +{{- else }} + secretName: "tls-{{ .Values.jxRequirements.ingress.domain | replace "." "-" }}-s" +{{- end }} +{{- end }} +{{- end }} diff --git a/charts/go-demo-6/templates/ksvc.yaml b/charts/go-demo-6/templates/ksvc.yaml new file mode 100755 index 000000000..d37fb3f82 --- /dev/null +++ b/charts/go-demo-6/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: {{ quote $pval }} +{{- end }} + livenessProbe: + httpGet: + path: {{ .Values.probePath }} + initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.livenessProbe.periodSeconds }} + successThreshold: {{ .Values.livenessProbe.successThreshold }} + timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} + readinessProbe: + failureThreshold: {{ .Values.readinessProbe.failureThreshold }} + httpGet: + path: {{ .Values.probePath }} + periodSeconds: {{ .Values.readinessProbe.periodSeconds }} + successThreshold: {{ .Values.readinessProbe.successThreshold }} + timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} + resources: +{{ toYaml .Values.resources | indent 14 }} +{{- end }} diff --git a/charts/go-demo-6/templates/service.yaml b/charts/go-demo-6/templates/service.yaml new file mode 100755 index 000000000..9a2a4c758 --- /dev/null +++ b/charts/go-demo-6/templates/service.yaml @@ -0,0 +1,26 @@ +{{- if or .Values.knativeDeploy .Values.canary.enabled }} +{{- 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/go-demo-6/values.yaml b/charts/go-demo-6/values.yaml new file mode 100755 index 000000000..6f5042d71 --- /dev/null +++ b/charts/go-demo-6/values.yaml @@ -0,0 +1,95 @@ +# Default values for Go 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 + +# HorizontalPodAutoscaler +hpa: + enabled: false + minReplicas: 2 + maxReplicas: 6 + cpuTargetAverageUtilization: 80 + memoryTargetAverageUtilization: 80 + +# Canary deployments +# If enabled, Istio v1.5+ and Flagger need to be installed in the cluster +canary: + enabled: false + progressDeadlineSeconds: 60 + canaryAnalysis: + interval: "1m" + threshold: 5 + maxWeight: 60 + stepWeight: 20 + # WARNING: Canary deployments will fail and rollback if there is no traffic that will generate the below specified metrics. + metrics: + requestSuccessRate: + threshold: 99 + interval: "1m" + requestDuration: + threshold: 1000 + interval: "1m" + # The host is using Istio Gateway and is currently not auto-generated + # Please overwrite the `canary.host` in `values.yaml` in each environment repository (e.g., staging, production) + host: acme.com + +service: + name: go-demo-6 + 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: 256Mi + requests: + cpu: 80m + memory: 128Mi +probePath: / +livenessProbe: + initialDelaySeconds: 60 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 +readinessProbe: + failureThreshold: 1 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 + + +# custom ingress annotations on this service +ingress: + annotations: +# kubernetes.io/ingress.class: nginx + +# values we use from the `jx-requirements.yml` file if we are using helmfile and helm 3 +jxRequirements: + ingress: + domain: "" + externalDNS: false + namespaceSubDomain: -jx. + tls: + email: "" + enabled: false + production: false + + # For Kubernetes v1.14+, use 'networking.k8s.io/v1beta1' + apiVersion: "extensions/v1beta1" + + # shared ingress annotations on all services + annotations: + # kubernetes.io/ingress.class: nginx diff --git a/charts/preview/Chart.yaml b/charts/preview/Chart.yaml new file mode 100644 index 000000000..d5b379cf2 --- /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/go.png +name: preview +version: 0.1.0-SNAPSHOT diff --git a/charts/preview/Makefile b/charts/preview/Makefile new file mode 100755 index 000000000..c8d4e60cd --- /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\/go-demo-6|" 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 000000000..54957ae67 --- /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: go-demo-6 + repository: file://../go-demo-6 diff --git a/charts/preview/values.yaml b/charts/preview/values.yaml new file mode 100755 index 000000000..b53ceaa57 --- /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 000000000..a121a198e --- /dev/null +++ b/jenkins-x.yml @@ -0,0 +1 @@ +buildPack: go diff --git a/skaffold.yaml b/skaffold.yaml new file mode 100644 index 000000000..83c8be6df --- /dev/null +++ b/skaffold.yaml @@ -0,0 +1,28 @@ +apiVersion: skaffold/v1beta2 +kind: Config +build: + artifacts: + - image: vfarcic/go-demo-6 + context: . + docker: {} + tagPolicy: + envTemplate: + template: '{{.DOCKER_REGISTRY}}/{{.IMAGE_NAME}}:{{.VERSION}}' + local: {} +deploy: + kubectl: {} +profiles: +- name: dev + build: + tagPolicy: + envTemplate: + template: '{{.DOCKER_REGISTRY}}/{{.IMAGE_NAME}}:{{.DIGEST_HEX}}' + local: {} + deploy: + helm: + releases: + - name: go-demo-6 + chartPath: charts/go-demo-6 + setValueTemplates: + image.repository: '{{.DOCKER_REGISTRY}}/{{.IMAGE_NAME}}' + image.tag: '{{.DIGEST_HEX}}' diff --git a/watch.sh b/watch.sh new file mode 100644 index 000000000..679dc7073 --- /dev/null +++ b/watch.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +# watch the go files and continously deploy the service +make linux +skaffold run -p dev +reflex -r "\.go$" -- bash -c 'make linux && skaffold run -p dev'