diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index 9219990..0233faa 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -54,4 +54,9 @@ RUN composer install --prefer-dist --no-scripts --no-dev --optimize-autoloader EXPOSE 9000 +COPY entrypoint.sh /usr/bin +RUN chmod +x /usr/bin/entrypoint.sh + +ENTRYPOINT ["/usr/bin/entrypoint.sh"] + CMD ["php-fpm"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..f9e1a07 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +set -e + +echo "Creating the database if it does not exist..." +php bin/console doctrine:database:create --if-not-exists + +# Check if migrations need to be applied +if ! php bin/console doctrine:migrations:up-to-date --quiet; then + echo "Applying migrations..." + php bin/console doctrine:migrations:migrate --no-interaction +fi + +# Check if FORCE_SCHEMA_UPDATE is set to true +if [ "$FORCE_SCHEMA_UPDATE" = "true" ]; then + echo "Forcing schema update..." + php bin/console doctrine:schema:update --force +fi + +# Execute the CMD from the Dockerfile +exec "$@"