From 5954aa270388c3b6688c469f5f01fc8900043119 Mon Sep 17 00:00:00 2001 From: Kostis Kapelonis Date: Thu, 12 Jul 2018 06:01:05 -0400 Subject: [PATCH 1/5] Sample helm chart --- .dockerignore | 3 ++- Dockerfile | 1 + charts/python/.helmignore | 21 +++++++++++++++ charts/python/Chart.yaml | 4 +++ charts/python/templates/NOTES.txt | 15 +++++++++++ charts/python/templates/_helpers.tpl | 16 +++++++++++ charts/python/templates/deployment.yaml | 25 ++++++++++++++++++ charts/python/templates/ingress.yaml | 17 ++++++++++++ charts/python/templates/service.yaml | 15 +++++++++++ charts/python/values.yaml | 22 ++++++++++++++++ codefresh.yml | 35 ++++++++++++++----------- 11 files changed, 158 insertions(+), 16 deletions(-) create mode 100755 charts/python/.helmignore create mode 100644 charts/python/Chart.yaml create mode 100755 charts/python/templates/NOTES.txt create mode 100755 charts/python/templates/_helpers.tpl create mode 100755 charts/python/templates/deployment.yaml create mode 100755 charts/python/templates/ingress.yaml create mode 100755 charts/python/templates/service.yaml create mode 100755 charts/python/values.yaml diff --git a/.dockerignore b/.dockerignore index 191381e..d436eab 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,2 @@ -.git \ No newline at end of file +.git + diff --git a/Dockerfile b/Dockerfile index 859f5fa..07a6430 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,7 @@ RUN flask init-db EXPOSE 5000 + CMD [ "flask", "run", "--host=0.0.0.0" ] diff --git a/charts/python/.helmignore b/charts/python/.helmignore new file mode 100755 index 0000000..f0c1319 --- /dev/null +++ b/charts/python/.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/python/Chart.yaml b/charts/python/Chart.yaml new file mode 100644 index 0000000..92028dd --- /dev/null +++ b/charts/python/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: A Helm chart for Kubernetes +name: python +version: v0.3.0 diff --git a/charts/python/templates/NOTES.txt b/charts/python/templates/NOTES.txt new file mode 100755 index 0000000..da948fa --- /dev/null +++ b/charts/python/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/python/templates/_helpers.tpl b/charts/python/templates/_helpers.tpl new file mode 100755 index 0000000..f0d83d2 --- /dev/null +++ b/charts/python/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/python/templates/deployment.yaml b/charts/python/templates/deployment.yaml new file mode 100755 index 0000000..9139f99 --- /dev/null +++ b/charts/python/templates/deployment.yaml @@ -0,0 +1,25 @@ +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: + annotations: + buildID: {{ .Values.buildID }} + labels: + draft: {{ default "draft-app" .Values.draft }} + app: {{ template "fullname" . }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - containerPort: {{ .Values.service.internalPort }} + resources: +{{ toYaml .Values.resources | indent 12 }} diff --git a/charts/python/templates/ingress.yaml b/charts/python/templates/ingress.yaml new file mode 100755 index 0000000..974e6f6 --- /dev/null +++ b/charts/python/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/python/templates/service.yaml b/charts/python/templates/service.yaml new file mode 100755 index 0000000..d524c8b --- /dev/null +++ b/charts/python/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "fullname" . }} + labels: + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.externalPort }} + targetPort: {{ .Values.service.internalPort }} + protocol: TCP + name: {{ .Values.service.name }} + selector: + app: {{ template "fullname" . }} diff --git a/charts/python/values.yaml b/charts/python/values.yaml new file mode 100755 index 0000000..5de3ee1 --- /dev/null +++ b/charts/python/values.yaml @@ -0,0 +1,22 @@ +# Default values for python. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +replicaCount: 1 +image: + pullPolicy: IfNotPresent + repository: r.cfcr.io/kostis-codefresh/kostis-codefresh/python-flask-sampleapp + tag: master +service: + name: python + type: LoadBalancer + externalPort: 80 + internalPort: 5000 +resources: + limits: + cpu: 100m + memory: 128Mi + requests: + cpu: 100m + memory: 128Mi +ingress: + enabled: false diff --git a/codefresh.yml b/codefresh.yml index 2f1b929..7db0651 100644 --- a/codefresh.yml +++ b/codefresh.yml @@ -1,8 +1,4 @@ version: '1.0' -stages: - - checkout - - package - - test steps: main_clone: title: Cloning main repository... @@ -10,18 +6,27 @@ steps: repo: '${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}' revision: '${{CF_REVISION}}' stage: checkout - MyAppDockerImage: + BuildingDockerImage: title: Building Docker Image type: build - stage: package - image_name: my-app-image + image_name: kostis-codefresh/python-flask-sampleapp working_directory: ./ - tag: v1.0.1 + tag: '${{CF_BRANCH_TAG_NORMALIZED}}-${{CF_SHORT_REVISION}}' dockerfile: Dockerfile - MyUnitTests: - title: Running Unit tests - image: '${{MyAppDockerImage}}' - stage: test - commands: - - pip install pytest - - pytest + # Requires importing of shared configuration for the private Helm repository + StoreChart: + title: Storing Helm chart + image: 'codefresh/cfstep-helm:2.9.1' + environment: + - ACTION=push + - CHART_REF=charts/python + DeployMyChart: + image: 'codefresh/cfstep-helm:2.9.1' + title: Deploying Helm chart + environment: + - CHART_REF=charts/python + - RELEASE_NAME=mypython-chart-prod + - KUBE_CONTEXT=myDemoAKSCluster + - VALUE_image_pullPolicy=Always + - VALUE_image_tag='${{CF_BRANCH_TAG_NORMALIZED}}-${{CF_SHORT_REVISION}}' + From 793a17033b7db845366b3553f1640db1c5858efd Mon Sep 17 00:00:00 2001 From: Kostis Kapelonis Date: Sat, 7 Mar 2020 19:14:28 +0200 Subject: [PATCH 2/5] Helm 3 changes: --- charts/python/templates/deployment.yaml | 2 ++ charts/python/templates/service.yaml | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/charts/python/templates/deployment.yaml b/charts/python/templates/deployment.yaml index 9139f99..8a3decf 100755 --- a/charts/python/templates/deployment.yaml +++ b/charts/python/templates/deployment.yaml @@ -15,6 +15,8 @@ spec: draft: {{ default "draft-app" .Values.draft }} app: {{ template "fullname" . }} spec: + imagePullSecrets: + - name: {{ .Values.image.pullSecret }} containers: - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" diff --git a/charts/python/templates/service.yaml b/charts/python/templates/service.yaml index d524c8b..7b7097d 100755 --- a/charts/python/templates/service.yaml +++ b/charts/python/templates/service.yaml @@ -3,7 +3,10 @@ kind: Service metadata: name: {{ template "fullname" . }} labels: - chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + app.kubernetes.io/name: "{{ template "name" . }}" + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + app.kubernetes.io/managed-by: "{{ .Release.Service }}" + app.kubernetes.io/instance: "{{ .Release.Name }}" spec: type: {{ .Values.service.type }} ports: From bb3b287b14a5debf6b2b73071b69b3f04580148a Mon Sep 17 00:00:00 2001 From: "Kostis (Codefresh)" <39800303+kostis-codefresh@users.noreply.github.com> Date: Mon, 18 May 2020 21:08:40 +0300 Subject: [PATCH 3/5] Update codefresh.yml for Helm 3 --- codefresh.yml | 60 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/codefresh.yml b/codefresh.yml index 7db0651..60ce7c7 100644 --- a/codefresh.yml +++ b/codefresh.yml @@ -1,32 +1,48 @@ version: '1.0' +stages: + - checkout + - package + - deploy steps: - main_clone: + clone: title: Cloning main repository... type: git-clone - repo: '${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}' - revision: '${{CF_REVISION}}' + arguments: + repo: '${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}' + revision: '${{CF_REVISION}}' stage: checkout BuildingDockerImage: title: Building Docker Image type: build - image_name: kostis-codefresh/python-flask-sampleapp - working_directory: ./ - tag: '${{CF_BRANCH_TAG_NORMALIZED}}-${{CF_SHORT_REVISION}}' - dockerfile: Dockerfile - # Requires importing of shared configuration for the private Helm repository - StoreChart: + working_directory: ${{clone}} + arguments: + image_name: my-flask-app + tag: '${{CF_BRANCH_TAG_NORMALIZED}}-${{CF_SHORT_REVISION}}' + dockerfile: Dockerfile + stage: package + deploy: title: Storing Helm chart - image: 'codefresh/cfstep-helm:2.9.1' - environment: - - ACTION=push - - CHART_REF=charts/python + type: helm + stage: deploy + working_directory: ./python-flask-sample-app + arguments: + action: push + chart_name: charts/python + helm_version: 3.0.2 + kube_context: 'mydemoAkscluster@BizSpark Plus' DeployMyChart: - image: 'codefresh/cfstep-helm:2.9.1' - title: Deploying Helm chart - environment: - - CHART_REF=charts/python - - RELEASE_NAME=mypython-chart-prod - - KUBE_CONTEXT=myDemoAKSCluster - - VALUE_image_pullPolicy=Always - - VALUE_image_tag='${{CF_BRANCH_TAG_NORMALIZED}}-${{CF_SHORT_REVISION}}' - + type: helm + stage: deploy + working_directory: ./python-flask-sample-app + arguments: + action: install + chart_name: charts/python + release_name: my-python-chart + helm_version: 3.0.2 + kube_context: 'mydemoAkscluster@BizSpark Plus' + custom_values: + - 'buildID=${{CF_BUILD_ID}}' + - 'image_pullPolicy=Always' + - 'repository=r.cfcr.io/kostis-codefresh/my-flask-app' + - 'image_tag=${{CF_BRANCH_TAG_NORMALIZED}}-${{CF_SHORT_REVISION}}' + - 'image_pullSecret=codefresh-generated-r.cfcr.io-cfcr-default' From 47934a70ecbe29ed9ed187f1bedb50a236cad702 Mon Sep 17 00:00:00 2001 From: TedSpinks Date: Sun, 11 Oct 2020 22:44:15 -0400 Subject: [PATCH 4/5] Update with-helm branch with various bugfixes - Update apiVersion in deployment.yaml to work with new versions of K8s - Add missing selector block to deployment.yaml - Fix bad custom_value key in codefresh.yml (repository -> image_repository) --- charts/python/templates/deployment.yaml | 6 +++++- codefresh.yml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/charts/python/templates/deployment.yaml b/charts/python/templates/deployment.yaml index 8a3decf..b111d29 100755 --- a/charts/python/templates/deployment.yaml +++ b/charts/python/templates/deployment.yaml @@ -1,12 +1,16 @@ -apiVersion: extensions/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: {{ template "fullname" . }} labels: draft: {{ default "draft-app" .Values.draft }} chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + app: {{ template "fullname" . }} spec: replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app: {{ template "fullname" . }} template: metadata: annotations: diff --git a/codefresh.yml b/codefresh.yml index 60ce7c7..d3090bd 100644 --- a/codefresh.yml +++ b/codefresh.yml @@ -43,6 +43,6 @@ steps: custom_values: - 'buildID=${{CF_BUILD_ID}}' - 'image_pullPolicy=Always' - - 'repository=r.cfcr.io/kostis-codefresh/my-flask-app' + - 'image_repository=r.cfcr.io/kostis-codefresh/my-flask-app' - 'image_tag=${{CF_BRANCH_TAG_NORMALIZED}}-${{CF_SHORT_REVISION}}' - 'image_pullSecret=codefresh-generated-r.cfcr.io-cfcr-default' From d60eac210457b2cc73cb45da55699d12c1577a17 Mon Sep 17 00:00:00 2001 From: hseligson1 Date: Wed, 15 Sep 2021 18:44:57 -0400 Subject: [PATCH 5/5] Update deployment.yaml Removed buildID from deployment.yaml on with-helm --- charts/python/templates/deployment.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/charts/python/templates/deployment.yaml b/charts/python/templates/deployment.yaml index b111d29..6628c54 100755 --- a/charts/python/templates/deployment.yaml +++ b/charts/python/templates/deployment.yaml @@ -14,7 +14,6 @@ spec: template: metadata: annotations: - buildID: {{ .Values.buildID }} labels: draft: {{ default "draft-app" .Values.draft }} app: {{ template "fullname" . }}