Skip to content

Commit

Permalink
Docker + migration + templating
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Baptiste Noblot committed Jul 22, 2021
1 parent d544597 commit 0875a4a
Show file tree
Hide file tree
Showing 23 changed files with 509 additions and 142 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"symfony/mime": "5.3.*",
"symfony/monolog-bundle": "^3.1",
"symfony/notifier": "5.3.*",
"symfony/polyfill-intl-messageformatter": "^1.23",
"symfony/process": "5.3.*",
"symfony/property-access": "5.3.*",
"symfony/property-info": "5.3.*",
Expand Down
86 changes: 85 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/packages/translation.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
framework:
default_locale: en
default_locale: fr
translator:
default_path: '%kernel.project_dir%/translations'
fallbacks:
Expand Down
34 changes: 23 additions & 11 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
version: '3.7'
services:
database:
image: 'postgres:alpine'
environment:
POSTGRES_PASSWORD: main
POSTGRES_USER: main
POSTGRES_DB: main
apache-php74:
build:
context: docker/apache
depends_on:
- mysql57
volumes:
- type: bind
source: .
target: /var/www/html/
ports:
- 8080:80

mysql57:
build:
context: docker/mysql
volumes:
- ~/Projects/tmp/mysql57_dblemenu:/var/lib/mysql
- ./docker/mysql/config:/etc/mysql/conf.d
ports:
# To allow the host machine to access the ports below, modify the lines below.
# For example, to allow the host to connect to port 3306 on the container, you would change
# "3306" to "3306:3306". Where the first port is exposed to the host and the second is the container port.
# See https://docs.docker.com/compose/compose-file/#ports for more information.
- '5432:5432'
- "3307:3306"
environment:
- MYSQL_ROOT_PASSWORD=root

#https://stackoverflow.com/questions/38088279/communication-between-multiple-docker-compose-projects
3 changes: 3 additions & 0 deletions docker/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/Oipnet/Docker-compose-apache-php_fpm

Organisation pas degeu
23 changes: 23 additions & 0 deletions docker/apache/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM php:7.4-apache

RUN apt update && apt install -y zip unzip libzip-dev zlib1g-dev libsodium-dev libonig-dev
RUN docker-php-ext-install -j$(nproc) mbstring bcmath zip sodium json opcache mysqli pdo pdo_mysql

ADD sites-available /etc/apache2/sites-available

WORKDIR /var/www/html

ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN a2ensite 999-gryapi
RUN a2dissite 000-default
RUN a2dissite default-ssl
#RUN /usr/sbin/apache2ctl -D FOREGROUND
RUN a2enmod rewrite
RUN service apache2 restart

RUN echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/20-xdebug.ini
RUN echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/20-xdebug.ini

EXPOSE 80
54 changes: 54 additions & 0 deletions docker/apache/sites-available/999-gryapi.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
ServerName le-menu.local

<VirtualHost *:80>
ServerName le-menu.local
ServerAlias www.le-menu.local
# The ServerName directive sets the request scheme, hostname and port that the server uses to identify itself.
# This is used when creating redirection URLs. In the context of virtual hosts, the ServerName specifies what
# hostname must appear in the request's Host: header to match this virtual host. For the default virtual host
# (this file) this value is not decisive as it is used as a last resort host regardless. However, you must set
# it for any further virtual host explicitly.

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/public/

DirectoryIndex /index.php

<Directory /var/www/html/public>
AllowOverride None
Order Allow,Deny
Allow from All

FallbackResource /index.php
</Directory>

# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/project>
# Options FollowSymlinks
# </Directory>

# optionally disable the fallback resource for the asset directories
# which will allow Apache to return a 404 error when files are
# not found instead of passing the request to Symfony
<Directory /var/www/project/public/bundles>
DirectoryIndex disabled
FallbackResource disabled
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn, error, crit, alert, emerg. It is also
#possible to configure the loglevel for particular modules, e.g. LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error-lemenu.log
CustomLog ${APACHE_LOG_DIR}/access-lemenu.log combined
# For most configuration files from conf-available/, which are enabled or disabled at a global level, it 1is
#possible to include a line for only one particular virtual host. For example the following line enables the CGI
#configuration for this host only after it has been globally disabled with "a2disconf". Include
#conf-available/serve-cgi-bin.conf

# optionally set the value of the environment variables used in the application
#SetEnv APP_ENV prod
#SetEnv APP_SECRET <app-secret-id>
#SetEnv DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name"
</VirtualHost>
1 change: 1 addition & 0 deletions docker/mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM mysql:5.7
3 changes: 3 additions & 0 deletions docker/mysql/config/myCustomConf.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[mysqld]
sql-mode='ANSI,TRADITIONAL'
# TRADITIONAL is equivalent to STRICT_TRANS_TABLES, STRICT_ALL_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, and NO_ENGINE_SUBSTITUTION.
71 changes: 71 additions & 0 deletions migrations/Version20210722151853.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210722151853 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE ingredient (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE ingredient_tag (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE ingredient_tag_ingredient (ingredient_tag_id INT NOT NULL, ingredient_id INT NOT NULL, INDEX IDX_A003A3A056A8A350 (ingredient_tag_id), INDEX IDX_A003A3A0933FE08C (ingredient_id), PRIMARY KEY(ingredient_tag_id, ingredient_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE menu (id INT AUTO_INCREMENT NOT NULL, restaurant_id INT NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, activate TINYINT(1) NOT NULL, INDEX IDX_7D053A93B1E7706E (restaurant_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE menu_item (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, price DOUBLE PRECISION UNSIGNED DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE menu_item_ingredient (menu_item_id INT NOT NULL, ingredient_id INT NOT NULL, INDEX IDX_EA047E5E9AB44FE0 (menu_item_id), INDEX IDX_EA047E5E933FE08C (ingredient_id), PRIMARY KEY(menu_item_id, ingredient_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE menu_item_tag (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE menu_item_tag_menu_item (menu_item_tag_id INT NOT NULL, menu_item_id INT NOT NULL, INDEX IDX_E3EE59FA54D70892 (menu_item_tag_id), INDEX IDX_E3EE59FA9AB44FE0 (menu_item_id), PRIMARY KEY(menu_item_tag_id, menu_item_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE menu_section (id INT AUTO_INCREMENT NOT NULL, menu_section_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, price DOUBLE PRECISION UNSIGNED DEFAULT NULL, INDEX IDX_A5A86751F98E57A8 (menu_section_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE menu_section_menu_item (menu_section_id INT NOT NULL, menu_item_id INT NOT NULL, INDEX IDX_982775A6F98E57A8 (menu_section_id), INDEX IDX_982775A69AB44FE0 (menu_item_id), PRIMARY KEY(menu_section_id, menu_item_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE restaurant (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, currency VARCHAR(5) DEFAULT \'EUR\' NOT NULL, activate TINYINT(1) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE ingredient_tag_ingredient ADD CONSTRAINT FK_A003A3A056A8A350 FOREIGN KEY (ingredient_tag_id) REFERENCES ingredient_tag (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE ingredient_tag_ingredient ADD CONSTRAINT FK_A003A3A0933FE08C FOREIGN KEY (ingredient_id) REFERENCES ingredient (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE menu ADD CONSTRAINT FK_7D053A93B1E7706E FOREIGN KEY (restaurant_id) REFERENCES restaurant (id)');
$this->addSql('ALTER TABLE menu_item_ingredient ADD CONSTRAINT FK_EA047E5E9AB44FE0 FOREIGN KEY (menu_item_id) REFERENCES menu_item (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE menu_item_ingredient ADD CONSTRAINT FK_EA047E5E933FE08C FOREIGN KEY (ingredient_id) REFERENCES ingredient (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE menu_item_tag_menu_item ADD CONSTRAINT FK_E3EE59FA54D70892 FOREIGN KEY (menu_item_tag_id) REFERENCES menu_item_tag (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE menu_item_tag_menu_item ADD CONSTRAINT FK_E3EE59FA9AB44FE0 FOREIGN KEY (menu_item_id) REFERENCES menu_item (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE menu_section ADD CONSTRAINT FK_A5A86751F98E57A8 FOREIGN KEY (menu_section_id) REFERENCES menu_section (id)');
$this->addSql('ALTER TABLE menu_section_menu_item ADD CONSTRAINT FK_982775A6F98E57A8 FOREIGN KEY (menu_section_id) REFERENCES menu_section (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE menu_section_menu_item ADD CONSTRAINT FK_982775A69AB44FE0 FOREIGN KEY (menu_item_id) REFERENCES menu_item (id) ON DELETE CASCADE');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE ingredient_tag_ingredient DROP FOREIGN KEY FK_A003A3A0933FE08C');
$this->addSql('ALTER TABLE menu_item_ingredient DROP FOREIGN KEY FK_EA047E5E933FE08C');
$this->addSql('ALTER TABLE ingredient_tag_ingredient DROP FOREIGN KEY FK_A003A3A056A8A350');
$this->addSql('ALTER TABLE menu_item_ingredient DROP FOREIGN KEY FK_EA047E5E9AB44FE0');
$this->addSql('ALTER TABLE menu_item_tag_menu_item DROP FOREIGN KEY FK_E3EE59FA9AB44FE0');
$this->addSql('ALTER TABLE menu_section_menu_item DROP FOREIGN KEY FK_982775A69AB44FE0');
$this->addSql('ALTER TABLE menu_item_tag_menu_item DROP FOREIGN KEY FK_E3EE59FA54D70892');
$this->addSql('ALTER TABLE menu_section DROP FOREIGN KEY FK_A5A86751F98E57A8');
$this->addSql('ALTER TABLE menu_section_menu_item DROP FOREIGN KEY FK_982775A6F98E57A8');
$this->addSql('ALTER TABLE menu DROP FOREIGN KEY FK_7D053A93B1E7706E');
$this->addSql('DROP TABLE ingredient');
$this->addSql('DROP TABLE ingredient_tag');
$this->addSql('DROP TABLE ingredient_tag_ingredient');
$this->addSql('DROP TABLE menu');
$this->addSql('DROP TABLE menu_item');
$this->addSql('DROP TABLE menu_item_ingredient');
$this->addSql('DROP TABLE menu_item_tag');
$this->addSql('DROP TABLE menu_item_tag_menu_item');
$this->addSql('DROP TABLE menu_section');
$this->addSql('DROP TABLE menu_section_menu_item');
$this->addSql('DROP TABLE restaurant');
}
}
33 changes: 33 additions & 0 deletions migrations/Version20210722220605.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210722220605 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE menu_menu_section (menu_id INT NOT NULL, menu_section_id INT NOT NULL, INDEX IDX_DAAA96F4CCD7E912 (menu_id), INDEX IDX_DAAA96F4F98E57A8 (menu_section_id), PRIMARY KEY(menu_id, menu_section_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE menu_menu_section ADD CONSTRAINT FK_DAAA96F4CCD7E912 FOREIGN KEY (menu_id) REFERENCES menu (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE menu_menu_section ADD CONSTRAINT FK_DAAA96F4F98E57A8 FOREIGN KEY (menu_section_id) REFERENCES menu_section (id) ON DELETE CASCADE');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE menu_menu_section');
}
}
19 changes: 19 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>

<rule ref="PSR12"/>

<file>bin/</file>
<file>config/</file>
<file>public/</file>
<file>src/</file>
<file>tests/</file>

</ruleset>
Loading

0 comments on commit 0875a4a

Please sign in to comment.