From 821f1dc6ebfb062d55e70ada77f460fadca8aa54 Mon Sep 17 00:00:00 2001 From: Tsahi Duek Date: Mon, 15 Aug 2022 14:15:36 +0100 Subject: [PATCH] Create new project: pr-test --- mypath/catalog-info.yaml | 8 ++++ mypath/django-on-app-runner/Dockerfile | 17 ++++++++ .../django-on-app-runner/K8s/deployment.yaml | 42 +++++++++++++++++++ mypath/django-on-app-runner/Makefile | 24 +++++++++++ mypath/django-on-app-runner/app.py | 18 ++++++++ mypath/django-on-app-runner/helm/.helmignore | 23 ++++++++++ mypath/django-on-app-runner/helm/Chart.yaml | 23 ++++++++++ .../helm/templates/deployment.yaml | 27 ++++++++++++ .../helm/templates/namespace.yaml | 6 +++ .../helm/templates/service.yaml | 12 ++++++ .../helm/values-prod.yaml | 34 +++++++++++++++ .../helm/values-staging.yaml | 34 +++++++++++++++ mypath/django-on-app-runner/helm/values.yaml | 35 ++++++++++++++++ mypath/django-on-app-runner/requirements.txt | 6 +++ 14 files changed, 309 insertions(+) create mode 100644 mypath/catalog-info.yaml create mode 100644 mypath/django-on-app-runner/Dockerfile create mode 100644 mypath/django-on-app-runner/K8s/deployment.yaml create mode 100644 mypath/django-on-app-runner/Makefile create mode 100644 mypath/django-on-app-runner/app.py create mode 100644 mypath/django-on-app-runner/helm/.helmignore create mode 100644 mypath/django-on-app-runner/helm/Chart.yaml create mode 100644 mypath/django-on-app-runner/helm/templates/deployment.yaml create mode 100644 mypath/django-on-app-runner/helm/templates/namespace.yaml create mode 100644 mypath/django-on-app-runner/helm/templates/service.yaml create mode 100644 mypath/django-on-app-runner/helm/values-prod.yaml create mode 100644 mypath/django-on-app-runner/helm/values-staging.yaml create mode 100644 mypath/django-on-app-runner/helm/values.yaml create mode 100644 mypath/django-on-app-runner/requirements.txt diff --git a/mypath/catalog-info.yaml b/mypath/catalog-info.yaml new file mode 100644 index 0000000..798bcec --- /dev/null +++ b/mypath/catalog-info.yaml @@ -0,0 +1,8 @@ +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: "pr-test" +spec: + type: website + lifecycle: experimental + owner: user:guest diff --git a/mypath/django-on-app-runner/Dockerfile b/mypath/django-on-app-runner/Dockerfile new file mode 100644 index 0000000..882a29b --- /dev/null +++ b/mypath/django-on-app-runner/Dockerfile @@ -0,0 +1,17 @@ +FROM alpine:latest + +RUN apk update && \ + apk add python3 + +# We copy just the requirements.txt first to leverage Docker cache +COPY ./requirements.txt /app/requirements.txt + +WORKDIR /app + +RUN pip3 install -r requirements.txt + +COPY . /app + +ENTRYPOINT [ "python3" ] + +CMD [ "app.py" ] \ No newline at end of file diff --git a/mypath/django-on-app-runner/K8s/deployment.yaml b/mypath/django-on-app-runner/K8s/deployment.yaml new file mode 100644 index 0000000..468f09b --- /dev/null +++ b/mypath/django-on-app-runner/K8s/deployment.yaml @@ -0,0 +1,42 @@ +apiVersion: v1 +kind: Service +metadata: + name: flask-http +spec: + selector: + k8s-app: flask-http + ports: + - port: 80 + targetPort: 5000 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: flask-http + namespace: default + labels: + k8s-app: flask-http +spec: + replicas: 1 + selector: + matchLabels: + k8s-app: flask-http + template: + metadata: + labels: + k8s-app: flask-http + spec: + containers: + - name: flask-http + image: tduek/flask-http:m-0.1 + imagePullPolicy: Always + ports: + - containerPort: 5000 + protocol: TCP + resources: + requests: + cpu: 500m + memory: 128Mi + limits: + cpu: 1000m + memory: 128Mi diff --git a/mypath/django-on-app-runner/Makefile b/mypath/django-on-app-runner/Makefile new file mode 100644 index 0000000..5579da5 --- /dev/null +++ b/mypath/django-on-app-runner/Makefile @@ -0,0 +1,24 @@ +REPO?=tduek +IMAGE?=flask-http +TAG?=0.1 +MULTIARCH_TAG?=m-0.1 +PLATFORMS?=linux/amd64,linux/arm64 + +all: build build-multiarch + +.PHONY: build +build: ## Build and + docker build -t $(REPO)/$(IMAGE):$(TAG) . + +.PHONY: push +push: ## + docker push $(REPO)/$(IMAGE):$(TAG) + +.PHONY: build-multiarch +build-multiarch: ## + docker buildx build --platform $(PLATFORMS) -t $(REPO)/$(IMAGE):$(MULTIARCH_TAG) --push . + +.PHONY: deploy-k8s +deploy-k8s: ## + docker buildx build --platform $(PLATFORMS) -t $(REPO)/$(IMAGE):$(MULTIARCH_TAG) --push . + diff --git a/mypath/django-on-app-runner/app.py b/mypath/django-on-app-runner/app.py new file mode 100644 index 0000000..c21b1cf --- /dev/null +++ b/mypath/django-on-app-runner/app.py @@ -0,0 +1,18 @@ +# flask_web/app.py + +from flask import Flask +app = Flask(__name__) + + +@app.route('/') +def hello_world(): + return 'Hey, we have Flask in a Docker container!' + + +@app.route('/goaway') +def goaway(): + return 'GO AWAY!' + + +if __name__ == '__main__': + app.run(debug=True, host='0.0.0.0') diff --git a/mypath/django-on-app-runner/helm/.helmignore b/mypath/django-on-app-runner/helm/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/mypath/django-on-app-runner/helm/.helmignore @@ -0,0 +1,23 @@ +# 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 +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/mypath/django-on-app-runner/helm/Chart.yaml b/mypath/django-on-app-runner/helm/Chart.yaml new file mode 100644 index 0000000..fd4ad48 --- /dev/null +++ b/mypath/django-on-app-runner/helm/Chart.yaml @@ -0,0 +1,23 @@ +apiVersion: v2 +name: mychart +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +appVersion: 1.16.0 diff --git a/mypath/django-on-app-runner/helm/templates/deployment.yaml b/mypath/django-on-app-runner/helm/templates/deployment.yaml new file mode 100644 index 0000000..0c2041b --- /dev/null +++ b/mypath/django-on-app-runner/helm/templates/deployment.yaml @@ -0,0 +1,27 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{.Values.name}}-deployment +spec: + replicas: {{int .Values.replicas}} + selector: + matchLabels: + app: {{.Values.name}} + template: + metadata: + labels: + app: {{.Values.name}} + spec: + containers: + - name: {{.Values.name}} + image: {{.Values.image}} + ports: + - containerPort: 5000 + protocol: TCP + resources: + requests: + cpu: {{.Values.resources.requests.cpu}} + memory: {{.Values.resources.requests.memory}} + limits: + cpu: {{.Values.resources.limits.cpu}} + memory: {{.Values.resources.limits.memory}} \ No newline at end of file diff --git a/mypath/django-on-app-runner/helm/templates/namespace.yaml b/mypath/django-on-app-runner/helm/templates/namespace.yaml new file mode 100644 index 0000000..135b228 --- /dev/null +++ b/mypath/django-on-app-runner/helm/templates/namespace.yaml @@ -0,0 +1,6 @@ +{{- if .Values.createNamespace}} +apiVersion: v1 +kind: Namespace +metadata: + name: {{.Values.namespace}} +{{- end}} \ No newline at end of file diff --git a/mypath/django-on-app-runner/helm/templates/service.yaml b/mypath/django-on-app-runner/helm/templates/service.yaml new file mode 100644 index 0000000..35cb7b9 --- /dev/null +++ b/mypath/django-on-app-runner/helm/templates/service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{.Values.name}}-svc +spec: + type: {{.Values.serviceType}} + ports: + - port: {{.Values.servicePort}} + targetPort: {{.Values.serviceTargetPort}} + protocol: TCP + selector: + app: {{.Values.name}} \ No newline at end of file diff --git a/mypath/django-on-app-runner/helm/values-prod.yaml b/mypath/django-on-app-runner/helm/values-prod.yaml new file mode 100644 index 0000000..d94696f --- /dev/null +++ b/mypath/django-on-app-runner/helm/values-prod.yaml @@ -0,0 +1,34 @@ +name: flask-http +replicas: 1 + +image: tduek/flask-http:m-0.1 + +createNamespace: false +namespace: flask-http-prod + +# Service Type allow you to specify what kind of service you want. +# Possible values for ServiceType are: +# ClusterIP | NodePort | LoadBalancer | ExternalName +serviceType: ClusterIP + +# A Service can map an incoming port to any targetPort. +# targetPort is where application is listening on inside the container. +servicePort: 80 +serviceTargetPort: 5000 + +resources: + requests: + cpu: 100m + memory: 128Mi + limits: + cpu: 200m + memory: 256Mi +# Specify all environment variables to be added to the container. +# The following two maps, config and secrets, are put into a ConfigMap +# and a Secret, respectively. +# Both are added to the container environment in podSpec as envFrom source. +# env: +# config: +# key1: value1 +# secrets: +# key2: value2 diff --git a/mypath/django-on-app-runner/helm/values-staging.yaml b/mypath/django-on-app-runner/helm/values-staging.yaml new file mode 100644 index 0000000..7a8e51e --- /dev/null +++ b/mypath/django-on-app-runner/helm/values-staging.yaml @@ -0,0 +1,34 @@ +name: flask-http +replicas: 1 + +image: tduek/flask-http:m-0.1 + +createNamespace: false +namespace: flask-http-staging + +# Service Type allow you to specify what kind of service you want. +# Possible values for ServiceType are: +# ClusterIP | NodePort | LoadBalancer | ExternalName +serviceType: ClusterIP + +# A Service can map an incoming port to any targetPort. +# targetPort is where application is listening on inside the container. +servicePort: 80 +serviceTargetPort: 5000 + +resources: + requests: + cpu: 100m + memory: 128Mi + limits: + cpu: 200m + memory: 256Mi +# Specify all environment variables to be added to the container. +# The following two maps, config and secrets, are put into a ConfigMap +# and a Secret, respectively. +# Both are added to the container environment in podSpec as envFrom source. +# env: +# config: +# key1: value1 +# secrets: +# key2: value2 diff --git a/mypath/django-on-app-runner/helm/values.yaml b/mypath/django-on-app-runner/helm/values.yaml new file mode 100644 index 0000000..9a4f082 --- /dev/null +++ b/mypath/django-on-app-runner/helm/values.yaml @@ -0,0 +1,35 @@ +name: flask-http +replicas: 1 + +image: tduek/flask-http:m-0.1 + +createNamespace: false +namespace: flask-http + +# Service Type allow you to specify what kind of service you want. +# Possible values for ServiceType are: +# ClusterIP | NodePort | LoadBalancer | ExternalName +serviceType: ClusterIP + +# A Service can map an incoming port to any targetPort. +# targetPort is where application is listening on inside the container. +servicePort: 80 +serviceTargetPort: 5000 + +resources: + requests: + cpu: 100m + memory: 128Mi + limits: + cpu: 200m + memory: 256Mi + +# Specify all environment variables to be added to the container. +# The following two maps, config and secrets, are put into a ConfigMap +# and a Secret, respectively. +# Both are added to the container environment in podSpec as envFrom source. +# env: +# config: +# key1: value1 +# secrets: +# key2: value2 \ No newline at end of file diff --git a/mypath/django-on-app-runner/requirements.txt b/mypath/django-on-app-runner/requirements.txt new file mode 100644 index 0000000..8730c48 --- /dev/null +++ b/mypath/django-on-app-runner/requirements.txt @@ -0,0 +1,6 @@ +Click==7.0 +Flask==1.0.2 +itsdangerous==1.1.0 +Jinja2==2.10 +MarkupSafe==1.1.1 +Werkzeug==0.15.3