From 629f9735ef88c6d6fda65652ae5bc2df880441c4 Mon Sep 17 00:00:00 2001 From: Andrej Petras Date: Wed, 5 Jun 2024 18:07:53 +0200 Subject: [PATCH] feat: create project (#1) * feat: migrate adminer to onecx-develop * feat: migrate adminer to onecx-develop --- .github/changelog.yaml | 22 ++++++++ .github/workflows/build-branch.yml | 17 ++++++ .github/workflows/build-pr.yml | 14 +++++ .github/workflows/build-release.yml | 13 +++++ .github/workflows/build.yml | 23 +++++++++ .github/workflows/create-fix-branch.yml | 7 +++ .github/workflows/create-release.yml | 7 +++ helm/Chart.yaml | 12 +++++ helm/templates/_helpers.tpl | 19 +++++++ helm/templates/deployment.yaml | 33 ++++++++++++ helm/templates/ingress.yaml | 33 ++++++++++++ helm/templates/service.yaml | 18 +++++++ helm/templates/traefik-middleware.yaml | 11 ++++ helm/templates/traefik-secret.yaml | 11 ++++ helm/values.yaml | 69 +++++++++++++++++++++++++ 15 files changed, 309 insertions(+) create mode 100644 .github/changelog.yaml create mode 100644 .github/workflows/build-branch.yml create mode 100644 .github/workflows/build-pr.yml create mode 100644 .github/workflows/build-release.yml create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/create-fix-branch.yml create mode 100644 .github/workflows/create-release.yml create mode 100644 helm/Chart.yaml create mode 100644 helm/templates/_helpers.tpl create mode 100644 helm/templates/deployment.yaml create mode 100644 helm/templates/ingress.yaml create mode 100644 helm/templates/service.yaml create mode 100644 helm/templates/traefik-middleware.yaml create mode 100644 helm/templates/traefik-secret.yaml create mode 100644 helm/values.yaml diff --git a/.github/changelog.yaml b/.github/changelog.yaml new file mode 100644 index 0000000..03d84aa --- /dev/null +++ b/.github/changelog.yaml @@ -0,0 +1,22 @@ +sections: +- title: Major changes + labels: + - "release/super-feature" +- title: Complete changelog + labels: + - "bug" + - "enhancement" + - "dependencies" +template: | + Add Adminer helm chart template as dependency to Chart.yaml: + ```yaml + dependencies: + - name: adminer + alias: app + version: "{{ .Version }}" + repository: oci://ghcr.io/onecx/charts + ``` + + {{ range $section := .Sections }}{{ if $section.Items }}### {{ $section.GetTitle }}{{ range $item := $section.Items }} + * [#{{ $item.GetID }}]({{ $item.GetURL }}) - {{ $item.GetTitle }}{{ end }}{{ end }} + {{ end }} \ No newline at end of file diff --git a/.github/workflows/build-branch.yml b/.github/workflows/build-branch.yml new file mode 100644 index 0000000..75000d7 --- /dev/null +++ b/.github/workflows/build-branch.yml @@ -0,0 +1,17 @@ +name: Build Feature Branch + +on: + workflow_dispatch: + push: + branches: + - '**' + - '!main' + - '!fix/[0-9]+.[0-9]+.x' + +jobs: + helm: + uses: onecx/ci-common/.github/workflows/helm-build.yml@v1 + secrets: inherit + with: + helmDir: 'helm' + artifact: '' \ No newline at end of file diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml new file mode 100644 index 0000000..0660014 --- /dev/null +++ b/.github/workflows/build-pr.yml @@ -0,0 +1,14 @@ +name: Build Pull Request +on: + pull_request: + branches: + - 'main' + - 'fix/[0-9]+.[0-9]+.x' + +jobs: + helm: + uses: onecx/ci-common/.github/workflows/helm-build.yml@v1 + secrets: inherit + with: + helmDir: 'helm' + artifact: '' diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml new file mode 100644 index 0000000..5a2906a --- /dev/null +++ b/.github/workflows/build-release.yml @@ -0,0 +1,13 @@ +name: Build Release +on: + push: + tags: + - '**' +jobs: + helm: + uses: onecx/ci-common/.github/workflows/helm-release.yml@v1 + secrets: inherit + changelog: + uses: onecx/ci-common/.github/workflows/generate-changelog.yml@v1 + needs: helm + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..48a4ba8 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,23 @@ +name: Build +on: + workflow_dispatch: + push: + branches: + - 'main' + - 'fix/[0-9]+.[0-9]+.x' + +jobs: + helm: + uses: onecx/ci-common/.github/workflows/helm-build.yml@v1 + secrets: inherit + with: + push: true + artifact: '' + helmDir: 'helm' + templateValuesYaml: '' + helm-event: + uses: onecx/ci-product/.github/workflows/helm-send-event.yml@v1 + needs: helm + secrets: inherit + with: + targetRepository: onecx/onecx-develop \ No newline at end of file diff --git a/.github/workflows/create-fix-branch.yml b/.github/workflows/create-fix-branch.yml new file mode 100644 index 0000000..92af624 --- /dev/null +++ b/.github/workflows/create-fix-branch.yml @@ -0,0 +1,7 @@ +name: Create Fix Branch +on: + workflow_dispatch: +jobs: + fix: + uses: onecx/ci-common/.github/workflows/create-fix-branch.yml@v1 + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml new file mode 100644 index 0000000..c97eb42 --- /dev/null +++ b/.github/workflows/create-release.yml @@ -0,0 +1,7 @@ +name: Create Release Version +on: + workflow_dispatch: +jobs: + release: + uses: onecx/ci-common/.github/workflows/create-release.yml@v1 + secrets: inherit \ No newline at end of file diff --git a/helm/Chart.yaml b/helm/Chart.yaml new file mode 100644 index 0000000..009b00c --- /dev/null +++ b/helm/Chart.yaml @@ -0,0 +1,12 @@ +apiVersion: v2 +name: onecx-develop-adminer +version: 0.0.0 +appVersion: 0.0.0 +description: adminer +keywords: + - adminer +sources: + - https://github.com/onecx/onecx-develop-adminer +maintainers: + - name: Tkit Developer + email: tkit_dev@1000kit.org diff --git a/helm/templates/_helpers.tpl b/helm/templates/_helpers.tpl new file mode 100644 index 0000000..90a366d --- /dev/null +++ b/helm/templates/_helpers.tpl @@ -0,0 +1,19 @@ +{{- define "app.fullname" -}} + {{ .Release.Name }}-{{ .Values.name | default .Chart.Name }} +{{- end -}} + +{{- define "app.product.name" -}} + {{ .Release.Name }} +{{- end -}} + +{{- define "app.version" -}} + {{ .Values.image.tag }} +{{- end -}} + +{{- define "app.labels.common" -}} +version: {{ .Chart.Version | replace "+" "_" }} +adminer: {{ .Values.image.tag | quote }} +helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} +app.kubernetes.io/managed-by: {{ .Release.Service | quote }} +app.kubernetes.io/name: {{ template "app.fullname" $ }} +{{- end -}} \ No newline at end of file diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml new file mode 100644 index 0000000..50a8550 --- /dev/null +++ b/helm/templates/deployment.yaml @@ -0,0 +1,33 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "app.fullname" . }} + labels: +{{ include "app.labels.common" $ | indent 4 }} +spec: + replicas: {{ .Values.replicas }} + selector: + matchLabels: + app: {{ include "app.fullname" . }} + template: + metadata: + labels: + app: {{ include "app.fullname" . }} + spec: + {{- if .Values.imagePullSecrets }} + imagePullSecrets: + - name: {{ .Values.imagePullSecrets }} + {{- end }} + containers: + - name: {{ include "app.fullname" . }} + image: {{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }} + imagePullPolicy: {{ .Values.imagePullPolicy }} + env: + - name: ADMINER_DESIGN + value: {{ .Values.theme }} + {{- if .Values.db.server }} + - name: ADMINER_DEFAULT_SERVER + value: {{ .Values.db.server }} + {{- end }} + restartPolicy: Always + terminationGracePeriodSeconds: 30 diff --git a/helm/templates/ingress.yaml b/helm/templates/ingress.yaml new file mode 100644 index 0000000..fd3b6d2 --- /dev/null +++ b/helm/templates/ingress.yaml @@ -0,0 +1,33 @@ +{{- if .Values.routing.enabled }} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "app.fullname" . }} + labels: +{{ include "app.labels.common" $ | indent 4 }} + annotations: +{{- if .Values.traefik.middleware.auth.enabled }} + traefik.ingress.kubernetes.io/router.middlewares: {{ include "app.fullname" . }}-auth@kubernetescrd +{{- end }} +{{- if .Values.routing.ingress.annotations }} +{{ toYaml .Values.routing.ingress.annotations | indent 4 }} +{{- end }} +spec: + rules: + - http: + paths: + - path: "/" + pathType: Prefix + backend: + service: + name: {{ .Release.Name }}-{{ .Values.name | default .Chart.Name }} + port: + number: {{ .Values.service.port }} + {{ if .Values.routing.ingress.host.override }} + host: {{ .Values.routing.ingress.host.override }}.{{ .Values.global.default_url | default .Values.routing.default_url }} + {{ else if .Values.routing.ingress.host.name }} + host: {{ .Values.routing.ingress.host.name }}-{{ .Release.Namespace }}.{{ .Values.global.default_url | default .Values.routing.default_url }} + {{ else }} + host: {{ .Release.Name }}-{{ .Values.name | default .Chart.Name }}-{{ .Release.Namespace }}.{{ .Values.global.default_url | default .Values.routing.default_url }} + {{- end }} +{{ end }} diff --git a/helm/templates/service.yaml b/helm/templates/service.yaml new file mode 100644 index 0000000..f7ee33d --- /dev/null +++ b/helm/templates/service.yaml @@ -0,0 +1,18 @@ +kind: Service +apiVersion: v1 +metadata: + name: {{ include "app.fullname" . }} + labels: +{{ include "app.labels.common" $ | indent 4 }} + annotations: + description: {{ include "app.fullname" . }} +spec: + selector: + app: {{ include "app.fullname" . }} + ports: + - name: http + protocol: TCP + port: {{ .Values.service.port }} + targetPort: {{ .Values.pod.port }} + type: ClusterIP + sessionAffinity: None diff --git a/helm/templates/traefik-middleware.yaml b/helm/templates/traefik-middleware.yaml new file mode 100644 index 0000000..b48cefa --- /dev/null +++ b/helm/templates/traefik-middleware.yaml @@ -0,0 +1,11 @@ +{{- if .Values.traefik.middleware.auth.enabled }} +kind: Middleware +apiVersion: traefik.io/v1alpha1 +metadata: + name: {{ include "app.fullname" . }}-auth + labels: +{{ include "app.labels.common" $ | indent 4 }} +spec: + basicAuth: + secret: {{ include "app.fullname" . }}-auth +{{- end }} diff --git a/helm/templates/traefik-secret.yaml b/helm/templates/traefik-secret.yaml new file mode 100644 index 0000000..db1d76f --- /dev/null +++ b/helm/templates/traefik-secret.yaml @@ -0,0 +1,11 @@ +{{- if .Values.traefik.middleware.auth.enabled }} +kind: Secret +apiVersion: v1 +metadata: + name: {{ include "app.fullname" . }}-auth + labels: +{{ include "app.labels.common" $ | indent 4 }} +type: Opaque +data: + users: {{ .Values.traefik.middleware.auth.users }} +{{- end }} diff --git a/helm/values.yaml b/helm/values.yaml new file mode 100644 index 0000000..9532fa1 --- /dev/null +++ b/helm/values.yaml @@ -0,0 +1,69 @@ +# global configuration +global: + # global host name + default_url: + +# Name of the instance, default {{ .Release.Name }}-{{ .Values.name | default .Chart.Name }} +name: adminer + +# Adminer image +image: + # Docker registry + registry: "docker.io" + # Docker image + repository: "adminer" + # Docker version + tag: 4.8.1-standalone + +# service +service: + port: 8080 + +# post configuration +pod: + # pot port + port: 8080 + +imagePullPolicy: IfNotPresent + +# Route +routing: + # Enable or disable route + enabled: true + + # Default URL + default_url: "change.com" + + # ingress + ingress: + # host configuration + host: + # prio1 if the name is define generate domain . + override : + # prio2 if the name is define generate domain -. + name: + # else --. + + # aditional annotations + annotations: {} + # traefik.ingress.kubernetes.io/router.middlewares: traefik-develop-basic-auth@kubernetescrd + +# database configuration +db: + # default server + server: + +# Replicas +replicas: 1 + +# Adminer theme +theme: "pepa-linha" + +# Custom resources +traefik: + middleware: + auth: + # enable or disabel traefik middleware + enabled: true + # user:password hash + users: \ No newline at end of file