diff --git a/charts/apollo/Chart.yaml b/charts/apollo/Chart.yaml index b0b6a9c..847796b 100644 --- a/charts/apollo/Chart.yaml +++ b/charts/apollo/Chart.yaml @@ -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 diff --git a/charts/apollo/templates/config-service/configmap-configservice.yaml b/charts/apollo/templates/config-service/configmap-configservice.yaml index 9deb74b..f0371be 100644 --- a/charts/apollo/templates/config-service/configmap-configservice.yaml +++ b/charts/apollo/templates/config-service/configmap-configservice.yaml @@ -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 }} \ No newline at end of file + {{- end }} + {{- if .Values.db.configdb.autoInitDatabase.enabled }} + init-database.sql: | + {{- .Files.Get "init-db/apolloconfigdb.sql" | nindent 4 }} + {{- end }} \ No newline at end of file diff --git a/charts/apollo/templates/config-service/deployment-configservice.yaml b/charts/apollo/templates/config-service/deployment-configservice.yaml index 8b73dbd..270f4b6 100644 --- a/charts/apollo/templates/config-service/deployment-configservice.yaml +++ b/charts/apollo/templates/config-service/deployment-configservice.yaml @@ -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 }}" diff --git a/charts/apollo/templates/portal/configmap-portal.yaml b/charts/apollo/templates/portal/configmap-portal.yaml index ae947e1..536c3f3 100644 --- a/charts/apollo/templates/portal/configmap-portal.yaml +++ b/charts/apollo/templates/portal/configmap-portal.yaml @@ -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 }} \ No newline at end of file diff --git a/charts/apollo/templates/portal/deployment-portal.yaml b/charts/apollo/templates/portal/deployment-portal.yaml index 96e3736..e6dfb39 100644 --- a/charts/apollo/templates/portal/deployment-portal.yaml +++ b/charts/apollo/templates/portal/deployment-portal.yaml @@ -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 }}" diff --git a/charts/apollo/values.yaml b/charts/apollo/values.yaml index 114b484..6c00126 100644 --- a/charts/apollo/values.yaml +++ b/charts/apollo/values.yaml @@ -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 @@ -35,6 +35,13 @@ db: port: 3306 type: ClusterIP + autoInitDatabase: + enabled: true + initContainer: + registry: "docker.io" + repository: mysql + tag: latest + portaldb: name: apollo-portaldb # apolloportaldb host @@ -42,9 +49,9 @@ db: 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 @@ -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: "" @@ -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: { } \ No newline at end of file