Adds mysql to e2e test app.

This commit is contained in:
2026-06-20 06:39:26 +00:00
parent c223e2b5e0
commit dc54a10b51
3 changed files with 74 additions and 1 deletions

View File

@@ -13,3 +13,4 @@ resources:
- service.yaml
- pvc.yaml
- db-init-job.yaml
- mysql-db-init-job.yaml

View File

@@ -1,6 +1,7 @@
version: 2.0.0
version: 2.0.0-1
requires:
- name: postgres
- name: mysql
defaultConfig:
namespace: e2e-test-app
domain: e2e-test-app.{{ .cloud.domain }}
@@ -12,9 +13,16 @@ defaultConfig:
port: '{{ .apps.postgres.port }}'
name: e2e_test_app
user: e2e_test_app
mysql:
host: '{{ .apps.mysql.host }}'
port: '{{ .apps.mysql.port }}'
name: e2e_test_app
user: e2e_test_app
defaultSecrets:
- key: dbPassword
- key: dbUrl
default: "postgres://{{ .app.db.user }}:{{ .secrets.dbPassword }}@{{ .app.db.host }}:{{ .app.db.port }}/{{ .app.db.name }}?sslmode=disable"
- key: mysqlPassword
requiredSecrets:
- postgres.password
- mysql.rootPassword

View File

@@ -0,0 +1,64 @@
apiVersion: batch/v1
kind: Job
metadata:
name: e2e-test-app-mysql-db-init
labels:
component: mysql-db-init
spec:
template:
metadata:
labels:
component: mysql-db-init
spec:
restartPolicy: OnFailure
containers:
- name: mysql-init
image: mysql:9.1.0
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: e2e-test-app-secrets
key: mysql.rootPassword
- name: DB_HOST
value: {{ .mysql.host }}
- name: DB_PORT
value: "{{ .mysql.port }}"
- name: DB_NAME
value: {{ .mysql.name }}
- name: DB_USER
value: {{ .mysql.user }}
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: e2e-test-app-secrets
key: mysqlPassword
command: ["/bin/bash", "-c"]
args:
- |
set -e
echo "Waiting for MySQL to be ready..."
until mysql -h "${DB_HOST}" -P "${DB_PORT}" -uroot -p"${MYSQL_ROOT_PASSWORD}" -e "SELECT 1" &>/dev/null; do
echo "MySQL not ready, retrying..."
sleep 3
done
echo "MySQL ready"
mysql -h "${DB_HOST}" -P "${DB_PORT}" -uroot -p"${MYSQL_ROOT_PASSWORD}" <<EOF
CREATE DATABASE IF NOT EXISTS \`${DB_NAME}\`;
CREATE USER IF NOT EXISTS '${DB_USER}'@'%' IDENTIFIED BY '${DB_PASSWORD}';
ALTER USER '${DB_USER}'@'%' IDENTIFIED BY '${DB_PASSWORD}';
GRANT ALL PRIVILEGES ON \`${DB_NAME}\`.* TO '${DB_USER}'@'%';
FLUSH PRIVILEGES;
EOF
mysql -h "${DB_HOST}" -P "${DB_PORT}" -uroot -p"${MYSQL_ROOT_PASSWORD}" "${DB_NAME}" <<EOF
CREATE TABLE IF NOT EXISTS e2e_test_data (
id INT AUTO_INCREMENT PRIMARY KEY,
test_key VARCHAR(255) UNIQUE NOT NULL,
test_value TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
EOF
echo "MySQL initialization complete"