Compare commits

..

4 Commits

Author SHA1 Message Date
2716e60d2d Merge pull request 'fix: include all SQL files in dbinit configmap' (#7) from fix/include-all-sql-in-dbinit into main 2026-04-28 09:04:17 +00:00
0c569ec528 fix: include all SQL files in dbinit configmap (not just 004_*.sql)
The glob was "sql/004_*.sql" which excluded 000_create_db.sql that
creates hades_user. Changed to "sql/*.sql" to include all migration
files in alphabetical order.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-28 14:34:06 +05:30
6e8b755f38 Merge pull request 'fix: create hades_user in dbinit for shared MySQL' (#6) from fix/create-hades-user-in-dbinit into main 2026-04-28 09:00:37 +00:00
e880f4e9c4 fix: create hades_user in dbinit for shared MySQL compatibility
Shared MySQL (mysql-5-7) only has mysql_user. The hades app connects
as hades_user which doesn't exist. dbinit runs as root, so it can
create the user before migrations run.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-28 14:30:15 +05:30
7 changed files with 20 additions and 118 deletions

View File

@ -2,3 +2,8 @@
-- This file runs first to ensure proper migration ordering
SELECT 'Database migration starting for hades_db' AS message;
-- Create hades_user for app connections (shared MySQL only has mysql_user)
CREATE USER IF NOT EXISTS 'hades_user'@'%' IDENTIFIED BY 'local-hades-pass';
GRANT ALL PRIVILEGES ON hades_db.* TO 'hades_user'@'%';
FLUSH PRIVILEGES;

View File

@ -9,7 +9,7 @@ metadata:
annotations:
argocd.argoproj.io/sync-options: ServerSideApply=true
binaryData:
{{- range $path, $_ := .Files.Glob "sql/004_*.sql" }}
{{- range $path, $_ := .Files.Glob "sql/*.sql" }}
{{ base $path }}: {{ $.Files.Get $path | b64enc }}
{{- end }}
{{- end }}

View File

@ -6,9 +6,8 @@ metadata:
labels:
{{- include "hades.labels" . | nindent 4 }}
data:
{{- range $filename, $content := .Values.config.files }}
{{ $filename }}: |
{{- tpl $content $ | nindent 4 }}
{{- with .Values.config.files }}
{{- toYaml . | nindent 2 }}
{{- end }}
hibernate.cfg.xml: |
<?xml version='1.0' encoding='utf-8'?>

View File

@ -142,29 +142,21 @@ spec:
value: "false"
- name: HIBERNATE_HBM2DDL_AUTO
value: "validate"
{{- if or .Values.config.enabled .Values.allhosts.enabled .Values.tomcatWritableDirs.enabled }}
{{- if or .Values.config.enabled .Values.allhosts.enabled }}
volumeMounts:
{{- if .Values.config.enabled }}
{{- range .Values.config.mountPaths }}
- name: config
mountPath: {{ . }}
mountPath: /etc/onlinesales/config/hades
readOnly: true
{{- end }}
{{- end }}
{{- if .Values.allhosts.enabled }}
- name: allhosts
mountPath: /etc/onlinesales/config/allhosts/allhosts.tsv
subPath: allhosts.tsv
readOnly: true
{{- end }}
{{- if .Values.tomcatWritableDirs.enabled }}
{{- range $i, $path := .Values.tomcatWritableDirs.paths }}
- name: tomcat-writable-{{ $i }}
mountPath: {{ $path }}
{{- end }}
{{- end }}
{{- end }}
{{- if or .Values.config.enabled .Values.allhosts.enabled .Values.tomcatWritableDirs.enabled }}
{{- if or .Values.config.enabled .Values.allhosts.enabled }}
volumes:
{{- if .Values.config.enabled }}
- name: config
@ -176,12 +168,6 @@ spec:
configMap:
name: {{ include "hades.fullname" . }}-allhosts
{{- end }}
{{- if .Values.tomcatWritableDirs.enabled }}
{{- range $i, $path := .Values.tomcatWritableDirs.paths }}
- name: tomcat-writable-{{ $i }}
emptyDir: {}
{{- end }}
{{- end }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:

View File

@ -50,12 +50,12 @@ spec:
- name: MYSQL_DATABASE
value: {{ include "hades.databaseName" . | quote }}
- name: MYSQL_USER
value: {{ .Values.dbInit.mysqlUser | default "root" | quote }}
value: "root"
- name: MYSQL_PWD
valueFrom:
secretKeyRef:
name: {{ include "hades.databaseSecretName" . }}
key: {{ .Values.dbInit.mysqlPasswordKey | default "mysql-root-password" }}
key: mysql-root-password
command:
- /bin/bash
- -c
@ -72,7 +72,7 @@ spec:
# Test connection
echo "Testing database connection..."
if ! mysql -h"${MYSQL_HOST}" -P"${MYSQL_PORT}" -u"${MYSQL_USER}" -e "SELECT 1" "${MYSQL_DATABASE}" &> /dev/null; then
if ! mysql -h"${MYSQL_HOST}" -P"${MYSQL_PORT}" -u"root" -e "SELECT 1" "${MYSQL_DATABASE}" &> /dev/null; then
echo "ERROR: Cannot connect to database"
exit 1
fi
@ -94,7 +94,7 @@ spec:
echo -n "Applying $filename... "
if mysql -h"${MYSQL_HOST}" -P"${MYSQL_PORT}" -u"${MYSQL_USER}" "${MYSQL_DATABASE}" < "$sql_file" 2>/tmp/migration_error.log; then
if mysql -h"${MYSQL_HOST}" -P"${MYSQL_PORT}" -u"root" "${MYSQL_DATABASE}" < "$sql_file" 2>/tmp/migration_error.log; then
echo "✓ SUCCESS"
SUCCESS=$((SUCCESS + 1))
else

View File

@ -107,17 +107,13 @@ allhosts:
# Configuration files for local development
config:
enabled: true
mountPaths:
- /etc/onlinesales/config/hades
- /etc/onlinesales/config/hadesV2
- /etc/onlinesales/db/hadesV2
files:
hades.cfg: |
{
test: {
logConfig: "/etc/onlinesales/config/hades/log.cfg",
hades_hibernate_config_read: "/etc/onlinesales/db/hadesV2/hades.read.hibernate.cfg.xml",
hades_hibernate_config_write: "/etc/onlinesales/db/hadesV2/hades.write.hibernate.cfg.xml",
hades_hibernate_config_read: "/etc/onlinesales/config/hades/hibernate.cfg.xml",
hades_hibernate_config_write: "/etc/onlinesales/config/hades/hibernate.cfg.xml",
rest_accessor_config_file: "/etc/onlinesales/config/hades/restAccessor.cfg",
forgot_password_email_config_file: "/etc/onlinesales/config/hades/forgotPasswordEmailSender.cfg",
activation_email_config_file: "/etc/onlinesales/config/hades/activationEmailConfigFile.cfg",
@ -126,7 +122,7 @@ config:
stats_logging_config: "/etc/onlinesales/config/hades/statsLogging.cfg",
sms_sender_lib_config: "/etc/onlinesales/config/hades/smsSenderLib.cfg",
context_key: "/etc/onlinesales/config/hades/contextKey.cfg",
is_app_ip_enabled: "false",
is_app_ip_enabled: "true",
firebase_admin_sdk_config: "/etc/onlinesales/config/hades/firebaseAdminConfig.cfg",
firebase_data_url: "https://os-login-656b5.firebaseio.com",
failed_events_file: "/tmp/hades_failed_events.err",
@ -294,81 +290,6 @@ config:
}
}
hades.read.hibernate.cfg.xml: |
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://{{ include "hades.databaseHost" . }}:{{ include "hades.databasePort" . }}/{{ include "hades.databaseName" . }}?useUnicode=true&amp;characterEncoding=UTF-8&amp;autoReconnect=true&amp;</property>
<property name="connection.username">{{ include "hades.databaseUsername" . }}</property>
<property name="connection.password">{{ .Values.database.password | default .Values.mysql.mysqlPassword | default "local-mysql-pass" }}</property>
<property name="connection.pool_size">1</property>
<property name="dialect">ai.osmos.dblib.CustomMySQL8DialectUtf8mb4</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="show_sql">false</property>
<property name="use_keying_service">false</property>
<property name="use_credential_store">false</property>
<property name="connection.isolation">2</property>
<property name="connection.autocommit">true</property>
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>
<property name="c3p0.acquire_increment">10</property>
<property name="c3p0.idle_test_period">3600</property>
<property name="c3p0.max_size">30</property>
<property name="c3p0.max_statements">0</property>
<property name="c3p0.min_size">10</property>
<property name="c3p0.timeout">3605</property>
<property name="hibernate.c3p0.preferredTestQuery">select 1;</property>
<property name="hibernate.globally_quoted_identifiers">true</property>
</session-factory>
</hibernate-configuration>
hades.write.hibernate.cfg.xml: |
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://{{ include "hades.databaseHost" . }}:{{ include "hades.databasePort" . }}/{{ include "hades.databaseName" . }}?useUnicode=true&amp;characterEncoding=UTF-8&amp;autoReconnect=true&amp;</property>
<property name="connection.username">{{ include "hades.databaseUsername" . }}</property>
<property name="connection.password">{{ .Values.database.password | default .Values.mysql.mysqlPassword | default "local-mysql-pass" }}</property>
<property name="connection.pool_size">1</property>
<property name="dialect">ai.osmos.dblib.CustomMySQL8DialectUtf8mb4</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="show_sql">false</property>
<property name="use_keying_service">false</property>
<property name="use_credential_store">false</property>
<property name="connection.isolation">2</property>
<property name="connection.autocommit">true</property>
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>
<property name="c3p0.acquire_increment">10</property>
<property name="c3p0.idle_test_period">3600</property>
<property name="c3p0.max_size">30</property>
<property name="c3p0.max_statements">0</property>
<property name="c3p0.min_size">10</property>
<property name="c3p0.timeout">3605</property>
<property name="hibernate.c3p0.preferredTestQuery">select 1;</property>
<property name="hibernate.globally_quoted_identifiers">true</property>
</session-factory>
</hibernate-configuration>
# Tomcat writable directories (emptyDir mounts for non-root pods)
tomcatWritableDirs:
enabled: true
paths:
- /usr/local/tomcat/conf/Catalina
- /usr/local/tomcat/work
# Hibernate configuration options (hibernate.cfg.xml is now generated dynamically)
hibernate:
connectionPoolSize: 10

View File

@ -36,8 +36,8 @@ securityContext:
drop:
- ALL
readOnlyRootFilesystem: false
runAsNonRoot: false
runAsUser: 0
runAsNonRoot: true
runAsUser: 1000
service:
type: ClusterIP
@ -166,14 +166,10 @@ mysql:
# Automatically runs all SQL migration files from sql/ directory in alphabetical order
dbInit:
enabled: true
mysqlUser: "root"
mysqlPasswordKey: "mysql-root-password"
# ConfigMap for application configuration files
config:
enabled: true
mountPaths:
- /etc/onlinesales/config/hades
# Add your configuration files here
# files:
# hades.cfg: |
@ -192,11 +188,6 @@ hibernate:
connectionPoolSize: 10
showSql: "true"
# Tomcat writable directories (emptyDir mounts for non-root pods)
tomcatWritableDirs:
enabled: false
paths: []
nodeSelector: {}
tolerations: []