From a8565b55a7f5d8e824d12fe8a3088fec24e109ad Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Thu, 5 May 2022 14:20:19 +0200 Subject: [PATCH] Fix examples --- examples/basic/README.md | 2 +- examples/basic/docker-compose.yaml | 6 ++- examples/ghost/README.md | 9 ++++ examples/ghost/chart/ghost/Chart.yaml | 8 ++++ .../ghost/chart/ghost/templates/NOTES.txt | 8 ++++ .../ghost/templates/blog.deployment.yaml | 33 +++++++++++++++ .../chart/ghost/templates/blog.ingress.yaml | 42 +++++++++++++++++++ .../chart/ghost/templates/blog.service.yaml | 19 +++++++++ examples/ghost/chart/ghost/values.yaml | 6 +++ examples/ghost/docker-compose.yaml | 30 +++++++++++++ 10 files changed, 160 insertions(+), 3 deletions(-) create mode 100644 examples/ghost/README.md create mode 100644 examples/ghost/chart/ghost/Chart.yaml create mode 100644 examples/ghost/chart/ghost/templates/NOTES.txt create mode 100644 examples/ghost/chart/ghost/templates/blog.deployment.yaml create mode 100644 examples/ghost/chart/ghost/templates/blog.ingress.yaml create mode 100644 examples/ghost/chart/ghost/templates/blog.service.yaml create mode 100644 examples/ghost/chart/ghost/values.yaml create mode 100644 examples/ghost/docker-compose.yaml diff --git a/examples/basic/README.md b/examples/basic/README.md index 893b7ee..1b3974a 100644 --- a/examples/basic/README.md +++ b/examples/basic/README.md @@ -5,6 +5,6 @@ This is a basic example of what can do Katenary with standard docker-compose fil In this example: - `depends_on` yield a `initContainer` in the webapp ddeployment to wait for database -- so we need to declare the listened port inside `database` container as we don't use it with docker-compose- also, we needed to declare that `DB_HOST` is actually a service name +- so we need to declare the listened port inside `database` container as we don't use it with docker-compose- also, we needed to declare that `DB_HOST` is actually a service name using `mapenv` label Take a look on [chart/basic](chart/basic) directory to see what `katenary convert` command has generated. diff --git a/examples/basic/docker-compose.yaml b/examples/basic/docker-compose.yaml index ce9dd35..3e9b3fc 100644 --- a/examples/basic/docker-compose.yaml +++ b/examples/basic/docker-compose.yaml @@ -1,7 +1,8 @@ version: "3" +# this example is absolutely not working, it's an example to see how it is converted +# by Katenary services: - webapp: image: php:7-apache environment: @@ -12,7 +13,8 @@ services: # expose an ingress katenary.io/ingress: 80 # DB_HOST is actually a service name - katenary.io/env-to-service: DB_HOST + katenary.io/mapenv: | + DB_HOST: {{ .Release.Name }}-database depends_on: - database diff --git a/examples/ghost/README.md b/examples/ghost/README.md new file mode 100644 index 0000000..58135d4 --- /dev/null +++ b/examples/ghost/README.md @@ -0,0 +1,9 @@ +# Example with Ghost + +[Ghost](https://ghost.org/) is a simple but powerfull blog engine. It is very nice to test some behaviors with Docker or Podman. + +The given `docker-compose.yaml` file here declares a stand-alone blog service. To help using it, we use [Patwae](https://pathwae.net) reverse-proxy to listend http://ghost.example.localhost + +The problem to solve is that the `url` environment variable correspond to the Ingress host when we will convert it to Helm Chart. So, we use the `mapenv` label to declare that `url` is actually `{{ .Values.blog.ingress.host }}` value. + +Note that we also `ignore` pathwae because we don't need it in our Helm Chart. diff --git a/examples/ghost/chart/ghost/Chart.yaml b/examples/ghost/chart/ghost/Chart.yaml new file mode 100644 index 0000000..f4732b0 --- /dev/null +++ b/examples/ghost/chart/ghost/Chart.yaml @@ -0,0 +1,8 @@ +# Create on 2022-05-05T14:16:27+02:00 +# Katenary command line: /tmp/go-build669507924/b001/exe/main convert +apiVersion: v2 +appVersion: 0.0.1 +description: A helm chart for ghost +name: ghost +type: application +version: 0.1.0 diff --git a/examples/ghost/chart/ghost/templates/NOTES.txt b/examples/ghost/chart/ghost/templates/NOTES.txt new file mode 100644 index 0000000..10ce5b3 --- /dev/null +++ b/examples/ghost/chart/ghost/templates/NOTES.txt @@ -0,0 +1,8 @@ + +Congratulations, + +Your application is now deployed. This may take a while to be up and responding. + +{{ if .Values.blog.ingress.enabled -}} +- blog is accessible on : http://{{ .Values.blog.ingress.host }} +{{- end }} diff --git a/examples/ghost/chart/ghost/templates/blog.deployment.yaml b/examples/ghost/chart/ghost/templates/blog.deployment.yaml new file mode 100644 index 0000000..6378e0d --- /dev/null +++ b/examples/ghost/chart/ghost/templates/blog.deployment.yaml @@ -0,0 +1,33 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: '{{ .Release.Name }}-blog' + labels: + katenary.io/component: blog + katenary.io/project: ghost + katenary.io/release: '{{ .Release.Name }}' + annotations: + katenary.io/docker-compose-sha1: 0c2bbf548ff569c3dc5d77dc158e98bbe86fb5d4 + katenary.io/version: master +spec: + replicas: 1 + selector: + matchLabels: + katenary.io/component: blog + katenary.io/release: '{{ .Release.Name }}' + template: + metadata: + labels: + katenary.io/component: blog + katenary.io/release: '{{ .Release.Name }}' + spec: + containers: + - name: blog + image: '{{ .Values.blog.image }}' + ports: + - name: blog + containerPort: 2368 + env: + - name: url + value: http://{{ .Values.blog.ingress.host }} + diff --git a/examples/ghost/chart/ghost/templates/blog.ingress.yaml b/examples/ghost/chart/ghost/templates/blog.ingress.yaml new file mode 100644 index 0000000..43c804d --- /dev/null +++ b/examples/ghost/chart/ghost/templates/blog.ingress.yaml @@ -0,0 +1,42 @@ +{{- if .Values.blog.ingress.enabled -}} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: '{{ .Release.Name }}-blog' + labels: + katenary.io/component: blog + katenary.io/project: ghost + katenary.io/release: '{{ .Release.Name }}' + annotations: + katenary.io/docker-compose-sha1: 0c2bbf548ff569c3dc5d77dc158e98bbe86fb5d4 + katenary.io/version: master +spec: + {{- if and .Values.blog.ingress.class (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: '{{ .Values.blog.ingress.class }}' + {{- end }} + rules: + - host: '{{ .Values.blog.ingress.host }}' + http: + paths: + - path: / + {{- if semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion }} + pathType: Prefix + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion }} + service: + name: '{{ .Release.Name }}-blog' + port: + number: 2368 + {{- else }} + serviceName: '{{ .Release.Name }}-blog' + servicePort: 2368 + {{- end }} + +{{- end -}} diff --git a/examples/ghost/chart/ghost/templates/blog.service.yaml b/examples/ghost/chart/ghost/templates/blog.service.yaml new file mode 100644 index 0000000..5c54299 --- /dev/null +++ b/examples/ghost/chart/ghost/templates/blog.service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: '{{ .Release.Name }}-blog' + labels: + katenary.io/component: blog + katenary.io/project: ghost + katenary.io/release: '{{ .Release.Name }}' + annotations: + katenary.io/docker-compose-sha1: 0c2bbf548ff569c3dc5d77dc158e98bbe86fb5d4 + katenary.io/version: master +spec: + selector: + katenary.io/component: blog + katenary.io/release: '{{ .Release.Name }}' + ports: + - protocol: TCP + port: 2368 + targetPort: 2368 diff --git a/examples/ghost/chart/ghost/values.yaml b/examples/ghost/chart/ghost/values.yaml new file mode 100644 index 0000000..6ef57af --- /dev/null +++ b/examples/ghost/chart/ghost/values.yaml @@ -0,0 +1,6 @@ +blog: + image: ghost + ingress: + class: nginx + enabled: false + host: blog.ghost.tld diff --git a/examples/ghost/docker-compose.yaml b/examples/ghost/docker-compose.yaml new file mode 100644 index 0000000..67472f7 --- /dev/null +++ b/examples/ghost/docker-compose.yaml @@ -0,0 +1,30 @@ +version: "3" + +services: + blog: + image: ghost + environment: + # this is OK for local test, but not with Helm + # because the URL depends on Ingress + url: http://ghost.example.localhost + labels: + katenary.io/ports: 2368 + katenary.io/ingress: 2368 + # ... so we declare that "url" is actually + # the ingress host + katenary.io/mapenv: | + url: http://{{ .Values.blog.ingress.host }} + + proxy: + # A simple proxy for localhost + image: quay.io/pathwae/proxy + environment: + CONFIG: | + ghost.example.localhost: + to: http://blog:2368 + ports: + - 80:80 + labels: + # we don't want this in Helm because we will use + # an ingress + katenary.io/ignore: true