2021-04-17 19:46:00 +00:00
|
|
|
Environnement de développement Docker pour démarrer un nouveau projet Symfony5
|
|
|
|
==================================
|
|
|
|
|
2022-10-01 16:38:56 +00:00
|
|
|
## En partant de la branche *5_start_new-project*
|
2021-04-17 19:46:00 +00:00
|
|
|
|
2022-10-01 16:38:56 +00:00
|
|
|
Le projet, symfony et ses dépendances sont prêt à être installé.
|
2021-04-17 19:46:00 +00:00
|
|
|
|
2022-10-01 16:38:56 +00:00
|
|
|
```
|
|
|
|
$ docker-compose build
|
|
|
|
$ docker-compose up -d
|
|
|
|
$ docker-compose exec -u 1000 php bash
|
|
|
|
```
|
|
|
|
|
|
|
|
dans le conteneur php :
|
|
|
|
|
|
|
|
```
|
|
|
|
$ composer install
|
|
|
|
$ bin/console doctrine:schema:create
|
|
|
|
```
|
|
|
|
|
|
|
|
et pour node :
|
|
|
|
|
|
|
|
```
|
|
|
|
$ bash docker-node.sh yarn install --force
|
|
|
|
$ bash docker-node.sh yarn encore dev-server
|
|
|
|
```
|
|
|
|
|
|
|
|
Voilà, le site est disponible sur http://localhost:8000
|
|
|
|
|
|
|
|
|
|
|
|
## En partant de la branche *1_docker_ready*
|
|
|
|
|
|
|
|
### 1. Se mettre sur la bonne branche
|
2021-04-17 19:46:00 +00:00
|
|
|
|
2022-10-01 15:50:16 +00:00
|
|
|
```bash
|
|
|
|
$ git co -b 1_docker_ready origin/1_docker_ready
|
|
|
|
```
|
2021-04-17 19:46:00 +00:00
|
|
|
|
2022-10-01 16:38:56 +00:00
|
|
|
### 2. Construire les images et les conteneurs
|
2021-04-17 19:46:00 +00:00
|
|
|
|
2022-10-01 15:50:16 +00:00
|
|
|
```bash
|
|
|
|
$ docker-compose build
|
|
|
|
$ docker-compose up
|
|
|
|
.. 221001_test3_db_1 exited with code 1
|
|
|
|
```
|
2021-04-17 19:46:00 +00:00
|
|
|
|
2022-10-01 16:38:56 +00:00
|
|
|
### 3. Parce que 'db' ne se lance pas:
|
2021-04-17 19:46:00 +00:00
|
|
|
|
2022-10-01 15:50:16 +00:00
|
|
|
```bash
|
|
|
|
$ docker-compose rm db
|
|
|
|
$ sudo rm -rf ./data
|
|
|
|
$ docker-compose up db
|
|
|
|
```
|
2021-04-17 20:55:04 +00:00
|
|
|
|
2022-10-01 16:38:56 +00:00
|
|
|
### 4. Entrer dans le conteneur php
|
2021-04-17 20:55:04 +00:00
|
|
|
|
2022-10-01 15:50:16 +00:00
|
|
|
```bash
|
|
|
|
$ docker-compose exec -u 1000 php bash
|
|
|
|
```
|
2021-04-17 20:55:04 +00:00
|
|
|
|
2022-10-01 16:38:56 +00:00
|
|
|
### 5. Créer le projet
|
2021-04-17 20:55:04 +00:00
|
|
|
|
2022-10-01 15:50:16 +00:00
|
|
|
```bash
|
2022-10-01 16:38:56 +00:00
|
|
|
$ symfony new project
|
|
|
|
$ mv project/* . && mv project/.* . && rmdir project
|
2022-10-01 15:50:16 +00:00
|
|
|
```
|
2021-04-17 20:55:04 +00:00
|
|
|
|
2022-10-01 16:38:56 +00:00
|
|
|
### 6. Charger les dépendances de composer
|
2021-04-17 21:56:04 +00:00
|
|
|
|
2022-10-01 15:50:16 +00:00
|
|
|
```bash
|
|
|
|
$ composer require doctrine/annotations twig/twig doctrine/orm symfony/orm-pack symfony/form symfony/maker-bundle symfony/security-csrf
|
|
|
|
```
|
2021-04-17 21:56:04 +00:00
|
|
|
|
2022-10-01 16:38:56 +00:00
|
|
|
### 7. Connexion à postgresql
|
2021-04-17 21:56:04 +00:00
|
|
|
|
2022-10-01 15:50:16 +00:00
|
|
|
modifier DATABASE_URL dans app/.env :
|
|
|
|
```bash
|
|
|
|
+++ DATABASE_URL="postgresql://postgres:secret@db:5432/postgres?serverVersion=12&charset=utf8"
|
|
|
|
```
|
|
|
|
|
|
|
|
et dans le conteneur php :
|
|
|
|
```bash
|
|
|
|
$ bin/console doctrine:schema:create
|
|
|
|
```
|
|
|
|
|
2022-10-01 16:38:56 +00:00
|
|
|
### 8. Chargement de dépendances, la suite
|
2022-10-01 15:50:16 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
$ composer require symfony/yaml symfony/twig-bridge symfony/validator
|
|
|
|
|
|
|
|
$ composer require symfony/asset symfony/expression-language symfony/security-http symfony/translation symfony/web-link egulias/email-validator symfony/expression-language symfony/intl symfony/translation
|
|
|
|
|
|
|
|
$ composer require --dev symfony/profiler-pack symfony/debug-bundle symfony/var-dumper
|
|
|
|
```
|
|
|
|
|
2022-10-01 16:38:56 +00:00
|
|
|
### 9. Installer node et yarn
|
2022-10-01 15:50:16 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
$ composer require symfony/webpack-encore-bundle
|
|
|
|
```
|
|
|
|
|
|
|
|
mettre en place le script qui lance docker node, le lancer pour entrer dans le conteneur node:
|
|
|
|
```bash
|
|
|
|
$ yarn install --force
|
|
|
|
$ yarn add sass sass-loader
|
|
|
|
$ yarn encore dev-server
|
|
|
|
```
|
|
|
|
|
2022-10-01 16:38:56 +00:00
|
|
|
### 10. C'est installé !
|
2022-10-01 15:50:16 +00:00
|
|
|
|
|
|
|
le site est disponible sur http://localhost:8000
|