feat: update gRPC server configuration and enhance Docker setup
All checks were successful
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 3m2s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 3m18s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 3m6s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 3m15s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 3m4s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 1m50s

This commit is contained in:
2025-12-04 08:43:19 -05:00
parent 24f0671066
commit 1b4e1468fc
7 changed files with 131 additions and 39 deletions

View File

@@ -11,12 +11,9 @@ grpc:
pool: pool:
command: "php grpc-worker.php" command: "php grpc-worker.php"
num_workers: ${GRPC_WORKERS:-4} num_workers: ${GRPC_WORKERS:-4}
allocate_timeout: 5s debug: ${DEBUG:-false}
reset_timeout: 5s
destroy_timeout: 5s
stream_timeout: 5s
reflection: ${GRPC_REFLECTION:-true} reflection: ${GRPC_REFLECTION:-true}
health_check: ${GRPC_HEALTH_CHECK:-true} destroy_timeout: 5s
proto: proto:
- "protos/example.proto" - "protos/example.proto"

View File

@@ -43,11 +43,13 @@ COPY --from=library /app/vendor /app/vendor
# Copy the RoadRunner configuration file and source # Copy the RoadRunner configuration file and source
ADD src src/ ADD src src/
ADD generated generated/ ADD generated generated/
ADD protos protos/
ADD server.php . ADD server.php .
ADD .rr.yaml . ADD .rr.yaml .
ADD config.php . ADD config.php .
EXPOSE 9501 EXPOSE 9501
EXPOSE 9001
# Entrypoint command to run the RoadRunner server with the specified configuration # Entrypoint command to run the RoadRunner server with the specified configuration
ENTRYPOINT ["rr", "serve", "-c", ".rr.yaml", "-s"] ENTRYPOINT ["rr", "serve", "-c", ".rr.yaml", "-s"]

139
README.md
View File

@@ -2,55 +2,132 @@
![pipeline status](https://gitea.siteworxpro.com/siteworxpro/Php-Template/actions/workflows/tests.yml/badge.svg?branch=master&style=flat-square) ![pipeline status](https://gitea.siteworxpro.com/siteworxpro/Php-Template/actions/workflows/tests.yml/badge.svg?branch=master&style=flat-square)
## Overview
This is a PHP project template that provides a structured development environment using Docker Compose and Make.
It includes tools for code quality, testing, dependency management, and gRPC support.
## Dev Environment ## Dev Environment
### Prerequisites This project uses Docker Compose and Make to manage the development environment. The `makefile` provides convenient
- Docker commands for common development tasks.
- Docker Compose
### migrations ## Prerequisites
create a new migration - Docker and Docker Compose
```shell - Make
docker run --rm -v $(PWD):/app siteworxpro/migrate:v4.18.3 create -ext sql -dir /app/db/migrations -seq create_users_table - protoc (Protocol Buffers compiler) - for gRPC code generation
## Quick Start
```bash
# Install PHP dependencies
make composer-install
# Start the development container
make start
# Run the application server
make run
``` ```
```text ## Available Commands
postgres://siteworxpro:password@localhost:5432/siteworxpro?sslmode=disable
### Container Management
- `make start` - Start the development runtime container
- `make stop` - Stop and remove all containers
- `make restart` - Restart the development container
- `make rebuild` - Rebuild containers (use after Dockerfile changes)
- `make sh` - Open a shell in the development container
- `make ps` - Show running containers
### Application
- `make run` - Run the application server (RoadRunner)
- `make migrate` - Run database migrations
### Composer & Dependencies
- `make composer-install` - Install PHP dependencies
- `make composer-update` - Update PHP dependencies
- `make composer-require package=vendor/package` - Add a new dependency
- `make composer-require-dev package=vendor/package` - Add a new dev dependency
### Code Quality
- `make lint` - Run linters (phpcs and phpstan)
- `make fmt` - Format code with php-cs-fixer
- `make test` - Run the test suite (phpunit)
- `make license-check` - Check license headers in source files
### Debugging & Coverage
- `make enable-debug` - Enable Xdebug for debugging
- `make enable-coverage` - Enable PCOV for code coverage
### gRPC
- `make protoc` - Generate PHP gRPC code from `.proto` files
### CI Workflow
- `make ci` - Run the full CI pipeline locally (install, license check, lint, test)
### Help
- `make help` - Show all available commands with descriptions
## Common Workflows
### Starting Development
```bash
make composer-install
make start
make run
``` ```
```shell ### Adding a New Package
docker run --rm -v $(PWD):/app siteworxpro/migrate:v4.18.3 -database "postgres://siteworxpro:password@localhost:5432/siteworxpro?sslmode=disable" -path /app/db/migrations up
```bash
make composer-require package=vendor/package-name
``` ```
### Starting the Runtime ### Running Tests
```shell
docker-compose up -d ```bash
``` make test
### Start the server
```shell
docker exec -it template-dev-runtime-1 rr serve
``` ```
You can access the api at `http://localhost:9501/` ### Code Quality Check
### Xdebug ```bash
make lint
xdebug needs to be built into the container before it will work make fmt
```shell
docker exec -it php-template-composer-runtime-1 bin/xdebug.sh
``` ```
### Install the dependencies ### Debugging
```shell
docker run --rm -v $(PWD):/app siteworxpro/composer install --ignore-platform-reqs ```bash
make enable-debug
make run
``` ```
### Running all tests ## Notes
```shell
docker run --rm -v $(PWD):/app siteworxpro/composer run tests:all
```
- All commands run inside Docker containers, ensuring a consistent environment
- The development runtime uses RoadRunner as the application server
- Composer commands run in a separate `composer-runtime` container
- Database migrations run in a dedicated `migration-container`
## Additional Information
### Accessing Services
- You can access the api at [https://localhost](https://localhost)
- Traefik dashboard is at [https://127.0.0.1/dashboard/](https://127.0.0.1/dashboard/)
- the grpc server is at [tcp://localhost:9001](tcp://localhost:9001)
## License ## License

View File

@@ -14,7 +14,6 @@ return [
*/ */
'server' => [ 'server' => [
'port' => Env::get('HTTP_PORT', 9501, 'int'), 'port' => Env::get('HTTP_PORT', 9501, 'int'),
'dev_mode' => Env::get('DEV_MODE', false, 'bool'),
], ],
/** /**

View File

@@ -5,6 +5,12 @@ volumes:
services: services:
traefik: traefik:
labels:
- "traefik.enable=true"
- "traefik.http.routers.traefik.entrypoints=web-secure"
- "traefik.http.routers.traefik.rule=Host(`127.0.0.1`) && (PathPrefix(`/dashboard`) || PathPrefix(`/api`))"
- "traefik.http.routers.traefik.tls=true"
- "traefik.http.routers.traefik.service=api@internal"
image: traefik:latest image: traefik:latest
container_name: traefik container_name: traefik
healthcheck: healthcheck:
@@ -15,15 +21,18 @@ services:
ports: ports:
- "80:80" - "80:80"
- "443:443" - "443:443"
- "9001:9001"
volumes: volumes:
- "/var/run/docker.sock:/var/run/docker.sock" - "/var/run/docker.sock:/var/run/docker.sock"
restart: always restart: always
command: command:
- "--providers.docker=true" - "--providers.docker=true"
- "--api.insecure=true"
- "--ping" - "--ping"
- "--providers.docker.exposedByDefault=false" - "--providers.docker.exposedByDefault=false"
- "--entrypoints.web.address=:80" - "--entrypoints.web.address=:80"
- "--entrypoints.web-secure.address=:443" - "--entrypoints.web-secure.address=:443"
- "--entrypoints.grpc.address=:9001"
- "--accesslog=true" - "--accesslog=true"
- "--entrypoints.web.http.redirections.entryPoint.to=web-secure" - "--entrypoints.web.http.redirections.entryPoint.to=web-secure"
- "--entrypoints.web.http.redirections.entryPoint.scheme=https" - "--entrypoints.web.http.redirections.entryPoint.scheme=https"
@@ -79,6 +88,13 @@ services:
- "traefik.http.services.api.loadbalancer.healthcheck.path=/healthz" - "traefik.http.services.api.loadbalancer.healthcheck.path=/healthz"
- "traefik.http.services.api.loadbalancer.healthcheck.interval=5s" - "traefik.http.services.api.loadbalancer.healthcheck.interval=5s"
- "traefik.http.services.api.loadbalancer.healthcheck.timeout=60s" - "traefik.http.services.api.loadbalancer.healthcheck.timeout=60s"
- "traefik.tcp.services.api.loadbalancer.server.port=9001"
- "traefik.http.services.api.loadbalancer.server.port=9501"
- "traefik.tcp.routers.grpc.entrypoints=grpc"
- "traefik.tcp.routers.grpc.rule=HostSNI(`localhost`) || HostSNI(`127.0.0.1`)"
- "traefik.tcp.routers.grpc.tls=true"
- "traefik.tcp.routers.grpc.service=api"
container_name: dev-runtime
volumes: volumes:
- .:/app - .:/app
build: build:
@@ -103,6 +119,7 @@ services:
QUEUE_BROKER: redis QUEUE_BROKER: redis
PHP_IDE_CONFIG: serverName=localhost PHP_IDE_CONFIG: serverName=localhost
WORKERS: 1 WORKERS: 1
GRPC_WORKERS: 1
DEBUG: 1 DEBUG: 1
REDIS_HOST: redis REDIS_HOST: redis
DB_HOST: postgres DB_HOST: postgres

View File

@@ -6,7 +6,7 @@ require __DIR__ . '/vendor/autoload.php';
try { try {
$server = new Grpc(); $server = new Grpc();
$server->start(); exit($server->start());
} catch (\Exception $e) { } catch (\Exception $e) {
echo $e->getMessage(); echo $e->getMessage();

View File

@@ -36,7 +36,7 @@ class Grpc
public function start(): int public function start(): int
{ {
$server = new Server(new Invoker(), [ $server = new Server(new Invoker(), [
'debug' => (bool) Config::get('app.debug'), 'debug' => Config::get('app.dev_mode'),
]); ]);
$server->registerService(GreeterInterface::class, new GreeterHandler()); $server->registerService(GreeterInterface::class, new GreeterHandler());