diff --git a/README.md b/README.md index cf2fb5eb..90f966f6 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,9 @@ Applications, developed or curated by [mika](https://github.com/irfanhakim-as), | [cloudflareddns](https://github.com/irfanhakim-as/charts/tree/master/mika/cloudflareddns) | Access your home network remotely via a custom domain name without a static IP! | ✅ | ✅ | | [grocy](https://github.com/irfanhakim-as/charts/tree/master/mika/grocy) | Grocy is a web-based self-hosted groceries & household management solution for your home. | ✅ | ✅ | | [mango](https://github.com/irfanhakim-as/charts/tree/master/mika/mango) | Mango is an easy to use Mastodon bot framework built on top of Django. | ✅ | 🔒 | +| [mariadb-agent](https://github.com/irfanhakim-as/charts/tree/master/mika/mariadb-agent) | Easily create or delete multiple pairs of databases and users in a remote MariaDB instance. | ✅ | ✅ | | [postgres](https://github.com/irfanhakim-as/charts/tree/master/mika/postgres) | Easy tool to deploy a PostgreSQL instance on Kubernetes. | ✅ | ✅ | -| [postgres-agent](https://github.com/irfanhakim-as/charts/tree/master/mika/postgres-agent) | Easily deploy a database and create a user, or delete a database in a remote PostgreSQL instance. | ✅ | ✅ | +| [postgres-agent](https://github.com/irfanhakim-as/charts/tree/master/mika/postgres-agent) | Easily create or delete a database and user pair in a remote PostgreSQL instance. | ✅ | ✅ | | [rizz](https://github.com/irfanhakim-as/charts/tree/master/mika/rizz) | Rizz is a simple web application that tracks and posts content from RSS Feeds to Mastodon. | ✅ | 🔒 | | [telego](https://github.com/irfanhakim-as/charts/tree/master/mika/telego) | Telego is an easy to use Telegram bot framework built on top of Django. | ✅ | 🔒 | | [vpbot](https://github.com/irfanhakim-as/charts/tree/master/mika/vpbot) | Vpbot is a Telegram bot with support for a number of useful features such as prayer time notifications, COVID-19 statistics, and more. | ✅ | 🔒 | diff --git a/logos/clog.png b/logos/clog.png old mode 100755 new mode 100644 diff --git a/logos/mariadb.png b/logos/mariadb.png new file mode 100644 index 00000000..31050fab Binary files /dev/null and b/logos/mariadb.png differ diff --git a/logos/mika.png b/logos/mika.png old mode 100755 new mode 100644 diff --git a/logos/postgres.png b/logos/postgres.png old mode 100755 new mode 100644 diff --git a/logos/vpbot.png b/logos/vpbot.png old mode 100755 new mode 100644 diff --git a/mika/clog/Chart.yaml b/mika/clog/Chart.yaml index fc824c01..267dad4a 100644 --- a/mika/clog/Chart.yaml +++ b/mika/clog/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: clog description: Creative blog, Career blog, Coin blog, you name it. type: application -version: 0.2.2 -appVersion: "0.0.1-stable" +version: 0.2.3 +appVersion: "0.0.2-stable-r1" keywords: - "clog" - "blog" diff --git a/mika/clog/templates/deployment.yaml b/mika/clog/templates/deployment.yaml index 68fd80de..c30bc0c6 100644 --- a/mika/clog/templates/deployment.yaml +++ b/mika/clog/templates/deployment.yaml @@ -45,34 +45,6 @@ spec: protocol: TCP resources: {{- toYaml .Values.resources.clog | nindent 12 }} - env: - {{- if or $cloudflared $ingress }} - - name: ALLOWED_HOSTS - valueFrom: - configMapKeyRef: - name: {{ .Release.Name }}-clog-cm - key: DOMAIN - {{- end }} - - name: POSTGRES_HOST - valueFrom: - secretKeyRef: - name: {{ .Release.Name }}-clog-postgres-secret - key: DB_HOST - - name: POSTGRES_DB - valueFrom: - secretKeyRef: - name: {{ .Release.Name }}-clog-postgres-secret - key: DB_NAME - - name: POSTGRES_USER - valueFrom: - secretKeyRef: - name: {{ .Release.Name }}-clog-postgres-secret - key: DB_USER - - name: POSTGRES_PASSWORD - valueFrom: - secretKeyRef: - name: {{ .Release.Name }}-clog-postgres-secret - key: DB_PASS envFrom: - configMapRef: name: {{ .Release.Name }}-clog-cm diff --git a/mika/clog/templates/ingress.yaml b/mika/clog/templates/ingress.yaml index 9aed6569..8ec71ae0 100644 --- a/mika/clog/templates/ingress.yaml +++ b/mika/clog/templates/ingress.yaml @@ -1,7 +1,7 @@ {{- $ingress := .Values.clog.ingress.enabled }} {{- if $ingress }} {{- $cluster_issuer := .Values.clog.ingress.clusterIssuer | default "letsencrypt-dns-prod" | toString | quote }} -{{- $domain = .Values.clog.ingress.domain | default "localhost" | toString }} +{{- $domain := .Values.clog.ingress.domain | default "localhost" | toString }} apiVersion: networking.k8s.io/v1 kind: Ingress metadata: diff --git a/mika/clog/templates/secret.yaml b/mika/clog/templates/secret.yaml index cd220b13..5ea5021d 100644 --- a/mika/clog/templates/secret.yaml +++ b/mika/clog/templates/secret.yaml @@ -19,15 +19,6 @@ data: {{- if $ngrok }} NGROK_AUTH_TOKEN: {{ $token }} {{- end }} ---- -apiVersion: v1 -kind: Secret -metadata: - name: {{ .Release.Name }}-clog-postgres-secret - labels: - {{- include "clog.labels" . | nindent 4 }} -type: Opaque -data: DB_TYPE: {{ $db_type }} DB_NAME: {{ $db_name }} DB_USER: {{ $db_user }} diff --git a/mika/mariadb-agent/.helmignore b/mika/mariadb-agent/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/mika/mariadb-agent/.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/mika/mariadb-agent/Chart.yaml b/mika/mariadb-agent/Chart.yaml new file mode 100644 index 00000000..a067d247 --- /dev/null +++ b/mika/mariadb-agent/Chart.yaml @@ -0,0 +1,19 @@ +apiVersion: v2 +name: mariadb-agent +description: Easily create or delete multiple pairs of databases and users in a remote MariaDB instance. +type: application +version: 0.1.0 +appVersion: "11.1.3-debian-11-r0" +keywords: + - "mariadb" + - "mysql" + - "agent" + - "job" +home: "https://github.com/irfanhakim-as/charts" +icon: "https://irfanhakim-as.github.io/charts/logos/mariadb.png" +sources: + - "https://github.com/irfanhakim-as/charts" +maintainers: + - name: "Irfan Hakim" + email: "irfanhakim.as@yahoo.com" + url: "https://github.com/irfanhakim-as" diff --git a/mika/mariadb-agent/README.md b/mika/mariadb-agent/README.md new file mode 100644 index 00000000..d63bc6e7 --- /dev/null +++ b/mika/mariadb-agent/README.md @@ -0,0 +1,85 @@ +# [`mariadb-agent`](https://github.com/mariadb/mariadb) + +## Prerequisites + +- Kubernetes 1.19+ +- Helm 3.2.0+ + +## Preflight checklist + +## How to add repo + +Add the repo to your local helm client. + +```sh +helm repo add mika https://irfanhakim-as.github.io/charts +``` + +Update the repo to retrieve the latest versions of the packages. + +```sh +helm repo update +``` + +## How to install + +### Prepare MariaDB host + +Install [`bitnami/mariadb`](https://github.com/bitnami/charts/tree/main/bitnami/mariadb). This step can be skipped if you have an existing MariaDB server. + +### Prepare chart values + +Copy `values.yaml` from the chart you would like to install. Refer to the [Configurations](#configurations) section for more information. + +```sh +cp mika/mariadb-agent/values.yaml . +``` + +Edit `values.yaml` with the appropriate values. Refer to the [Configurations](#Configurations) section for available options. + +```sh +nano values.yaml +``` + +### Perform installation + +Install the desired chart. Replace `$release_name` and `$namespace` accordingly. + +```sh +helm install $release_name mika/mariadb-agent --namespace $namespace --create-namespace --values values.yaml --wait +``` + +Verify that your chart has been installed. Replace `$namespace` and `$release_name` accordingly. + +```sh +helm ls --namespace $namespace | grep "$release_name" +``` + +## How to upgrade + +After making any necessary changes to the `values.yaml` file, upgrade the desired chart. Replace `$release_name` and `$namespace` accordingly. + +```sh +helm upgrade $release_name mika/mariadb-agent --namespace $namespace --values values.yaml --wait +``` + +## How to uninstall + +Uninstall the desired chart. Replace `$release_name` and `$namespace` accordingly. + +```sh +helm uninstall $release_name --namespace $namespace --wait +``` + +## Configurations + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| image.mariadb.pullPolicy | string | `""` | The policy that determines when Kubernetes should pull the MariaDB container image. Default: `"IfNotPresent"`. | +| image.mariadb.registry | string | `""` | The registry where the MariaDB container image is hosted. Default: `"docker.io"`. | +| image.mariadb.repository | string | `""` | The name of the repository that contains the MariaDB container image used. Default: `"bitnami/mariadb"`. | +| image.mariadb.tag | string | `""` | The tag that specifies the version of the MariaDB container image used. Default: `Chart appVersion`. | +| mariadb.databases | list | `[]` | Database configurations array. Elements: `.name`, `.user`, `.password`, `.create`, `.drop`, `.custom_command`. | +| mariadb.host | string | `""` | The hostname or IP address of the MariaDB database server. | +| mariadb.root.password | string | `""` | The password associated with the MariaDB database server root user. | +| mariadb.root.user | string | `""` | The username or user account for accessing the MariaDB database server as root. Default: `"root"`. | diff --git a/mika/mariadb-agent/templates/NOTES.txt b/mika/mariadb-agent/templates/NOTES.txt new file mode 100644 index 00000000..e3f9ee05 --- /dev/null +++ b/mika/mariadb-agent/templates/NOTES.txt @@ -0,0 +1,5 @@ +mariadb-agent job has been deployed for {{ .Release.Name | toString }}. + +See the values.yaml file of this chart for more configuration options. + +Please refer to the official documentation for more information on how to use mariadb-agent. diff --git a/mika/mariadb-agent/templates/_helpers.tpl b/mika/mariadb-agent/templates/_helpers.tpl new file mode 100644 index 00000000..b23a9dc6 --- /dev/null +++ b/mika/mariadb-agent/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "mariadb-agent.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). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "mariadb-agent.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "mariadb-agent.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "mariadb-agent.labels" -}} +helm.sh/chart: {{ include "mariadb-agent.chart" . }} +{{ include "mariadb-agent.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "mariadb-agent.selectorLabels" -}} +app.kubernetes.io/name: {{ include "mariadb-agent.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "mariadb-agent.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "mariadb-agent.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/mika/mariadb-agent/templates/deployment.yaml b/mika/mariadb-agent/templates/deployment.yaml new file mode 100644 index 00000000..2e712a59 --- /dev/null +++ b/mika/mariadb-agent/templates/deployment.yaml @@ -0,0 +1,55 @@ +{{- $host := .Values.mariadb.host | default "mariadb" | toString }} +{{- $registry := .Values.image.mariadb.registry | default "docker.io" | toString }} +{{- $repository := .Values.image.mariadb.repository | default "bitnami/mariadb" | toString }} +{{- $tag := .Values.image.mariadb.tag | default .Chart.AppVersion | toString }} +{{- $pullPolicy := .Values.image.mariadb.pullPolicy | default "IfNotPresent" | toString | quote }} +{{- $databases := .Values.mariadb.databases }} +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ printf "%s-%s-%s" (index (splitList "." $host) 0) .Release.Name "mariadb-agent" }} + labels: + {{- include "mariadb-agent.labels" . | nindent 4 }} +spec: + ttlSecondsAfterFinished: 120 + backoffLimit: 0 + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "mariadb-agent.selectorLabels" . | nindent 8 }} + spec: + containers: + - name: mariadb-agent + image: {{ printf "%s/%s:%s" $registry $repository $tag | quote }} + imagePullPolicy: {{ $pullPolicy }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + command: ["/bin/bash"] + args: + - -c + - >- + mysql -h $(DB_HOST) -u $(ROOT_USER) -e ' + {{- range $databases }} + {{- if .create }} + CREATE DATABASE IF NOT EXISTS {{ .name }}; + CREATE USER IF NOT EXISTS "{{ .user }}"@"%"; + SET PASSWORD FOR "{{ .user }}"@"%" = PASSWORD("{{ .password }}"); + GRANT ALL PRIVILEGES ON {{ .name }}.* TO "{{ .user }}"@"%"; + {{- else if .drop }} + DROP DATABASE IF EXISTS {{ .name }}; + DROP USER IF EXISTS "{{ .user }}"@"%"; + {{- end }} + {{- if .custom_command }} + {{- .custom_command | replace "$.name" .name | replace "$.user" .user | replace "$.password" .password | nindent 16 }} + {{- end }} + {{- end }} + FLUSH PRIVILEGES; + ' + envFrom: + - secretRef: + name: {{ .Release.Name }}-mariadb-agent-secret + restartPolicy: Never diff --git a/mika/mariadb-agent/templates/secret.yaml b/mika/mariadb-agent/templates/secret.yaml new file mode 100644 index 00000000..a49a755a --- /dev/null +++ b/mika/mariadb-agent/templates/secret.yaml @@ -0,0 +1,14 @@ +{{- $db_host := .Values.mariadb.host | toString | b64enc }} +{{- $root_user := .Values.mariadb.root.user | default "root" | toString | b64enc }} +{{- $root_password := .Values.mariadb.root.password | toString | b64enc }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ .Release.Name }}-mariadb-agent-secret + labels: + {{- include "mariadb-agent.labels" . | nindent 4 }} +type: Opaque +data: + DB_HOST: {{ $db_host }} + ROOT_USER: {{ $root_user }} + MYSQL_PWD: {{ $root_password }} diff --git a/mika/mariadb-agent/values.yaml b/mika/mariadb-agent/values.yaml new file mode 100644 index 00000000..acbaafc9 --- /dev/null +++ b/mika/mariadb-agent/values.yaml @@ -0,0 +1,64 @@ +# Default values for mariadb-agent. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +# Container image used for MariaDB. +image: + # MariaDB container image configurations. + mariadb: + # The registry where the MariaDB container image is hosted. + # Default: "docker.io" + registry: "" + # The name of the repository that contains the MariaDB container image used. + # Default: "bitnami/mariadb" + repository: "" + # The tag that specifies the version of the MariaDB container image used. + # Default: Chart appVersion + tag: "" + # The policy that determines when Kubernetes should pull the MariaDB container image. + # Default: "IfNotPresent" + pullPolicy: "" + +# MariaDB configurations. +mariadb: + # Database configurations array. + # Elements: `.name`, `.user`, `.password`, `.create`, `.drop`, `.custom_command`. + # .name: The name of the intended MariaDB database. + # .user: The username or user account for accessing the intended MariaDB database. + # .password: The password associated with the intended MariaDB database user. + # .create: Specifies whether to create the database and user in the remote MariaDB instance. + # .drop: Specifies whether to delete the database and user in the remote MariaDB instance. + # .custom_command: Specify a custom command to run against the remote MariaDB instance. + # Example: + # databases: + # - name: "mariadb" + # user: "mariadbuser" + # password: "mariadbuserpassword" + # create: true + # drop: false + # custom_command: >- + # CREATE TABLE IF NOT EXISTS `$.name`.`StorageRecords` ( + # `id` int(11) NOT NULL AUTO_INCREMENT, + # `key` varchar(255) NOT NULL, + # `value` text NOT NULL, + # `created_at` datetime NOT NULL, + # `updated_at` datetime NOT NULL, + # PRIMARY KEY (`id`), + # UNIQUE KEY `key` (`key`) + # ); + databases: [] + # The hostname or IP address of the MariaDB database server. + # Example: + # host: "mariadb.default.svc.cluster.local" + host: "" + # MariaDB database server root user configurations. + root: + # The username or user account for accessing the MariaDB database server as root. + # Default: "root" + # Example: + # user: "root" + user: "" + # The password associated with the MariaDB database server root user. + # Example: + # password: "password" + password: "" diff --git a/mika/postgres-agent/Chart.yaml b/mika/postgres-agent/Chart.yaml index 849b41bb..3c66d261 100644 --- a/mika/postgres-agent/Chart.yaml +++ b/mika/postgres-agent/Chart.yaml @@ -1,8 +1,8 @@ apiVersion: v2 name: postgres-agent -description: Easily deploy a database and create a user, or delete a database in a remote PostgreSQL instance. +description: Easily create or delete a database and user pair in a remote PostgreSQL instance. type: application -version: 0.2.1 +version: 0.2.2 appVersion: "13.3" keywords: - "postgresql" diff --git a/mika/postgres-agent/README.md b/mika/postgres-agent/README.md index 7531e8b1..44f9aa8f 100644 --- a/mika/postgres-agent/README.md +++ b/mika/postgres-agent/README.md @@ -81,7 +81,7 @@ helm uninstall $release_name --namespace $namespace --wait | image.postgres.tag | string | `""` | The tag that specifies the version of the PostgreSQL container image used. Default: `Chart appVersion`. | | postgres.host | string | `""` | The hostname or IP address of the PostgreSQL database server. | | postgres.mode.create | bool | `true` | Specifies whether to create a database and user in a remote PostgreSQL instance. | -| postgres.mode.drop | bool | `false` | Specifies whether to delete a database in a remote PostgreSQL instance. | +| postgres.mode.drop | bool | `false` | Specifies whether to delete a database and user in a remote PostgreSQL instance. | | postgres.name | string | `""` | The name of the intended PostgreSQL database. | | postgres.password | string | `""` | The password associated with the intended PostgreSQL database user. | | postgres.root.password | string | `""` | The password associated with the PostgreSQL database server root user. | diff --git a/mika/postgres-agent/values.yaml b/mika/postgres-agent/values.yaml index 6abb0720..00a29d85 100644 --- a/mika/postgres-agent/values.yaml +++ b/mika/postgres-agent/values.yaml @@ -27,7 +27,7 @@ postgres: # Example: # create: false create: true - # Specifies whether to delete a database in a remote PostgreSQL instance. + # Specifies whether to delete a database and user in a remote PostgreSQL instance. # Example: # drop: true drop: false