You've already forked Php-Template
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
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:
7
.rr.yaml
7
.rr.yaml
@@ -11,12 +11,9 @@ grpc:
|
||||
pool:
|
||||
command: "php grpc-worker.php"
|
||||
num_workers: ${GRPC_WORKERS:-4}
|
||||
allocate_timeout: 5s
|
||||
reset_timeout: 5s
|
||||
destroy_timeout: 5s
|
||||
stream_timeout: 5s
|
||||
debug: ${DEBUG:-false}
|
||||
reflection: ${GRPC_REFLECTION:-true}
|
||||
health_check: ${GRPC_HEALTH_CHECK:-true}
|
||||
destroy_timeout: 5s
|
||||
proto:
|
||||
- "protos/example.proto"
|
||||
|
||||
|
||||
@@ -43,11 +43,13 @@ COPY --from=library /app/vendor /app/vendor
|
||||
# Copy the RoadRunner configuration file and source
|
||||
ADD src src/
|
||||
ADD generated generated/
|
||||
ADD protos protos/
|
||||
ADD server.php .
|
||||
ADD .rr.yaml .
|
||||
ADD config.php .
|
||||
|
||||
EXPOSE 9501
|
||||
EXPOSE 9001
|
||||
|
||||
# Entrypoint command to run the RoadRunner server with the specified configuration
|
||||
ENTRYPOINT ["rr", "serve", "-c", ".rr.yaml", "-s"]
|
||||
139
README.md
139
README.md
@@ -2,55 +2,132 @@
|
||||
|
||||

|
||||
|
||||
## 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
|
||||
|
||||
### Prerequisites
|
||||
- Docker
|
||||
- Docker Compose
|
||||
This project uses Docker Compose and Make to manage the development environment. The `makefile` provides convenient
|
||||
commands for common development tasks.
|
||||
|
||||
### migrations
|
||||
## Prerequisites
|
||||
|
||||
create a new migration
|
||||
```shell
|
||||
docker run --rm -v $(PWD):/app siteworxpro/migrate:v4.18.3 create -ext sql -dir /app/db/migrations -seq create_users_table
|
||||
- Docker and Docker Compose
|
||||
- Make
|
||||
- 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
|
||||
postgres://siteworxpro:password@localhost:5432/siteworxpro?sslmode=disable
|
||||
## Available Commands
|
||||
|
||||
### 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
|
||||
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
|
||||
### Adding a New Package
|
||||
|
||||
```bash
|
||||
make composer-require package=vendor/package-name
|
||||
```
|
||||
|
||||
### Starting the Runtime
|
||||
```shell
|
||||
docker-compose up -d
|
||||
```
|
||||
### Start the server
|
||||
```shell
|
||||
docker exec -it template-dev-runtime-1 rr serve
|
||||
### Running Tests
|
||||
|
||||
```bash
|
||||
make test
|
||||
```
|
||||
|
||||
You can access the api at `http://localhost:9501/`
|
||||
### Code Quality Check
|
||||
|
||||
### Xdebug
|
||||
|
||||
xdebug needs to be built into the container before it will work
|
||||
```shell
|
||||
docker exec -it php-template-composer-runtime-1 bin/xdebug.sh
|
||||
```bash
|
||||
make lint
|
||||
make fmt
|
||||
```
|
||||
|
||||
### Install the dependencies
|
||||
```shell
|
||||
docker run --rm -v $(PWD):/app siteworxpro/composer install --ignore-platform-reqs
|
||||
### Debugging
|
||||
|
||||
```bash
|
||||
make enable-debug
|
||||
make run
|
||||
```
|
||||
|
||||
### Running all tests
|
||||
```shell
|
||||
docker run --rm -v $(PWD):/app siteworxpro/composer run tests:all
|
||||
```
|
||||
## Notes
|
||||
|
||||
- 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
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ return [
|
||||
*/
|
||||
'server' => [
|
||||
'port' => Env::get('HTTP_PORT', 9501, 'int'),
|
||||
'dev_mode' => Env::get('DEV_MODE', false, 'bool'),
|
||||
],
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,6 +5,12 @@ volumes:
|
||||
services:
|
||||
|
||||
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
|
||||
container_name: traefik
|
||||
healthcheck:
|
||||
@@ -15,15 +21,18 @@ services:
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
- "9001:9001"
|
||||
volumes:
|
||||
- "/var/run/docker.sock:/var/run/docker.sock"
|
||||
restart: always
|
||||
command:
|
||||
- "--providers.docker=true"
|
||||
- "--api.insecure=true"
|
||||
- "--ping"
|
||||
- "--providers.docker.exposedByDefault=false"
|
||||
- "--entrypoints.web.address=:80"
|
||||
- "--entrypoints.web-secure.address=:443"
|
||||
- "--entrypoints.grpc.address=:9001"
|
||||
- "--accesslog=true"
|
||||
- "--entrypoints.web.http.redirections.entryPoint.to=web-secure"
|
||||
- "--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.interval=5s"
|
||||
- "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:
|
||||
- .:/app
|
||||
build:
|
||||
@@ -103,6 +119,7 @@ services:
|
||||
QUEUE_BROKER: redis
|
||||
PHP_IDE_CONFIG: serverName=localhost
|
||||
WORKERS: 1
|
||||
GRPC_WORKERS: 1
|
||||
DEBUG: 1
|
||||
REDIS_HOST: redis
|
||||
DB_HOST: postgres
|
||||
|
||||
@@ -6,7 +6,7 @@ require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
try {
|
||||
$server = new Grpc();
|
||||
$server->start();
|
||||
exit($server->start());
|
||||
} catch (\Exception $e) {
|
||||
echo $e->getMessage();
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class Grpc
|
||||
public function start(): int
|
||||
{
|
||||
$server = new Server(new Invoker(), [
|
||||
'debug' => (bool) Config::get('app.debug'),
|
||||
'debug' => Config::get('app.dev_mode'),
|
||||
]);
|
||||
|
||||
$server->registerService(GreeterInterface::class, new GreeterHandler());
|
||||
|
||||
Reference in New Issue
Block a user