From 344b3f8a946ba827b87bd84ecdcbd51f642aef42 Mon Sep 17 00:00:00 2001 From: Hubert Filar Date: Fri, 19 Jul 2024 11:51:17 +0200 Subject: [PATCH 1/8] OP-291: Add docker support --- .docker/fpm.conf | 21 ++++++++++++ .docker/nginx.conf | 48 ++++++++++++++++++++++++++ .docker/php.ini | 15 +++++++++ .docker/supervisord.conf | 14 ++++++++ Dockerfile | 73 ++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 45 +++++++++++++++++++++++++ tests/Application/.env | 2 +- 7 files changed, 217 insertions(+), 1 deletion(-) create mode 100644 .docker/fpm.conf create mode 100644 .docker/nginx.conf create mode 100644 .docker/php.ini create mode 100644 .docker/supervisord.conf create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.docker/fpm.conf b/.docker/fpm.conf new file mode 100644 index 00000000..4f0c372e --- /dev/null +++ b/.docker/fpm.conf @@ -0,0 +1,21 @@ +[www] +user = www-data +group = www-data + +listen = /var/run/php-www.sock +listen.owner = www-data +listen.group = www-data +listen.mode = 0660 + +clear_env = no + +pm = dynamic +pm.max_children = 5 +pm.start_servers = 2 +pm.min_spare_servers = 1 +pm.max_spare_servers = 3 + +pm.status_path = /status +catch_workers_output = yes + +security.limit_extensions = .php diff --git a/.docker/nginx.conf b/.docker/nginx.conf new file mode 100644 index 00000000..7fa27004 --- /dev/null +++ b/.docker/nginx.conf @@ -0,0 +1,48 @@ +user www-data; +worker_processes auto; +daemon off; +pid /run/nginx.pid; + +include /etc/nginx/modules-enabled/*.conf; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + server_tokens off; + + client_max_body_size 64m; + sendfile on; + tcp_nodelay on; + tcp_nopush on; + + gzip_vary on; + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + server { + listen 80; + + root /app/tests/Application/public; + index index.php; + + location / { + try_files $uri /index.php$is_args$args; + } + + location ~ \.php$ { + include fastcgi_params; + + fastcgi_pass unix:/var/run/php-www.sock; + fastcgi_split_path_info ^(.+\.php)(/.*)$; + + fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; + fastcgi_param DOCUMENT_ROOT $realpath_root; + } + } +} diff --git a/.docker/php.ini b/.docker/php.ini new file mode 100644 index 00000000..c283a534 --- /dev/null +++ b/.docker/php.ini @@ -0,0 +1,15 @@ +[PHP] +memory_limit=512M + +[date] +date.timezone=${PHP_DATE_TIMEZONE} + +[opcache] +opcache.enable=0 +opcache.memory_consumption=256 +opcache.max_accelerated_files=20000 +opcache.validate_timestamps=0 +;opcache.preload=/app/config/preload.php +opcache.preload_user=www-data +opcache.jit=1255 +opcache.jit_buffer_size=256M diff --git a/.docker/supervisord.conf b/.docker/supervisord.conf new file mode 100644 index 00000000..913adb67 --- /dev/null +++ b/.docker/supervisord.conf @@ -0,0 +1,14 @@ +[supervisord] +nodaemon = true +user = root +pidfile = /run/supervisord.pid + +[program:nginx] +command = /usr/sbin/nginx +user = root +autostart = true + +[program:php-fpm] +command = /usr/sbin/php-fpm -F +user = root +autostart = true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..834732c5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,73 @@ +FROM ubuntu:20.04 +ARG DEBIAN_FRONTEND=noninteractive +ARG PHP_VERSION=8.1 +ENV LC_ALL=C.UTF-8 + +# Install basic tools +RUN apt-get update && apt-get install -y \ + software-properties-common \ + curl \ + make \ + supervisor \ + unzip \ + python2 \ + g++ + +# Append NODE, NGINX and PHP repositories +RUN add-apt-repository ppa:ondrej/php \ + && add-apt-repository ppa:ondrej/nginx \ + && curl -sL https://deb.nodesource.com/setup_14.x | bash - + +# Install required PHP extensions +RUN apt-get update && apt-get install -y \ + nodejs \ + nginx \ + php${PHP_VERSION} \ + php${PHP_VERSION}-apcu \ + php${PHP_VERSION}-calendar \ + php${PHP_VERSION}-common \ + php${PHP_VERSION}-cli \ + php${PHP_VERSION}-ctype \ + php${PHP_VERSION}-curl \ + php${PHP_VERSION}-dom \ + php${PHP_VERSION}-exif \ + php${PHP_VERSION}-fpm \ + php${PHP_VERSION}-gd \ + php${PHP_VERSION}-intl \ + php${PHP_VERSION}-mbstring \ + php${PHP_VERSION}-mysql \ + php${PHP_VERSION}-opcache \ + php${PHP_VERSION}-pdo \ + php${PHP_VERSION}-pgsql \ + php${PHP_VERSION}-sqlite \ + php${PHP_VERSION}-xml \ + php${PHP_VERSION}-xsl \ + php${PHP_VERSION}-yaml \ + php${PHP_VERSION}-zip + +# Install Composer +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename composer + +# Cleanup +RUN apt-get remove --purge -y software-properties-common curl && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* /usr/share/man/* + +# Create directory for php-fpm socket +# Link php-fpm binary file without version +# -p Creates missing intermediate path name directories +RUN ln -s /usr/sbin/php-fpm${PHP_VERSION} /usr/sbin/php-fpm && mkdir -p /run/php + +# Install yarn +RUN npm install -g yarn && npm cache clean --force + +# Initialize config files +COPY .docker/supervisord.conf /etc/supervisor/conf.d/supervisor.conf +COPY .docker/nginx.conf /etc/nginx/nginx.conf +COPY .docker/fpm.conf /etc/php/${PHP_VERSION}/fpm/pool.d/www.conf +COPY .docker/php.ini /etc/php/${PHP_VERSION}/fpm/php.ini +COPY .docker/php.ini /etc/php/${PHP_VERSION}/cli/php.ini + +WORKDIR /app + +EXPOSE 80 + +CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..3c53ae87 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,45 @@ +services: + app: + container_name: app + build: + context: . + environment: + APP_ENV: "dev" + DATABASE_URL: "mysql://root:mysql@mysql/sylius_%kernel.environment%?charset=utf8mb4" +# DATABASE_URL: "pgsql://root:postgres@postgres/sylius_%kernel.environment%?charset=utf8" # When using postgres + PHP_DATE_TIMEZONE: "Europe/Warsaw" + volumes: + - ./:/app:delegated + - ./.docker/php.ini:/etc/php8/php.ini:delegated + - ./.docker/nginx.conf:/etc/nginx/nginx.conf:delegated + ports: + - 80:80 + depends_on: + - mysql + networks: + - sylius + + mysql: + container_name: mysql + image: mysql:8.0 + platform: linux/amd64 + environment: + MYSQL_ROOT_PASSWORD: mysql + ports: + - ${MYSQL_PORT:-3306}:3306 + networks: + - sylius + +# postgres: +# image: postgres:14-alpine +# environment: +# POSTGRES_USER: root +# POSTGRES_PASSWORD: postgres +# ports: +# - ${POSTGRES_PORT:-5432}:5432 +# networks: +# - sylius + +networks: + sylius: + driver: bridge diff --git a/tests/Application/.env b/tests/Application/.env index 2a35c9e9..c6a0f029 100755 --- a/tests/Application/.env +++ b/tests/Application/.env @@ -12,7 +12,7 @@ APP_SECRET=EDITME # Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url # For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db" # Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls -DATABASE_URL=mysql://root@127.0.0.1/sylius_wish_list_plugin_%kernel.environment%?serverVersion=5.7 +DATABASE_URL=mysql://root@127.0.0.1/sylius_wish_list_plugin_%kernel.environment% ###< doctrine/doctrine-bundle ### ###> symfony/swiftmailer-bundle ### From 4fa91a6146783d32dfae9951ab90025666478765 Mon Sep 17 00:00:00 2001 From: Hubert Filar Date: Fri, 19 Jul 2024 11:53:55 +0200 Subject: [PATCH 2/8] OP-291: Delete resource override, document it --- doc/01-installation.md | 18 ++++++++++++++---- src/Resources/config/config.yml | 1 - src/Resources/config/resources.yml | 5 ----- tests/Application/config/resources.yml | 5 +++++ 4 files changed, 19 insertions(+), 10 deletions(-) delete mode 100644 src/Resources/config/resources.yml create mode 100644 tests/Application/config/resources.yml diff --git a/doc/01-installation.md b/doc/01-installation.md index 382c5204..63e1f986 100644 --- a/doc/01-installation.md +++ b/doc/01-installation.md @@ -42,13 +42,23 @@ bitbag_sylius_wishlist_plugin: resource: "@BitBagSyliusWishlistPlugin/Resources/config/routing.yml" ``` -5. Clear application cache by using command: +5. Override `OrderItemController` +```yaml +sylius_order: + resources: + order_item: + classes: + controller: BitBag\SyliusWishlistPlugin\Controller\OrderItemController + +``` + +6. Clear application cache by using command: ```bash $ bin/console cache:clear ``` -6. Update your database +7. Update your database First, please run legacy-versioned migrations by using command: @@ -71,14 +81,14 @@ $ bin/console doctrine:migrations:migrate $ bin/console doctrine:migrations:version BitBag\\SyliusWishlistPlugin\\Migrations\\Version20201029161558 --add --no-interaction ``` -7. Please add plugin templates into your project: +8. Please add plugin templates into your project: ```bash $ cp -R vendor/bitbag/wishlist-plugin/tests/Application/templates/bundles/SyliusShopBundle/Product templates/bundles/SyliusShopBundle $ cp vendor/bitbag/wishlist-plugin/tests/Application/templates/bundles/SyliusShopBundle/_header.html.twig templates/bundles/SyliusShopBundle $ cp vendor/bitbag/wishlist-plugin/tests/Application/templates/bundles/SyliusShopBundle/_logo.html.twig templates/bundles/SyliusShopBundle ``` -8. Add plugin assets to your project +9. Add plugin assets to your project We recommend you to use Webpack (Encore), for which we have prepared four different instructions on how to add this plugin's assets to your project: diff --git a/src/Resources/config/config.yml b/src/Resources/config/config.yml index 45b7a36e..53ed0724 100644 --- a/src/Resources/config/config.yml +++ b/src/Resources/config/config.yml @@ -1,3 +1,2 @@ imports: - { resource: "@BitBagSyliusWishlistPlugin/Resources/config/services.xml" } - - { resource: "@BitBagSyliusWishlistPlugin/Resources/config/resources.yml" } diff --git a/src/Resources/config/resources.yml b/src/Resources/config/resources.yml deleted file mode 100644 index 44729c9f..00000000 --- a/src/Resources/config/resources.yml +++ /dev/null @@ -1,5 +0,0 @@ -sylius_order: - resources: - order_item: - classes: - controller: BitBag\SyliusWishlistPlugin\Controller\OrderItemController diff --git a/tests/Application/config/resources.yml b/tests/Application/config/resources.yml new file mode 100644 index 00000000..ea29f50e --- /dev/null +++ b/tests/Application/config/resources.yml @@ -0,0 +1,5 @@ +sylius_order: + resources: + order_item: + classes: + controller: BitBag\SyliusWishlistPlugin\Controller\OrderItemController From 0568a1f2819d7c0b28127e0a342b6e2548d52bab Mon Sep 17 00:00:00 2001 From: Hubert Filar Date: Fri, 19 Jul 2024 11:56:38 +0200 Subject: [PATCH 3/8] OP-291: Delete package.json distinction --- .github/workflows/build.yml | 5 --- ...package.json.~1.12.0.dist => package.json} | 0 tests/Application/package.json.~1.13.0.dist | 41 ------------------- 3 files changed, 46 deletions(-) rename tests/Application/{package.json.~1.12.0.dist => package.json} (100%) delete mode 100755 tests/Application/package.json.~1.13.0.dist diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 42bc283d..fe2db96f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -136,11 +136,6 @@ jobs: restore-keys: | ${{ runner.os }}-node-${{ matrix.node }}-yarn- - - - name: Copy package.json.dist to package.json - if: matrix.sylius != '' - run: (cd tests/Application && cp package.json.\${{ matrix.sylius }}.dist package.json) - - name: Install JS dependencies run: (cd tests/Application && yarn install) diff --git a/tests/Application/package.json.~1.12.0.dist b/tests/Application/package.json similarity index 100% rename from tests/Application/package.json.~1.12.0.dist rename to tests/Application/package.json diff --git a/tests/Application/package.json.~1.13.0.dist b/tests/Application/package.json.~1.13.0.dist deleted file mode 100755 index 36e6c1f0..00000000 --- a/tests/Application/package.json.~1.13.0.dist +++ /dev/null @@ -1,41 +0,0 @@ -{ - "dependencies": { - "@babel/polyfill": "^7.0.0", - "chart.js": "^3.7.1", - "jquery": "^3.5.0", - "jquery.dirtyforms": "^2.0.0", - "lightbox2": "^2.9.0", - "semantic-ui-css": "^2.2.0", - "slick-carousel": "^1.8.1" - }, - "devDependencies": { - "@symfony/webpack-encore": "^1.6.1", - "babel-core": "^6.26.3", - "babel-plugin-external-helpers": "^6.22.0", - "babel-plugin-module-resolver": "^3.1.1", - "babel-plugin-transform-object-rest-spread": "^6.26.0", - "babel-preset-env": "^1.7.0", - "babel-register": "^6.26.0", - "dedent": "^0.7.0", - "eslint": "^4.19.1", - "eslint-config-airbnb-base": "^12.1.0", - "eslint-import-resolver-babel-module": "^4.0.0", - "eslint-plugin-import": "^2.11.0", - "merge-stream": "^1.0.0", - "sass": "^1.39.2", - "sass-loader": "^12.1.0" - }, - "scripts": { - "dev": "yarn encore dev", - "watch": "yarn encore dev --watch", - "prod": "yarn encore prod", - "lint": "yarn lint:js", - "lint:js": "eslint gulpfile.babel.js" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/Sylius/Sylius.git" - }, - "author": "Paweł Jędrzejewski", - "license": "MIT" -} From 9cd21f47b2f6e36fd7fdb173e3f1998bbd73efb7 Mon Sep 17 00:00:00 2001 From: Hubert Filar Date: Wed, 18 Sep 2024 13:47:22 +0200 Subject: [PATCH 4/8] OP-291: Bump php version used in docker env --- .github/workflows/build.yml | 4 ++-- Dockerfile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fe2db96f..e2d316da 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -190,7 +190,7 @@ jobs: - name: Upload Behat logs - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: failure() with: name: Behat logs @@ -199,7 +199,7 @@ jobs: - name: Upload test log logs - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: failure() with: name: Var logs diff --git a/Dockerfile b/Dockerfile index 834732c5..988443fa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:20.04 ARG DEBIAN_FRONTEND=noninteractive -ARG PHP_VERSION=8.1 +ARG PHP_VERSION=8.3 ENV LC_ALL=C.UTF-8 # Install basic tools From ceaee016cc739f3916523f0aeb8684051166a5bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Deszert-K=C5=82osowski?= Date: Fri, 27 Sep 2024 09:46:02 +0200 Subject: [PATCH 5/8] docker instructions Updated instructions for docker use. --- doc/04-development.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/04-development.md b/doc/04-development.md index 8a83b71c..d0a57fa3 100644 --- a/doc/04-development.md +++ b/doc/04-development.md @@ -65,4 +65,19 @@ $ yarn watch It's an infinite process, which will watch your changes in the assets folder and (re)build them. So all of your frontend changes should be done in `{root}/src/Resources/assets` directory. We have configured two independent entry points that should not be combined - `shop` for the storefront and `admin` for the admin panel. -> **⚠ Note**: Before every commit, you should type the `yarn dist` command from the plugin root directory to rebuild dist assets, which are located in `{root}/src/Resources/public`.

You also shouldn't add assets to this folder manually because **they will be removed automatically** \ No newline at end of file +> **⚠ Note**: Before every commit, you should type the `yarn dist` command from the plugin root directory to rebuild dist assets, which are located in `{root}/src/Resources/public`.

You also shouldn't add assets to this folder manually because **they will be removed automatically** + +#### Docker + +To test plugin with docker You can use: + +```bash +$ docker-compose up +$ docker-compose exec -it app composer install +$ docker-compose exec -it app yarn install +$ docker-compose exec -it -w /app/tests/Application app bin/console d:d:c +$ docker-compose exec -it -w /app/tests/Application app bin/console d:s:c +$ docker-compose exec -it -w /app/tests/Application app bin/console sy:fi:lo -q +``` + +This should make sure test app from docker container is up and running. From 3cbee511904c2e4b29b872cbbfffaa47ef6e9433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Deszert-K=C5=82osowski?= Date: Fri, 27 Sep 2024 09:46:35 +0200 Subject: [PATCH 6/8] Update 04-development.md --- doc/04-development.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/04-development.md b/doc/04-development.md index d0a57fa3..deb9b9f1 100644 --- a/doc/04-development.md +++ b/doc/04-development.md @@ -8,6 +8,8 @@ - [Installation](#installation) - [Development](#development) - [Frontend](#frontend) +- [Docker](#docker) + #### Installation From a52dce03cb90527d0e1a4312de9624cbc745605b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Kukli=C5=84ski?= Date: Tue, 8 Oct 2024 20:58:23 +0200 Subject: [PATCH 7/8] Add bin/fixtures script for loading fixtures in docker --- bin/fixtures | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 bin/fixtures diff --git a/bin/fixtures b/bin/fixtures new file mode 100755 index 00000000..2c0180fe --- /dev/null +++ b/bin/fixtures @@ -0,0 +1,14 @@ +#!/bin/bash + +mkdir -p tests/Application/var/log +mkdir -p tests/Application/var/cache +chown www-data:www-data tests/Application/var/log +chown www-data:www-data tests/Application/var/cache + +chown -Rf www-data:www-data tests/Application/public/media +chown -Rf www-data:www-data tests/Application/public/media/* + +tests/Application/bin/console cache:clear +tests/Application/bin/console doctrine:database:create --if-not-exists +tests/Application/bin/console doctrine:schema:update --force +tests/Application/bin/console sylius:fixtures:load -n From 8d8981b9a8dda8c9f34f591561e2cbe0008ba9c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Kukli=C5=84ski?= Date: Tue, 8 Oct 2024 21:50:50 +0200 Subject: [PATCH 8/8] Fix issues related to docker application setup --- bin/{fixtures => docker-setup} | 10 ++++++++-- docker-compose.yml | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) rename bin/{fixtures => docker-setup} (63%) diff --git a/bin/fixtures b/bin/docker-setup similarity index 63% rename from bin/fixtures rename to bin/docker-setup index 2c0180fe..58aeb87c 100755 --- a/bin/fixtures +++ b/bin/docker-setup @@ -2,13 +2,19 @@ mkdir -p tests/Application/var/log mkdir -p tests/Application/var/cache -chown www-data:www-data tests/Application/var/log -chown www-data:www-data tests/Application/var/cache +chown -Rf www-data:www-data tests/Application/var/log +chown -Rf www-data:www-data tests/Application/var/cache chown -Rf www-data:www-data tests/Application/public/media chown -Rf www-data:www-data tests/Application/public/media/* +composer install + tests/Application/bin/console cache:clear +tests/Application/bin/console assets:install tests/Application/bin/console doctrine:database:create --if-not-exists tests/Application/bin/console doctrine:schema:update --force tests/Application/bin/console sylius:fixtures:load -n + +(cd tests/Application && yarn install) +(cd tests/Application && yarn dev) diff --git a/docker-compose.yml b/docker-compose.yml index 3c53ae87..8c88251a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,8 @@ services: context: . environment: APP_ENV: "dev" - DATABASE_URL: "mysql://root:mysql@mysql/sylius_%kernel.environment%?charset=utf8mb4" + DATABASE_SERVER_VERSION: "8.0.39" + DATABASE_URL: "mysql://root:mysql@mysql/sylius_%kernel.environment%??charset=utf8mb4&serverVersion=8.0.39" # DATABASE_URL: "pgsql://root:postgres@postgres/sylius_%kernel.environment%?charset=utf8" # When using postgres PHP_DATE_TIMEZONE: "Europe/Warsaw" volumes: