Skip to content

Commit 43bf9bd

Browse files
committed
Enhance launcher scripts with new commands and options
1 parent 3cc7cf8 commit 43bf9bd

File tree

4 files changed

+486
-351
lines changed

4 files changed

+486
-351
lines changed

config/docker-config/Dockerfile.backend

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ RUN mkdir -p /run/nginx /var/log/nginx && \
3030
RUN chown -R www-data:www-data /var/www/html && chown -R www-data:www-data /detection-rules
3131

3232
COPY sentinel-kit_server_backend/composer.json /var/www/html/composer.json
33+
COPY sentinel-kit_server_backend/composer.lock* /var/www/html/
3334

3435
WORKDIR /var/www/html
3536

@@ -39,4 +40,4 @@ RUN composer install --no-scripts --no-autoloader && \
3940
COPY config/docker-config/backend-entrypoint.sh /opt/server-backend/backend-entrypoint.sh
4041
RUN chmod +x /opt/server-backend/backend-entrypoint.sh
4142

42-
ENTRYPOINT ["/bin/sh", "-c", "/opt/server-backend/backend-entrypoint.sh"]
43+
ENTRYPOINT ["/bin/bash", "-c", "/opt/server-backend/backend-entrypoint.sh"]

config/docker-config/backend-entrypoint.sh

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
echo "=== Sentinel Kit Backend Entrypoint ==="
44
echo "Environment: $APP_ENV"
55

66
chown -R www-data:www-data /var/www/html
77
chown -R www-data:www-data /detection-rules
88

9+
su -s /bin/bash www-data << 'EOF'
910
setup_symfony() {
1011
MARKER_FILE="/var/www/html/.initial_setup_done"
1112
rm -rf /var/www/html/var/cache
1213
rm -rf /var/www/html/public/bundles
1314
rm -rf /detection-rules/elastalert/*
1415
15-
# Vérifier si les dépendances Composer sont installées
1616
if [ ! -d "/var/www/html/vendor" ] || [ ! -f "/var/www/html/vendor/autoload.php" ]; then
1717
echo "Installing Composer dependencies..."
1818
composer install --no-scripts
@@ -21,17 +21,76 @@ setup_symfony() {
2121
echo "Composer dependencies already installed."
2222
fi
2323
24+
echo "Waiting for database to be ready..."
25+
max_attempts=30
26+
attempt=1
27+
while [ $attempt -le $max_attempts ]; do
28+
if php /var/www/html/bin/console doctrine:database:create --if-not-exists >/dev/null 2>&1; then
29+
echo "Database is ready!"
30+
break
31+
fi
32+
echo "Database not ready yet (attempt $attempt/$max_attempts), waiting 2 seconds..."
33+
sleep 2
34+
attempt=$((attempt + 1))
35+
done
36+
37+
if [ $attempt -gt $max_attempts ]; then
38+
echo "ERROR: Database is not ready after $max_attempts attempts"
39+
exit 1
40+
fi
41+
2442
if [ ! -f "$MARKER_FILE" ]; then
2543
echo "Running initial setup..."
26-
sleep 10
44+
45+
echo "Creating database if not exists..."
46+
php /var/www/html/bin/console doctrine:database:create --if-not-exists
47+
48+
echo "Dropping existing schema..."
49+
php /var/www/html/bin/console doctrine:schema:drop --force --full-database || true
50+
51+
echo "Cleaning old migrations..."
2752
rm -rf /var/www/html/migrations/*.php
28-
php /var/www/html/bin/console doctrine:schema:drop --force --full-database
29-
php /var/www/html/bin/console make:migration -n
30-
php /var/www/html/bin/console doctrine:migrations:migrate -n
31-
php /var/www/html/bin/console lexik:jwt:generate-keypair
53+
54+
echo "Creating new migration..."
55+
if ! php /var/www/html/bin/console make:migration -n; then
56+
echo "ERROR: Failed to create migration"
57+
exit 1
58+
fi
59+
60+
if [ -z "$(ls -A /var/www/html/migrations/)" ]; then
61+
echo "ERROR: No migration file was created"
62+
exit 1
63+
fi
64+
65+
echo "Applying migrations..."
66+
if ! php /var/www/html/bin/console doctrine:migrations:migrate -n; then
67+
echo "ERROR: Failed to apply migrations"
68+
exit 1
69+
fi
70+
71+
echo "Verifying database schema..."
72+
if ! php /var/www/html/bin/console doctrine:schema:validate; then
73+
echo "WARNING: Database schema validation failed"
74+
fi
75+
76+
echo "Generating JWT keypair..."
77+
if ! php /var/www/html/bin/console lexik:jwt:generate-keypair; then
78+
echo "ERROR: Failed to generate JWT keypair"
79+
exit 1
80+
fi
81+
3282
php /var/www/html/bin/console lexik:jwt:check-config
83+
3384
touch "$MARKER_FILE"
34-
echo "Initial setup completed."
85+
echo "Initial setup completed successfully."
86+
else
87+
echo "Initial setup already completed (marker file exists)."
88+
89+
echo "Checking if database migrations are up to date..."
90+
if ! php /var/www/html/bin/console doctrine:migrations:up-to-date; then
91+
echo "Database migrations are not up to date, running migrations..."
92+
php /var/www/html/bin/console doctrine:migrations:migrate -n
93+
fi
3594
fi
3695
3796
if [ "$APP_ENV" = "prod" ]; then
@@ -44,8 +103,6 @@ setup_symfony() {
44103
fi
45104
}
46105
47-
su -s /bin/sh www-data << 'EOF'
48-
$(declare -f setup_symfony)
49106
setup_symfony
50107
EOF
51108

0 commit comments

Comments
 (0)