diff --git a/.env.example b/.env.example index 2c6b6bf..e892f6a 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,6 @@ APP_NAME=Phenix APP_KEY= +APP_ENV=local APP_DEBUG=true APP_URL=http://127.0.0.1 APP_PORT=1337 @@ -8,8 +9,8 @@ DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=phenix -DB_USERNAME=root -DB_PASSWORD= +DB_USERNAME=phenix +DB_PASSWORD=secret LOG_CHANNEL=stream @@ -20,3 +21,6 @@ CORS_ORIGIN= REDIS_HOST=127.0.0.1 REDIS_PORT=6379 REDIS_PASSWORD=null + +USER_UID=1000 +USER_GID=1000 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..dffd3bd --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,30 @@ +services: + app: + build: + context: ./docker + args: + - USER_UID=${USER_UID} + - USER_GID=${USER_GID} + volumes: + - .:/usr/src/phenix:rw + working_dir: /usr/src/phenix + extra_hosts: + - 'host.docker.internal:host-gateway' + environment: + - APP_PORT=${APP_PORT} + - APP_ENV=${APP_ENV} + ports: + - '${APP_PORT}:${APP_PORT}' + mysql: + image: mysql:8.0 + ports: + - "${MYSQL_PORT:-3307}:3306" + environment: + MYSQL_ROOT_HOST: "%" + MYSQL_DATABASE: '${DB_DATABASE}' + MYSQL_USER: '${DB_USERNAME}' + MYSQL_PASSWORD: '${DB_PASSWORD}' + MYSQL_ALLOW_EMPTY_PASSWORD: 1 +networks: + phenix: + driver: bridge \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..42338a0 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,22 @@ +FROM php:8.2-cli +WORKDIR /usr/src/phenix + +ARG USER_UID +ARG USER_GID + +RUN groupadd -g ${USER_GID} phenix_group && useradd -ms /bin/bash -u ${USER_UID} -g ${USER_GID} phenix_user + +RUN docker-php-ext-install pcntl pdo pdo_mysql + +RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \ + apt-get install -y nodejs + +USER phenix_user + +COPY . /usr/src/phenix + +ENV APP_PORT=${APP_PORT} + +EXPOSE ${APP_PORT} + +ENTRYPOINT ["docker/entrypoint.sh"] diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 0000000..29a2f45 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +if [ "$APP_ENV" = "production" ]; then + php public/index.php --host=0.0.0.0 --port=${APP_PORT} +else + php ./server --host=0.0.0.0 --port=${APP_PORT} +fi \ No newline at end of file diff --git a/server b/server index 328ab9d..3a3cddd 100644 --- a/server +++ b/server @@ -6,6 +6,7 @@ use Dotenv\Dotenv; use Spatie\Watcher\Watch; use Symfony\Component\Process\Process; use Spatie\Watcher\Exceptions\CouldNotStartWatcher; +use Symfony\Component\Process\PhpExecutableFinder; require_once __DIR__ . '/vendor/autoload.php'; @@ -92,7 +93,7 @@ class Watcher extends Watch parent::__construct(); $this->setPaths($paths); - $this->host = $config['APP_URL'] ?? 'http://127.0.0.1'; + $this->host = $config['APP_HOST'] ?? '0.0.0.0'; $this->port = $config['APP_PORT'] ?? 1337; } @@ -168,8 +169,10 @@ class Watcher extends Watch return; } - $command = "XDEBUG_MODE=off php public/index.php"; - $this->serverProcess = Process::fromShellCommandline($command); + $this->serverProcess = new Process( + command:[(new PhpExecutableFinder)->find(), 'public/index.php', "--host={$this->host}", "--port={$this->port}"], + env:['XDEBUG_MODE' => 'off'] + ); $this->serverProcess->setTimeout(null); try {