test: add detailed connection testing to migration job
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 6m1s
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 6m1s
This commit is contained in:
parent
5c3833a9e4
commit
b2706bc747
@ -10,35 +10,42 @@ spec:
|
||||
spec:
|
||||
imagePullSecrets:
|
||||
- name: regcred
|
||||
initContainers:
|
||||
- name: wait-for-postgres
|
||||
image: postgres:15
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- |
|
||||
echo "Waiting for PostgreSQL to be ready..."
|
||||
for i in $(seq 1 30); do
|
||||
if pg_isready -h postgres-service -p 5432 -U prod_admin; then
|
||||
echo "PostgreSQL is ready!"
|
||||
exit 0
|
||||
fi
|
||||
echo "Attempt $i: PostgreSQL is not ready yet. Waiting..."
|
||||
sleep 10
|
||||
done
|
||||
echo "PostgreSQL failed to become ready in time"
|
||||
exit 1
|
||||
env:
|
||||
- name: PGPASSWORD
|
||||
value: "{{ .Values.backend.env.POSTGRES_PASSWORD }}"
|
||||
containers:
|
||||
- name: migrate-seed
|
||||
image: {{ .Values.backend.image }}
|
||||
command: ["/bin/sh", "-c"]
|
||||
args:
|
||||
- |
|
||||
echo "Running migrations and seeds..." && \
|
||||
npx mikro-orm migration:up && \
|
||||
echo "Environment variables:"
|
||||
echo "POSTGRES_NAME: $POSTGRES_NAME"
|
||||
echo "POSTGRES_HOSTNAME: $POSTGRES_HOSTNAME"
|
||||
echo "POSTGRES_PORT: $POSTGRES_PORT"
|
||||
echo "POSTGRES_USER: $POSTGRES_USER"
|
||||
echo "Testing direct connection..."
|
||||
PGPASSWORD=$POSTGRES_PASSWORD psql -h $POSTGRES_HOSTNAME -p $POSTGRES_PORT -U $POSTGRES_USER -d $POSTGRES_NAME -c "SELECT 1"
|
||||
echo "Testing MikroORM connection..."
|
||||
node -e "
|
||||
const { PostgreSqlDriver } = require('@mikro-orm/postgresql');
|
||||
const { MikroORM } = require('@mikro-orm/core');
|
||||
const config = {
|
||||
driver: PostgreSqlDriver,
|
||||
dbName: process.env.POSTGRES_NAME,
|
||||
host: process.env.POSTGRES_HOSTNAME,
|
||||
port: parseInt(process.env.POSTGRES_PORT),
|
||||
user: process.env.POSTGRES_USER,
|
||||
password: process.env.POSTGRES_PASSWORD,
|
||||
};
|
||||
console.log('MikroORM config:', config);
|
||||
MikroORM.init(config).then(orm => {
|
||||
console.log('Connected successfully!');
|
||||
orm.close();
|
||||
}).catch(err => {
|
||||
console.error('Connection failed:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
"
|
||||
echo "Running migrations and seeds..."
|
||||
npx mikro-orm migration:up
|
||||
npm run seed
|
||||
env:
|
||||
{{- range $key, $val := .Values.backend.env }}
|
||||
|
Loading…
Reference in New Issue
Block a user