From 95fa44d3e9a7c235eda1a185310aff1b3e4d5d0b Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Wed, 6 Jul 2022 02:17:26 +0300 Subject: [PATCH] Adding experimental Dockerfile with RoadRunner. --- .dockerignore | 43 +++++++++++++++++++++++++++++++++++++++++++ .env | 2 +- Dockerfile | 36 +++++++++++++++++++++++++++++------- README.md | 21 +++++++++++++++++++++ docker-compose.yml | 15 +++++++++------ 5 files changed, 103 insertions(+), 14 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4a177f5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,43 @@ +### Symfony template +# Cache and logs (Symfony2) +/app/cache/* +/app/logs/* +!app/cache/.gitkeep +!app/logs/.gitkeep + +# Email spool folder +/app/spool/* + +# Cache, session files and logs (Symfony3) +/var/cache/* +/var/sessions/* +!var/cache/.gitkeep +!var/sessions/.gitkeep + +# Logs (Symfony4) +/var/log/* +!var/log/.gitkeep + +# Managed by Composer +/app/bootstrap.php.cache +/var/bootstrap.php.cache +/bin/* +!bin/console +!bin/symfony_requirements +/vendor/ + +# PHPUnit +/app/phpunit.xml +/phpunit.xml + +# Composer PHAR +/composer.phar + +# Backup entities generated with doctrine:generate:entities command +**/Entity/*~ + +# Embedded web-server pid file +/.web-server-pid + +# DotEnv +.env.local \ No newline at end of file diff --git a/.env b/.env index 58e02c4..06386d7 100644 --- a/.env +++ b/.env @@ -3,7 +3,7 @@ # https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration ###> symfony/framework-bundle ### -APP_ENV=dev +APP_ENV=prod APP_SECRET=xxx ###< symfony/framework-bundle ### diff --git a/Dockerfile b/Dockerfile index 7d4b622..8899659 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,39 @@ -FROM php:8.1-fpm-alpine +# https://github.com/roadrunner-server/roadrunner/pkgs/container/roadrunner +FROM ghcr.io/roadrunner-server/roadrunner:latest AS roadrunner +FROM php:8.1-alpine ENV PHP_TIMEZONE Europe/Moscow +ENV APP_ENV=prod + +WORKDIR /app + +COPY --from=roadrunner /usr/bin/rr /app/bin/rr +COPY . /app/ RUN apk update && \ - apk add postgresql-dev libpq && \ - docker-php-ext-configure igbinary && \ + apk add autoconf build-base icu libpq postgresql-dev && \ docker-php-ext-configure intl && \ docker-php-ext-configure pdo_pgsql && \ - docker-php-ext-install -j$(nproc) igbinary && \ - docker-php-ext-install -j$(nproc) instl && \ + docker-php-ext-configure sockets && \ + docker-php-ext-install -j$(nproc) intl && \ docker-php-ext-install -j$(nproc) pdo_pgsql && \ + docker-php-ext-install -j$(nproc) sockets && \ + #pecl install igbinary-3.2.7 && \ pecl install redis-5.3.7 && \ + #docker-php-ext-enable igbinary && \ + docker-php-ext-enable intl && \ + docker-php-ext-enable pdo_pgsql && \ docker-php-ext-enable redis && \ - apk del postgresql-dev && \ + apk del autoconf build-base postgresql-dev && \ mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" && \ - echo "date.timezone = $PHP_TIMEZONE" > $PHP_INI_DIR/conf.d/timezone.ini + echo "date.timezone = $PHP_TIMEZONE" > $PHP_INI_DIR/conf.d/timezone.ini && \ + mkdir -p /usr/local/bin && \ + wget -O /usr/local/bin/composer https://getcomposer.org/download/latest-stable/composer.phar && \ + chmod +x /usr/local/bin/composer && \ + ls -la /app && ls -la /app/bin && \ + chmod +x /app/bin/console && \ + /usr/local/bin/composer install --no-dev --no-progress --no-interaction --optimize-autoloader + +VOLUME /var/log + +CMD ["/app/bin/rr", "serve"] diff --git a/README.md b/README.md index 1b7d6b4..cfe907a 100644 --- a/README.md +++ b/README.md @@ -91,3 +91,24 @@ php bin/console user:add [your_password] [--invites # see --help for more info php bin/console invite:add ``` + +## Enabling dev mode + +```shell +echo 'APP_ENV=dev > .env.local' +``` + +## Running in [RoadRunner](https://roadrunner.dev) + +```shell +# First time only: +./vendor/bin/rr get --location bin/ + +# Running the server: +./bin/rr serve + +# Running the server in dev mode (watching enabled) +bin/rr serve -c .rr.dev.yaml +``` + +Read more [here](https://github.com/baldinof/roadrunner-bundle) and [here](https://github.com/roadrunner-server/roadrunner). diff --git a/docker-compose.yml b/docker-compose.yml index c3b87c9..c51aebb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,16 +2,19 @@ version: '3.7' services: magnetico-web: - image: skobkin/magnetico-web-fpm + image: skobkin/magnetico-web build: - context: ./docker - container_name: magnetico-web-fpm - network_mode: host + context: . + container_name: magnetico-web + hostname: magnetico-web + extra_hosts: + - 'host.docker.internal:host-gateway' ports: - - "127.0.0.1:${PHP_FPM_PORT:-9000}:9000/tcp" + - "127.0.0.1:${EXT_HTTP_PORT:-8080}:8080/tcp" restart: unless-stopped + user: "$UID" volumes: - - "${APP_LOCAL_PATH}:${APP_LOCAL_PATH}" + - "${LOG_PATH:-./var/log}:/app/var/log" logging: driver: "json-file" options: