From e23f49d2f4246135b66e7df0e4057ef32515883b Mon Sep 17 00:00:00 2001 From: Julian PEREZ-RAMIREZ <julian.perez-ramirez@imt-atlantique.net> Date: Fri, 21 Feb 2025 20:13:01 +0100 Subject: [PATCH] trying to run doctrine --- Dockerfile | 13 +++++ compose.yaml | 9 ++-- composer.json | 8 +++ web_app/compose.override.yaml | 7 +++ web_app/compose.yaml | 25 +++++++++ web_app/composer.json | 6 ++- web_app/config/bundles.php | 2 + web_app/config/packages/doctrine.yaml | 54 +++++++++++++++++++ .../config/packages/doctrine_migrations.yaml | 6 +++ web_app/migrations/.gitignore | 0 web_app/src/Entity/.gitignore | 0 web_app/src/Repository/.gitignore | 0 web_app/symfony.lock | 27 ++++++++++ 13 files changed, 152 insertions(+), 5 deletions(-) create mode 100644 Dockerfile create mode 100644 composer.json create mode 100644 web_app/compose.override.yaml create mode 100644 web_app/compose.yaml create mode 100644 web_app/config/packages/doctrine.yaml create mode 100644 web_app/config/packages/doctrine_migrations.yaml create mode 100644 web_app/migrations/.gitignore create mode 100644 web_app/src/Entity/.gitignore create mode 100644 web_app/src/Repository/.gitignore diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..72f18ab --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM bitnami/symfony:latest + +WORKDIR /app + +COPY . /app + +# Ensure dependencies are installed +RUN composer install --no-interaction --prefer-dist --optimize-autoloader + +# Install Doctrine ORM explicitly +RUN composer require symfony/orm-pack --no-scripts --no-interactio + +EXPOSE 8000 diff --git a/compose.yaml b/compose.yaml index 23100aa..f86b3c8 100644 --- a/compose.yaml +++ b/compose.yaml @@ -17,8 +17,8 @@ services: image: mysql:8.1 container_name: symfony_db environment: - MYSQL_ROOT_PASSWORD: rootpassword - MYSQL_DATABASE: symfony + MYSQL_ROOT_PASSWORD: password + MYSQL_DATABASE: wishlist_db MYSQL_USER: symfony MYSQL_PASSWORD: symfony ports: @@ -34,4 +34,7 @@ services: depends_on: - mysql #this line links this container to the db container environment: - PMA_HOST: mysql \ No newline at end of file + PMA_HOST: mysql + +#If you got an error about folder permissions with innodb_redo, +# try to fix it by running sudo chmod -R 755 ~/<your_path>/wishlist/mysql_data \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..6da41e5 --- /dev/null +++ b/composer.json @@ -0,0 +1,8 @@ +{ + "require": { + "symfony/orm-pack": "^2.4" + }, + "require-dev": { + "symfony/maker-bundle": "^1.62" + } +} diff --git a/web_app/compose.override.yaml b/web_app/compose.override.yaml new file mode 100644 index 0000000..c5612b0 --- /dev/null +++ b/web_app/compose.override.yaml @@ -0,0 +1,7 @@ + +services: +###> doctrine/doctrine-bundle ### + database: + ports: + - "5432" +###< doctrine/doctrine-bundle ### diff --git a/web_app/compose.yaml b/web_app/compose.yaml new file mode 100644 index 0000000..89c74d1 --- /dev/null +++ b/web_app/compose.yaml @@ -0,0 +1,25 @@ + +services: +###> doctrine/doctrine-bundle ### + database: + image: postgres:${POSTGRES_VERSION:-16}-alpine + environment: + POSTGRES_DB: ${POSTGRES_DB:-app} + # You should definitely change the password in production + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-!ChangeMe!} + POSTGRES_USER: ${POSTGRES_USER:-app} + healthcheck: + test: ["CMD", "pg_isready", "-d", "${POSTGRES_DB:-app}", "-U", "${POSTGRES_USER:-app}"] + timeout: 5s + retries: 5 + start_period: 60s + volumes: + - database_data:/var/lib/postgresql/data:rw + # You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data! + # - ./docker/db/data:/var/lib/postgresql/data:rw +###< doctrine/doctrine-bundle ### + +volumes: +###> doctrine/doctrine-bundle ### + database_data: +###< doctrine/doctrine-bundle ### diff --git a/web_app/composer.json b/web_app/composer.json index d51a94e..bc22af8 100644 --- a/web_app/composer.json +++ b/web_app/composer.json @@ -7,6 +7,10 @@ "php": ">=8.2", "ext-ctype": "*", "ext-iconv": "*", + "doctrine/dbal": "^3", + "doctrine/doctrine-bundle": "^2.13", + "doctrine/doctrine-migrations-bundle": "^3.4", + "doctrine/orm": "^3.3", "symfony/console": "7.2.*", "symfony/dotenv": "7.2.*", "symfony/flex": "^2", @@ -14,8 +18,6 @@ "symfony/runtime": "7.2.*", "symfony/yaml": "7.2.*" }, - "require-dev": { - }, "config": { "allow-plugins": { "php-http/discovery": true, diff --git a/web_app/config/bundles.php b/web_app/config/bundles.php index 49d3fb6..c1fa06a 100644 --- a/web_app/config/bundles.php +++ b/web_app/config/bundles.php @@ -2,4 +2,6 @@ return [ Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], + Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], + Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], ]; diff --git a/web_app/config/packages/doctrine.yaml b/web_app/config/packages/doctrine.yaml new file mode 100644 index 0000000..25138b9 --- /dev/null +++ b/web_app/config/packages/doctrine.yaml @@ -0,0 +1,54 @@ +doctrine: + dbal: + url: '%env(resolve:DATABASE_URL)%' + + # IMPORTANT: You MUST configure your server version, + # either here or in the DATABASE_URL env var (see .env file) + #server_version: '16' + + profiling_collect_backtrace: '%kernel.debug%' + use_savepoints: true + orm: + auto_generate_proxy_classes: true + enable_lazy_ghost_objects: true + report_fields_where_declared: true + validate_xml_mapping: true + naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware + identity_generation_preferences: + Doctrine\DBAL\Platforms\PostgreSQLPlatform: identity + auto_mapping: true + mappings: + App: + type: attribute + is_bundle: false + dir: '%kernel.project_dir%/src/Entity' + prefix: 'App\Entity' + alias: App + controller_resolver: + auto_mapping: false + +when@test: + doctrine: + dbal: + # "TEST_TOKEN" is typically set by ParaTest + dbname_suffix: '_test%env(default::TEST_TOKEN)%' + +when@prod: + doctrine: + orm: + auto_generate_proxy_classes: false + proxy_dir: '%kernel.build_dir%/doctrine/orm/Proxies' + query_cache_driver: + type: pool + pool: doctrine.system_cache_pool + result_cache_driver: + type: pool + pool: doctrine.result_cache_pool + + framework: + cache: + pools: + doctrine.result_cache_pool: + adapter: cache.app + doctrine.system_cache_pool: + adapter: cache.system diff --git a/web_app/config/packages/doctrine_migrations.yaml b/web_app/config/packages/doctrine_migrations.yaml new file mode 100644 index 0000000..29231d9 --- /dev/null +++ b/web_app/config/packages/doctrine_migrations.yaml @@ -0,0 +1,6 @@ +doctrine_migrations: + migrations_paths: + # namespace is arbitrary but should be different from App\Migrations + # as migrations classes should NOT be autoloaded + 'DoctrineMigrations': '%kernel.project_dir%/migrations' + enable_profiler: false diff --git a/web_app/migrations/.gitignore b/web_app/migrations/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/web_app/src/Entity/.gitignore b/web_app/src/Entity/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/web_app/src/Repository/.gitignore b/web_app/src/Repository/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/web_app/symfony.lock b/web_app/symfony.lock index 8ca246f..bb5af90 100644 --- a/web_app/symfony.lock +++ b/web_app/symfony.lock @@ -1,4 +1,31 @@ { + "doctrine/doctrine-bundle": { + "version": "2.13", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "2.13", + "ref": "8d96c0b51591ffc26794d865ba3ee7d193438a83" + }, + "files": [ + "config/packages/doctrine.yaml", + "src/Entity/.gitignore", + "src/Repository/.gitignore" + ] + }, + "doctrine/doctrine-migrations-bundle": { + "version": "3.4", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "3.1", + "ref": "1d01ec03c6ecbd67c3375c5478c9a423ae5d6a33" + }, + "files": [ + "config/packages/doctrine_migrations.yaml", + "migrations/.gitignore" + ] + }, "symfony/console": { "version": "7.2", "recipe": { -- GitLab