Skip to content

Commit

Permalink
feat: update apollo chart.
Browse files Browse the repository at this point in the history
  • Loading branch information
dellnoantechnp committed Jul 12, 2024
1 parent 62c12d7 commit 39163a7
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 18 deletions.
2 changes: 1 addition & 1 deletion charts/apollo/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ maintainers:
url: https://github.com/dellnoantechnp/helm-chart-xxl-job-admin
name: apollo
type: application
version: 0.7.2
version: 0.8.0
dependencies:
- name: common
repository: oci://registry-1.docker.io/bitnamicharts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ data:
apollo.admin-service.url = {{ include "apollo.adminService.serviceUrl" .}}
{{- if .Values.configService.config.contextPath }}
server.servlet.context-path = {{ .Values.configService.config.contextPath }}
{{- end }}
{{- end }}
{{- if .Values.db.configdb.autoInitDatabase.enabled }}
init-database.sql: |
{{- .Files.Get "init-db/apolloconfigdb.sql" | nindent 4 }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,51 @@ spec:
items:
- key: application-github.properties
path: application-github.properties
{{- if .Values.db.configdb.autoInitDatabase.enabled }}
- key: init-database.sql
path: init-database.sql
{{- end }}
defaultMode: 420
{{- if .Values.db.configdb.autoInitDatabase.enabled }}
initContainers:
- name: init-database
image: "{{ .Values.db.configdb.autoInitDatabase.initContainer.registry }}/{{ .Values.db.configdb.autoInitDatabase.initContainer.repository }}:{{ .Values.db.configdb.autoInitDatabase.initContainer.tag }}"
env:
- name: MYSQL_HOST
value: {{ .Values.db.configdb.host }}
command:
- bash
- "-ec"
args:
- |
echo "INFO: Start to init database."
cat > /tmp/.my.cnf << EOF
[client]
host={{ .Values.db.configdb.host }}
user={{ .Values.db.configdb.userName | quote }}
password={{ .Values.db.configdb.password | quote }}
database={{ .Values.db.configdb.dbName }}
EOF
echo "INFO: Checking the database, if it's exist ..."
if mysql --defaults-file=/tmp/.my.cnf -E --connect-timeout=30 -w -e 'SHOW TABLES FROM {{ .Values.db.configdb.dbName }}' | grep -q : ; then
echo "INFO: {{ .Values.db.configdb.dbName }} was exists. skipping to initial SQL table."
else
#if [[ $? -eq 1 ]]; then
echo "INFO: {{ .Values.db.configdb.dbName }} is not exists. creating and init SQL file ..."
echo "INFO: CREATE DATABASE"
mysql --defaults-file=/tmp/.my.cnf -E --connect-timeout=30 -w -e 'CREATE DATABASE "{{ .Values.db.configdb.dbName }}" DEFAULT CHARSET utf8mb4'
echo "INFO: CREATE TABLES"
mysql --defaults-file=/tmp/.my.cnf -E --connect-timeout=30 -w {{ .Values.db.configdb.dbName }} < /docker-entrypoint-initdb.d/init-database.sql
fi
echo "INFO: starting app container ..."
volumeMounts:
- name: volume-configmap-{{ $configServiceFullName }}
mountPath: /tmp/application-github.properties
subPath: application-github.properties
- name: volume-configmap-{{ $configServiceFullName }}
mountPath: /docker-entrypoint-initdb.d/init-database.sql
subPath: init-database.sql
{{- end }}
containers:
- name: {{ .Values.configService.name }}
image: "{{ .Values.configService.image.repository }}:{{ .Values.configService.image.tag | default .Chart.AppVersion }}"
Expand Down
15 changes: 11 additions & 4 deletions charts/apollo/templates/portal/configmap-portal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ data:
{{- range $env, $address := .Values.portal.config.metaServers }}
{{ $env }}.meta = {{ $address }}
{{- end }}
{{- range $fileName, $content := .Values.portal.config.files }}
{{ $fileName | indent 2 }}: |
{{ $content | indent 4 }}
{{- end }}
{{- if not .Values.portal.config.metaServers }}
{{ .Values.portal.config.envs }}: {{ include "apollo.configService.serviceUrl" . }}{{ .Values.configService.config.contextPath }}
{{- end }}
{{- range $fileName, $content := .Values.portal.config.files }}
{{ $fileName | nindent 4 }}: |
{{ $content | nindent 4 }}
{{- end }}
{{- if .Values.db.portaldb.autoInitDatabase.enabled }}
init-database.sql: |
{{- .Files.Get "init-db/apolloportaldb.sql" | nindent 4 }}
{{- end }}
{{- end }}
44 changes: 44 additions & 0 deletions charts/apollo/templates/portal/deployment-portal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,51 @@ spec:
- key: {{ $fileName }}
path: {{ $fileName }}
{{- end }}
{{- if .Values.db.portaldb.autoInitDatabase.enabled }}
- key: init-database.sql
path: init-database.sql
{{- end }}
defaultMode: 420
{{- if .Values.db.portaldb.autoInitDatabase.enabled }}
initContainers:
- name: init-database
image: "{{ .Values.db.portaldb.autoInitDatabase.initContainer.registry }}/{{ .Values.db.portaldb.autoInitDatabase.initContainer.repository }}:{{ .Values.db.portaldb.autoInitDatabase.initContainer.tag }}"
env:
- name: MYSQL_HOST
value: {{ .Values.db.portaldb.host }}
command:
- bash
- "-ec"
args:
- |
echo "INFO: Start to init database."
cat > /tmp/.my.cnf << EOF
[client]
host={{ .Values.db.portaldb.host }}
user={{ .Values.db.portaldb.userName | quote }}
password={{ .Values.db.portaldb.password | quote }}
database={{ .Values.db.portaldb.dbName }}
EOF
echo "INFO: Checking the database, if it's exist ..."
if mysql --defaults-file=/tmp/.my.cnf -E --connect-timeout=30 -w -e 'SHOW TABLES FROM {{ .Values.db.portaldb.dbName }}' | grep -q : ; then
echo "INFO: {{ .Values.db.portaldb.dbName }} was exists. skipping to initial SQL table."
else
#if [[ $? -eq 1 ]]; then
echo "INFO: {{ .Values.db.portaldb.dbName }} is not exists. creating and init SQL file ..."
echo "INFO: CREATE DATABASE"
mysql --defaults-file=/tmp/.my.cnf -E --connect-timeout=30 -w -e 'CREATE DATABASE "{{ .Values.db.portaldb.dbName }}" DEFAULT CHARSET utf8mb4'
echo "INFO: CREATE TABLES"
mysql --defaults-file=/tmp/.my.cnf -E --connect-timeout=30 -w {{ .Values.db.portaldb.dbName }} < /docker-entrypoint-initdb.d/init-database.sql
fi
echo "INFO: starting app container ..."
volumeMounts:
- name: configmap-{{ $portalFullName }}
mountPath: /tmp/application-github.properties
subPath: application-github.properties
- name: configmap-{{ $portalFullName }}
mountPath: /docker-entrypoint-initdb.d/init-database.sql
subPath: init-database.sql
{{- end }}
containers:
- name: {{ .Values.portal.name }}
image: "{{ .Values.portal.image.repository }}:{{ .Values.portal.image.tag | default .Chart.AppVersion }}"
Expand Down
46 changes: 34 additions & 12 deletions charts/apollo/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ db:
port: 3306
dbName: ApolloConfigDB
# apolloconfigdb user name
userName: ""
userName: "abc"
# apolloconfigdb password
password: ""
password: "abc"
connectionStringProperties: characterEncoding=utf8&useSSL=false

## @param service: create a externalName service for foreign database endpoint
Expand All @@ -35,16 +35,23 @@ db:
port: 3306
type: ClusterIP

autoInitDatabase:
enabled: true
initContainer:
registry: "docker.io"
repository: mysql
tag: latest

portaldb:
name: apollo-portaldb
# apolloportaldb host
host: "x.x.x.x"
port: 3306
dbName: ApolloPortalDB
# apolloportaldb user name
userName: ""
userName: "abc"
# apolloportaldb password
password: ""
password: "abc"
connectionStringProperties: characterEncoding=utf8&useSSL=false

## @param service: create a externalName service for foreign database endpoint
Expand All @@ -56,6 +63,13 @@ db:
port: 3306
type: ClusterIP

autoInitDatabase:
enabled: true
initContainer:
registry: "docker.io"
repository: mysql
tag: latest

configService:
name: apollo-configservice
fullNameOverride: ""
Expand Down Expand Up @@ -223,15 +237,23 @@ portal:
annotations: { }

config:
# spring profiles to activate
## @param profiles: spring profiles to activate
##
profiles: "github,auth"
# specify the env names, e.g. dev,pro
envs: ""
# specify the meta servers, e.g.
# dev: http://apollo-configservice-dev:8080
# pro: http://apollo-configservice-pro:8080

## @param envs: specify the env names, e.g. dev,pro
##
envs: "dev"

## @param metaServers: specify the meta servers, e.g.
## dev: http://apollo-configservice-dev:8080
## pro: http://apollo-configservice-pro:8080
metaServers: { }
# specify the context path, e.g. /apollo

## @param contextPath: specify the context path, e.g. /apollo
##
contextPath: ""
# extra config files for apollo-portal, e.g. application-ldap.yml

## @param files: extra config files for apollo-portal, e.g. application-ldap.yml
##
files: { }

0 comments on commit 39163a7

Please sign in to comment.