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..6628c54 --- /dev/null +++ b/charts/python/templates/deployment.yaml @@ -0,0 +1,30 @@ +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: + labels: + 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 }}" + 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..7b7097d --- /dev/null +++ b/charts/python/templates/service.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "fullname" . }} + labels: + 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: + - 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..d3090bd 100644 --- a/codefresh.yml +++ b/codefresh.yml @@ -2,26 +2,47 @@ version: '1.0' stages: - checkout - package - - test + - 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 - MyAppDockerImage: + BuildingDockerImage: title: Building Docker Image type: build + working_directory: ${{clone}} + arguments: + image_name: my-flask-app + tag: '${{CF_BRANCH_TAG_NORMALIZED}}-${{CF_SHORT_REVISION}}' + dockerfile: Dockerfile stage: package - image_name: my-app-image - working_directory: ./ - tag: v1.0.1 - dockerfile: Dockerfile - MyUnitTests: - title: Running Unit tests - image: '${{MyAppDockerImage}}' - stage: test - commands: - - pip install pytest - - pytest + deploy: + title: Storing Helm chart + 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: + 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' + - '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'