diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4ff7ed4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,49 @@ +.git +.gitignore +.gitattributes + +Dockerfile +docker-compose.yml +.dockerignore + +README.md +CHANGELOG.md +LICENSE.md +docs/ + +.vscode/ +.idea/ +*.swp +*.swo + +.DS_Store +Thumbs.db + +storage/logs/* +storage/framework/logs/* +storage/app/public/* +storage/framework/cache/* +storage/framework/sessions/* +storage/framework/testing/* +storage/framework/views/* + +node_modules/ +vendor/ + +.env + +build/ +coverage/ + +*.tmp +*.log +*.pid +*.seed +*.pid.lock + +.phpunit.result.cache +.pest +.php_cs.cache + +dist/ +public/build/ diff --git a/.env.example b/.env.example index e892f6a..58cb2fe 100644 --- a/.env.example +++ b/.env.example @@ -10,7 +10,7 @@ DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=phenix DB_USERNAME=phenix -DB_PASSWORD=secret +DB_PASSWORD= LOG_CHANNEL=stream @@ -22,5 +22,4 @@ REDIS_HOST=127.0.0.1 REDIS_PORT=6379 REDIS_PASSWORD=null -USER_UID=1000 -USER_GID=1000 +SESSION_DRIVER=local diff --git a/.env.example.docker b/.env.example.docker new file mode 100644 index 0000000..0f2aa3b --- /dev/null +++ b/.env.example.docker @@ -0,0 +1,26 @@ +APP_NAME=Phenix +APP_KEY= +APP_ENV=local +APP_DEBUG=true +APP_URL=http://127.0.0.1 +APP_PORT=1337 + +DB_CONNECTION=mysql +DB_HOST=mysql +DB_PORT=3306 +DB_DATABASE=phenix +DB_USERNAME=phenix +DB_PASSWORD=secret +MYSQL_PORT=3307 + +LOG_CHANNEL=stream + +QUEUE_DRIVER=database + +CORS_ORIGIN= + +REDIS_HOST=redis +REDIS_PORT=6379 +REDIS_PASSWORD=null + +SESSION_DRIVER=redis diff --git a/config/cors.php b/config/cors.php index d191010..105b1ab 100644 --- a/config/cors.php +++ b/config/cors.php @@ -1,7 +1,7 @@ env('CORS_ORIGIN', fn (): array => ['http://localhost', 'http://127.0.0.1']), + 'origins' => env('CORS_ORIGIN', static fn (): array => ['http://localhost', 'http://127.0.0.1']), 'allowed_methods' => ['GET', 'POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE'], 'max_age' => 8600, 'allowed_headers' => ['X-Request-Headers', 'Content-Type', 'Authorization', 'X-Requested-With'], diff --git a/config/logging.php b/config/logging.php index cc0d9b6..cb63722 100644 --- a/config/logging.php +++ b/config/logging.php @@ -3,7 +3,7 @@ declare(strict_types=1); return [ - 'default' => env('LOG_CHANNEL', fn (): string => 'file'), + 'default' => env('LOG_CHANNEL', static fn (): string => 'file'), /* |-------------------------------------------------------------------------- diff --git a/config/session.php b/config/session.php index d229735..87ed685 100644 --- a/config/session.php +++ b/config/session.php @@ -15,9 +15,9 @@ | */ - 'driver' => env('SESSION_DRIVER', fn (): string => 'redis'), + 'driver' => env('SESSION_DRIVER', static fn (): string => 'redis'), - 'lifetime' => env('SESSION_LIFETIME', fn () => 120), + 'lifetime' => env('SESSION_LIFETIME', static fn (): int => 120), /* |-------------------------------------------------------------------------- diff --git a/docker-compose.yml b/docker-compose.yml index dffd3bd..93eb9de 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,30 +1,63 @@ services: app: build: - context: ./docker - args: - - USER_UID=${USER_UID} - - USER_GID=${USER_GID} + context: . + dockerfile: docker/Dockerfile + target: local volumes: - - .:/usr/src/phenix:rw - working_dir: /usr/src/phenix + - .:/var/www/html:rw + - /var/www/html/vendor + working_dir: /var/www/html extra_hosts: - 'host.docker.internal:host-gateway' environment: - - APP_PORT=${APP_PORT} - - APP_ENV=${APP_ENV} + - APP_PORT=${APP_PORT:-1337} + - APP_ENV=${APP_ENV:-local} + - DB_HOST=mysql + - DB_PORT=3306 + - DB_DATABASE=${DB_DATABASE:-phenix} + - DB_USERNAME=${DB_USERNAME:-phenix} + - DB_PASSWORD=${DB_PASSWORD:-secret} + - REDIS_HOST=redis + - REDIS_PORT=6379 + - REDIS_PASSWORD=${REDIS_PASSWORD} ports: - - '${APP_PORT}:${APP_PORT}' + - '${APP_PORT:-1337}:${APP_PORT:-1337}' + depends_on: + - mysql + - redis + networks: + - phenix + 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_DATABASE: '${DB_DATABASE:-phenix}' + MYSQL_USER: '${DB_USERNAME:-phenix}' + MYSQL_PASSWORD: '${DB_PASSWORD:-secret}' MYSQL_ALLOW_EMPTY_PASSWORD: 1 + volumes: + - mysql_data:/var/lib/mysql + networks: + - phenix + + redis: + image: redis:7-alpine + ports: + - "${REDIS_PORT:-6379}:6379" + command: redis-server --appendonly yes + volumes: + - redis_data:/data + networks: + - phenix + +volumes: + mysql_data: + redis_data: + networks: phenix: - driver: bridge \ No newline at end of file + driver: bridge diff --git a/docker/Dockerfile b/docker/Dockerfile index 42338a0..a69a17a 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,22 +1,41 @@ -FROM php:8.2-cli -WORKDIR /usr/src/phenix +FROM serversideup/php:8.2-cli-alpine AS base -ARG USER_UID -ARG USER_GID +USER root -RUN groupadd -g ${USER_GID} phenix_group && useradd -ms /bin/bash -u ${USER_UID} -g ${USER_GID} phenix_user +RUN apk add --no-cache \ + curl \ + git \ + unzip -RUN docker-php-ext-install pcntl pdo pdo_mysql +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer -RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \ - apt-get install -y nodejs +FROM base AS local -USER phenix_user +RUN apk add --no-cache nodejs npm -COPY . /usr/src/phenix +COPY --chown=www-data:www-data . /var/www/html -ENV APP_PORT=${APP_PORT} +RUN chmod -R 755 /var/www/html/storage -EXPOSE ${APP_PORT} +USER www-data + +RUN composer install --no-scripts --no-autoloader +RUN composer dump-autoload --optimize + +EXPOSE ${APP_PORT:-1337} + +ENTRYPOINT ["docker/entrypoint.sh"] + +FROM base AS production + +COPY --chown=www-data:www-data . /var/www/html + +RUN chmod -R 755 /var/www/html/storage + +USER www-data + +RUN composer install --no-dev --optimize-autoloader --no-scripts + +EXPOSE ${APP_PORT:-1337} ENTRYPOINT ["docker/entrypoint.sh"] diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 29a2f45..9828907 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,7 +1,11 @@ #!/bin/sh +set -e + if [ "$APP_ENV" = "production" ]; then - php public/index.php --host=0.0.0.0 --port=${APP_PORT} + echo "Starting production server..." + php public/index.php --host=0.0.0.0 --port=${APP_PORT:-1337} else - php ./server --host=0.0.0.0 --port=${APP_PORT} -fi \ No newline at end of file + echo "Starting development server with file watcher..." + php ./server --host=0.0.0.0 --port=${APP_PORT:-1337} +fi