diff --git a/.docker/mysql/Dockerfile b/.docker/mysql/Dockerfile deleted file mode 100644 index 21feff6..0000000 --- a/.docker/mysql/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM mysql:8 - -ARG MYSQL_USER -ARG MYSQL_PASSWORD -ARG MYSQL_PORT - -# Securise line command "mysql" and "mysqldump" (you don't need to specify user + password) -RUN printf "[client]\n\ -host=localhost\n\ -user=$MYSQL_USER\n\ -password=$MYSQL_PASSWORD\n\ -port=$MYSQL_PORT\n\ -default-character-set=utf8" >> ~/.my.cnf diff --git a/.docker/php/Dockerfile b/.docker/php/Dockerfile index 65ac659..ede029b 100644 --- a/.docker/php/Dockerfile +++ b/.docker/php/Dockerfile @@ -4,12 +4,11 @@ FROM php:7.4-fpm RUN apt-get update && apt-get install -y --no-install-recommends vim curl locales apt-utils unzip # https://github.com/mlocati/docker-php-extension-installer -ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/ - -RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && install-php-extensions \ +COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ +RUN install-php-extensions @composer \ apcu opcache intl \ gd imagick \ - pdo_mysql \ + pdo_pgsql \ mbstring \ xdebug \ zip @@ -18,10 +17,6 @@ RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && install-php-ext COPY php.ini /usr/local/etc/php/php.ini COPY php-fpm-pool.conf /usr/local/etc/php/php-fpm.conf -# Install composer -RUN curl -sSk https://getcomposer.org/installer | php -- --disable-tls && \ - mv composer.phar /usr/local/bin/composer - # Purge RUN rm -rf /var/lib/apt/lists/* \ && apt-get purge --auto-remove -y g++ \ @@ -31,4 +26,4 @@ WORKDIR /var/www/ USER www-data EXPOSE 9000 -CMD ["php-fpm"] +CMD ["php-fpm"] \ No newline at end of file diff --git a/.docker/php/symfony-demo.env b/.docker/php/symfony-demo.env index 61e1415..323a450 100644 --- a/.docker/php/symfony-demo.env +++ b/.docker/php/symfony-demo.env @@ -25,7 +25,7 @@ APP_SECRET=2bd64f8d83b2e89d5f19d612841d6bb9 # For a MySQL database, use: "mysql://db_user:db_password@127.0.0.1:3306/db_name" # For a PostgreSQL database, use: "postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=11&charset=utf8" # IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml -DATABASE_URL=mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DATABASE} +DATABASE_URL=postgres://${PG_USER}:${PG_PASSWORD}@${PG_HOST}:${PG_PORT}/${PG_DATABASE} ###< doctrine/doctrine-bundle ### ###> symfony/mailer ### diff --git a/.docker/phpmyadmin/config.inc.php b/.docker/phpmyadmin/config.inc.php deleted file mode 100644 index 2cc9c97..0000000 --- a/.docker/phpmyadmin/config.inc.php +++ /dev/null @@ -1,171 +0,0 @@ -. - */ - -// NOTE; pour retirer l'avertissement "Vous devriez utiliser MySQL en version 5.5.0 ou plus r�cente." -/* - I went to /usr/share/phpMyAdmin/libraries/common.inc.php and comment out this lines: - #if (PMA_MYSQL_INT_VERSION < 50500) { - # PMA_fatalError( - # __('You should upgrade to %s %s or later.'), - # array('MySQL', '5.5.0') - # ); - #} - - http://stackoverflow.com/questions/26222244/phpmyadmin-error-you-should-upgrade-to-mysql-5-5-0-or-later -*/ - -/* - * This is needed for cookie based authentication to encrypt password in - * cookie - */ -$cfg['blowfish_secret'] = 'a8b7c6d'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */ - -/* - * Servers configuration - */ -$i = 0; - -/* - * First server - */ -++$i; -/* Authentication type */ -$cfg['Servers'][$i]['auth_type'] = 'config'; // cookie -/* Server parameters */ -$cfg['Servers'][$i]['host'] = getenv('PMA_HOST'); -$cfg['Servers'][$i]['port'] = getenv('PMA_PORT'); -$cfg['Servers'][$i]['connect_type'] = 'tcp'; -$cfg['Servers'][$i]['compress'] = false; - -/* Select mysql if your server does not have mysqli */ -$cfg['Servers'][$i]['extension'] = 'mysqli'; -$cfg['Servers'][$i]['AllowNoPassword'] = true; -$cfg['ThemeDefault'] = 'original'; // Theme par defaut -$cfg['ActionLinksMode'] = 'icons'; // Desactiver le texte pour les actions - -/* - * phpMyAdmin configuration storage settings. - */ - -/* User used to manipulate with storage */ -// $cfg['Servers'][$i]['controlhost'] = ''; -// $cfg['Servers'][$i]['controlport'] = ''; -// $cfg['Servers'][$i]['controluser'] = 'pma'; -// $cfg['Servers'][$i]['controlpass'] = 'pmapass'; - -$cfg['Servers'][$i]['user'] = getenv('PMA_USER'); -$cfg['Servers'][$i]['password'] = getenv('PMA_PASSWORD'); -$cfg['Servers'][$i]['hide_db'] = '^(information_schema|performance_schema|mysql|phpmyadmin)$'; - -/* Storage database and tables */ -// $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin'; -// $cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark'; -// $cfg['Servers'][$i]['relation'] = 'pma__relation'; -// $cfg['Servers'][$i]['table_info'] = 'pma__table_info'; -// $cfg['Servers'][$i]['table_coords'] = 'pma__table_coords'; -// $cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages'; -// $cfg['Servers'][$i]['column_info'] = 'pma__column_info'; -// $cfg['Servers'][$i]['history'] = 'pma__history'; -// $cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs'; -// $cfg['Servers'][$i]['tracking'] = 'pma__tracking'; -// $cfg['Servers'][$i]['designer_coords'] = 'pma__designer_coords'; -// $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig'; -// $cfg['Servers'][$i]['recent'] = 'pma__recent'; -// $cfg['Servers'][$i]['users'] = 'pma__users'; -// $cfg['Servers'][$i]['usergroups'] = 'pma__usergroups'; -// $cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding'; -/* Contrib / Swekey authentication */ -// $cfg['Servers'][$i]['auth_swekey_config'] = '/etc/swekey-pma.conf'; - -/* - * End of servers configuration - */ - -/* - * Directories for saving/loading files from server - */ -$cfg['UploadDir'] = ''; -$cfg['SaveDir'] = ''; - -/* - * Defines whether a user should be displayed a "show all (records)" - * button in browse mode or not. - * default = false - */ -//$cfg['ShowAll'] = true; - -/* - * Number of rows displayed when browsing a result set. If the result - * set contains more rows, "Previous" and "Next". - * default = 30 - */ -//$cfg['MaxRows'] = 50; - -/* - * disallow editing of binary fields - * valid values are: - * false allow editing - * 'blob' allow editing except for BLOB fields - * 'noblob' disallow editing except for BLOB fields - * 'all' disallow editing - * default = blob - */ -$cfg['ProtectBinary'] = false; -$cfg['ShowBlob'] = true; - -/* - * Default language to use, if not browser-defined or user-defined - * (you find all languages in the locale folder) - * uncomment the desired line: - * default = 'en' - */ -//$cfg['DefaultLang'] = 'en'; -//$cfg['DefaultLang'] = 'de'; - -/* - * default display direction (horizontal|vertical|horizontalflipped) - */ -//$cfg['DefaultDisplay'] = 'vertical'; - -/* - * How many columns should be used for table display of a database? - * (a value larger than 1 results in some information being hidden) - * default = 1 - */ -//$cfg['PropertiesNumColumns'] = 2; - -/* - * Set to true if you want DB-based query history.If false, this utilizes - * JS-routines to display query history (lost by window close) - * - * This requires configuration storage enabled, see above. - * default = false - */ -//$cfg['QueryHistoryDB'] = true; - -/* - * When using DB-based query history, how many entries should be kept? - * - * default = 25 - */ -//$cfg['QueryHistoryMax'] = 100; - -/* - * Should error reporting be enabled for JavaScript errors - * - * default = 'ask' - */ -//$cfg['SendErrorReports'] = 'ask'; - -/* - * You can find more configuration options in the documentation - * in the doc/ folder or at . - */ diff --git a/.docker/phpmyadmin/uploads.ini b/.docker/phppgadmin/uploads.ini similarity index 77% rename from .docker/phpmyadmin/uploads.ini rename to .docker/phppgadmin/uploads.ini index ebcfcb4..a7a35f9 100644 --- a/.docker/phpmyadmin/uploads.ini +++ b/.docker/phppgadmin/uploads.ini @@ -2,4 +2,4 @@ file_uploads = On memory_limit = 200M upload_max_filesize = 200M post_max_size = 200M -max_execution_time = 600 \ No newline at end of file +max_execution_time = 600 diff --git a/.env.dist b/.env.dist index d32881e..52b2a64 100644 --- a/.env.dist +++ b/.env.dist @@ -15,7 +15,7 @@ ###> symfony/framework-bundle ### APP_ENV=dev -APP_SECRET=1c033cf04c8c84f016ffa88768ee165a +APP_SECRET=2d044cf04c8c84f096ffa88768ee276c #TRUSTED_PROXIES=127.0.0.1,127.0.0.2 #TRUSTED_HOSTS='^localhost|example\.com$' ###< symfony/framework-bundle ### @@ -31,9 +31,10 @@ APP_SECRET=1c033cf04c8c84f016ffa88768ee165a COMPOSE_PROJECT_NAME=sfdemopg # VOLUME_USER_ID=1001 # You can set your Linux UserID (command: id -u) # COMPOSER_HOME=/home/$user/.cache/composer/ # You can set your composer folder, change $user by your username -MYSQL_DATABASE=demo -MYSQL_USER=local -MYSQL_PASSWORD=local -MYSQL_PORT=3306 +PG_HOST=db +PG_USER=local +PG_PASSWORD=local +PG_DATABASE=demo +PG_PORT=5432 TIMEZONE=Europe/Paris ###< Docker database conf ### diff --git a/.gitignore b/.gitignore index 4c844b1..db6436f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ project/ +!project/.gitkeep .env !.env.dist docker-compose.override.yml +dump_*.sql diff --git a/Makefile b/Makefile index 4d5d6e3..ed1090f 100755 --- a/Makefile +++ b/Makefile @@ -11,7 +11,6 @@ EXEC_ROOT?=$(DOCKER_COMPOSE) exec -u root php CONSOLE=bin/console PHPCSFIXER?=$(EXEC) php -d memory_limit=1024m vendor/bin/php-cs-fixer DOCKER_COMPOSE_OVERRIDE ?= dev -ENV ?= dev help: @grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(firstword $(MAKEFILE_LIST)) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/' @@ -31,7 +30,7 @@ stop: ## Stop docker containers restart: stop up-ci ## Restart docker containers -install: docker-compose.override.yml build up composer-install perm ## Create and start docker containers +install: docker-compose.override.yml build up ## Create and start docker containers install-demo: @$(EXEC_ROOT) chmod 775 /var/www @@ -40,19 +39,19 @@ install-demo: $(call composer,create-project symfony/symfony-demo demo) @cp .docker/php/symfony-demo.env project/.env @$(EXEC_ROOT) bash -c "mv demo/* . && rm -rf demo/ data/" - @make restart perm db-create-migration db-install db-fixtures clear-cache + @make restart perm db-create-migration db-install clear-cache status: ## Docker container status @$(DOCKER_COMPOSE) ps -uninstall: stop clear ## Remove docker containers +uninstall: clear stop ## Remove docker containers @$(DOCKER_COMPOSE) rm -vf reset: uninstall install ## Remove and re-create docker containers clear-cache: perm ## Clear + Prepare Cache (alias: c:c), you can specify the env: ENV=prod - @$(EXEC) $(CONSOLE) cache:clear --no-warmup --env=$(ENV) - @$(EXEC) $(CONSOLE) cache:warmup --env=$(ENV) + @$(EXEC) $(CONSOLE) cache:clear --no-warmup --env=$(APP_ENV) + @$(EXEC) $(CONSOLE) cache:warmup --env=$(APP_ENV) c\:c: clear-cache @@ -96,20 +95,40 @@ db-create-migration: ## Create migration @$(EXEC) $(CONSOLE) make:migration db-migrate: ## Migrate database schema to the latest available version - @$(EXEC) $(CONSOLE) doctrine:migration:migrate -n --env=$(ENV) + @$(EXEC) $(CONSOLE) doctrine:migration:migrate -n --env=$(APP_ENV) db-rollback: ## Rollback the latest executed migration - @$(EXEC) $(CONSOLE) doctrine:migration:migrate prev -n --env=$(ENV) + @$(EXEC) $(CONSOLE) doctrine:migration:migrate prev -n --env=$(APP_ENV) db-validate: ## Check the ORM mapping @$(EXEC) $(CONSOLE) doctrine:schema:validate -db-install: ## Install database, you can add 'db-fixtures' argument for apply fixtures after install - @$(EXEC) $(CONSOLE) doctrine:database:create --if-not-exists - @$(EXEC) $(CONSOLE) doctrine:migrations:migrate -n --env=$(ENV) +db-create-database: ## Drop and create empty database + @$(EXEC) $(CONSOLE) doctrine:database:drop --force + @$(EXEC) $(CONSOLE) doctrine:database:create db-fixtures: ## Apply doctrine fixtures - @$(EXEC) $(CONSOLE) doctrine:fixtures:load -n --env=$(ENV) + @$(EXEC) $(CONSOLE) doctrine:fixtures:load -n --env=$(APP_ENV) + +db-install: db-create-database db-migrate db-fixtures ## Drop and install database with schema + fixtures + +db-dump: ## Dump data only from database on dump_DBNAME.sql file + @docker-compose exec db pg_dump -U $(PG_USER) -p $(PG_PORT) --data-only $(PG_DATABASE) > dump_$(PG_DATABASE).sql + @ls -l dump_$(PG_DATABASE).sql + +db-dump-full: ## Dump Schema + Data from database on dump_DBNAME.sql file + @docker-compose exec db pg_dump -U $(PG_USER) -p $(PG_PORT) $(PG_DATABASE) > dump_$(PG_DATABASE).sql + @ls -l dump_$(PG_DATABASE).sql + +db-import-data: db-create-database db-migrate ## Import dump "dump_DBNAME.sql" (data only), the database will be reset before import + @docker-compose exec -T db psql -U $(PG_USER) -p $(PG_PORT) $(PG_DATABASE) < dump_$(PG_DATABASE).sql + +db-import-full: db-create-database ## Import dump "dump_DBNAME.sql" (schema + data), the database will be reset before import + @docker-compose exec -T db psql -U $(PG_USER) -p $(PG_PORT) $(PG_DATABASE) < dump_$(PG_DATABASE).sql + +db-query: ## Execute query $CMD="postgres query" + @docker-compose exec -T db psql -U $(PG_USER) -p $(PG_PORT) $(PG_DATABASE) -c "$(CMD)" + # ## # ## Assets diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 243bf01..16af2bc 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -1,42 +1,33 @@ version: '3.6' services: db: - build: - context: .docker/mysql - args: - MYSQL_USER: ${MYSQL_USER} - MYSQL_PASSWORD: ${MYSQL_PASSWORD} - MYSQL_PORT: ${MYSQL_PORT} ports: - - 33060:3306 # Reserve port to localhost for database connexion on phpstorm - volumes: - - mysql-db:/var/lib/mysql + - 54320:5432 - phpmyadmin: - image: phpmyadmin/phpmyadmin + # https://hub.docker.com/r/neimheadh/phppgadmin + phppgadmin: + image: neimheadh/phppgadmin:latest labels: traefik.enable: true traefik.http.services.pma.loadbalancer.server.port: 80 - traefik.http.routers.pma.rule: "Host(`pma.localhost.tv`)" + traefik.http.routers.pma.rule: "Host(`pga.localhost.tv`)" traefik.http.routers.pma.entrypoints: web - environment: - PMA_HOST: db - PMA_PORT: 3306 - PMA_USER: ${MYSQL_USER} - PMA_PASSWORD: ${MYSQL_PASSWORD} ports: - - 80 + - "80" + environment: + POSTGRES_HOST: ${PG_HOST} + POSTGRES_PORT: ${PG_PORT} + POSTGRES_USER: ${PG_USER} + POSTGRES_PASS: ${PG_PASSWORD} + restart: always volumes: - - ./.docker/phpmyadmin/config.inc.php:/etc/phpmyadmin/config.user.inc.php - - ./.docker/phpmyadmin/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini + - ./.docker/phppgadmin/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini depends_on: - db - links: - - db networks: - sfdemo: + sfdemopg: aliases: - - pma.localhost.tv + - pga.localhost.tv maildev: image: djfarrelly/maildev @@ -48,7 +39,7 @@ services: - 80 - 25 networks: - sfdemo: + sfdemopg: aliases: - maildev.localhost.tv @@ -67,7 +58,7 @@ services: volumes: - /var/run/docker.sock:/var/run/docker.sock:ro networks: - - sfdemo + - sfdemopg volumes: - mysql-db: #Keep database on local docker storage + pgdata: #Keep database on local docker storage diff --git a/docker-compose.yml b/docker-compose.yml index ec7ec5c..bc22e74 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ services: image: nginx labels: traefik.enable: true - traefik.docker.network: sfdemo + traefik.docker.network: sfdemopg traefik.http.services.www.loadbalancer.server.port: 80 traefik.http.routers.www.rule: "Host(`demo.localhost.tv`)" traefik.http.routers.www.entrypoints: web @@ -19,34 +19,33 @@ services: depends_on: - php networks: - sfdemo: + sfdemopg: aliases: - demo.localhost.tv db: - image: mysql:8 - command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci + image: postgres:13 restart: always environment: - MYSQL_ROOT_PASSWORD: ${MYSQL_PASSWORD} - MYSQL_DATABASE: ${MYSQL_DATABASE} - MYSQL_USER: ${MYSQL_USER} - MYSQL_PASSWORD: ${MYSQL_PASSWORD} - TZ: ${TIMEZONE:-Europe/Paris} + POSTGRES_USER: ${PG_USER} + POSTGRES_PASSWORD: ${PG_PASSWORD} + POSTGRES_DB: ${PG_DATABASE} + volumes: + - pgdata:/var/lib/postgresql/data ports: - - 3306 + - 5432 networks: - - sfdemo + - sfdemopg php: build: .docker/php restart: always environment: - MYSQL_HOST: db - MYSQL_USER: ${MYSQL_USER} - MYSQL_PASSWORD: ${MYSQL_PASSWORD} - MYSQL_PORT: ${MYSQL_PORT} - MYSQL_DATABASE: ${MYSQL_DATABASE} + PG_HOST: ${PG_HOST} + PG_USER: ${PG_USER} + PG_PASSWORD: ${PG_PASSWORD} + PG_PORT: ${PG_PORT} + PG_DATABASE: ${PG_DATABASE} volumes: - ./project:/var/www - ${COMPOSER_HOME:-/tmp/composer}:/home/www-data/.composer # Share composer cache @@ -54,8 +53,8 @@ services: - db user: "${VOLUME_USER_ID:-www-data}:www-data" networks: - - sfdemo + - sfdemopg networks: - sfdemo: + sfdemopg: driver: bridge diff --git a/project/.gitignore b/project/.gitkeep similarity index 100% rename from project/.gitignore rename to project/.gitkeep diff --git a/readme.md b/readme.md index d3d2b02..89c5f12 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,5 @@ -# Docker Nginx + PHP + Mysql + Dev Tools -A Docker image based on Ubuntu, serving PHP 5 or 7 running as Apache Module. Useful for Web developers in need for a fixed PHP version. In addition, the `error_reporting` setting in php.ini is configurable per container via environment variable. +# Docker Nginx + PHP + Postgres + Dev Tools +A Docker image based on Ubuntu, serving PHP 7.4 FPM running as Nginx Module. Useful for Web developers in need for a fixed PHP version. In addition, the `error_reporting` setting in php.ini is configurable per container via environment variable. ## Prerequisite @@ -13,6 +13,9 @@ Before use the docker version, check that ports 80/8080/443 are available. If an ```shell script make install + +# If symfony project is present on project folder +make install composer-install perm ``` **Installed packages:** @@ -25,7 +28,7 @@ make install * php-imagick * php-intl * php-mbstring -* php-pdo_mysql +* php-pdo_pgsql * php-opcache * php-zip * composer (php package manager) @@ -41,16 +44,21 @@ Launch docker containers: `make up`, or stop with `make stop`, you can get comma You can connect on url application: * [Example Symfony Demo](http://demo.localhost.tv) -* [phpMyAdmin](http://pma.localhost.tv) +* [phpPgAdmin](http://pga.localhost.tv) * [mailDev](http://maildev.localhost.tv) ## Dev environment If you use dev docker file _(default configuration)_, you have additional tools: -* You can access to mysql on localhost:33060 (for PhpStorm / Mysql Workbench). -* You can use mysql command line without indicate user/pass: - * Standard request: `docker-compose exec db mysql symfony -e "show tables;"` - * Dump: `docker-compose exec db mysqldump symfony > export.sql` +* You can access to postgres on localhost:54320 (for PhpStorm / Postgres Workbench). +* You can use postgres command line without indicate user/pass: + * Standard request: + * `make db-query CMD="SELECT id, title, published_at FROM symfony_demo_post LIMIT 5"` + * or `make db-query CMD="\dt"` (show tables list) + * Dump (data only): `make db-dump` + * Dump (data with schema): `make db-dump-full` + * Import dump (data only): `make db-import-data` + * Import dump (data with schema): `make db-import-full` Enjoy \ No newline at end of file