Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ELASTICSEARCH_VERSION=7.16.2
POSTGRESQL_VERSION=13
TEMPORAL_VERSION=1.23
TEMPORAL_UI_VERSION=2.25.0
TEMPORAL_UI_VERSION=2.25.0
TEMPORAL_CLI_IMAGE=temporalio/temporal:1.10.0@sha256:003508da05989e7cf0d583cfce521c4bb2732e733574e3040db8f1284783baa2
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,23 @@ docker compose exec app php app.php {sample-name}
To observe active workers:

```shell
docker compose exec app rr workers -i
docker compose exec app ./rr workers -i
```

To run feature tests in docker use:

```shell
docker compose exec app composer test:feat
````
```

To inspect Workflows using the Temporal CLI:

```shell
docker compose exec temporal-cli temporal workflow list
```

## Local Setup
**1. Make sure you have PHP 8.1, or higher, installed.**
**1. Make sure you have PHP 8.4, or higher, installed.**

**2. Clone this repo and change directory into the root of the project.**

Expand Down Expand Up @@ -83,7 +89,7 @@ Run the following command to download the necessary binaries:
composer get:binaries
```

Note: You can install RoadRunner manually by downloading its binary from the [release page](https://github.com/spiral/roadrunner/releases/tag/v1.9.2).
Note: If installing RoadRunner manually, use the 2025.1 release series required by the SDK version in the committed lockfile, as specified in `app/dload.xml`.

Note: Check the [Quick install guide](https://docs.temporal.io/docs/server/quick-install) to install Temporal Server manually.

Expand Down
2 changes: 1 addition & 1 deletion app/.rr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ server:
command: "php worker.php"

temporal:
address: ${TEMPORAL_HOST:-localhost}:${TEMPORAL_PORT:-7233}
address: ${TEMPORAL_ADDRESS:-localhost:7233}
activities:
num_workers: 4

Expand Down
5 changes: 1 addition & 4 deletions app/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
// finds all available workflows, activity types and commands in a given directory
$declarations = DeclarationLocator::create(__DIR__ . '/src/');

$host = getenv('TEMPORAL_ADDRESS') ?: getenv('TEMPORAL_CLI_ADDRESS');
if (empty($host)) {
$host = 'localhost:7233';
}
$host = getenv('TEMPORAL_ADDRESS') ?: 'localhost:7233';

$app = new Application('Temporal PHP-SDK Samples');

Expand Down
2 changes: 1 addition & 1 deletion app/dload.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xsi:noNamespaceSchemaLocation="vendor/internal/dload/dload.xsd"
>
<actions>
<download software="rr" version="^3.0"/>
<download software="rr" version="^2025.1.5"/>
<download software="temporal" version="^1.5"/>
</actions>
</dload>
4 changes: 1 addition & 3 deletions app/src/Interceptors/.rr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ version: "3"

server:
command: "php worker.php"
env:
- TEMPORAL_CLI_ADDRESS: temporal:7233

temporal:
address: ${TEMPORAL_HOST:-localhost}:${TEMPORAL_PORT:-7233}
address: ${TEMPORAL_ADDRESS:-localhost:7233}
activities:
num_workers: 2

Expand Down
16 changes: 9 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ services:
volumes:
- ./config/dynamicconfig:/etc/temporal/config/dynamicconfig

temporal-admin-tools:
container_name: temporal-admin-tools
temporal-cli:
container_name: temporal-cli
depends_on:
- temporal
environment:
- TEMPORAL_CLI_ADDRESS=temporal:7233
image: temporalio/admin-tools:${TEMPORAL_VERSION}
- TEMPORAL_ADDRESS=temporal:7233
image: ${TEMPORAL_CLI_IMAGE}
entrypoint: [ "sleep", "infinity" ]
networks:
- temporal-network
stdin_open: true
Expand Down Expand Up @@ -108,23 +109,24 @@ services:
build:
dockerfile: docker/app/Dockerfile
context: ./
args:
TEMPORAL_CLI_IMAGE: ${TEMPORAL_CLI_IMAGE}
# volumes:
# - ./app:/var/app
depends_on:
- temporal
networks:
- temporal-network
environment:
- TEMPORAL_CLI_ADDRESS=temporal:7233
- TEMPORAL_ADDRESS=temporal:7233
- TELEMETRY_DRIVER=otel
- OTEL_TRACES_EXPORTER=otlp
- OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
- OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4318
- OTEL_PHP_TRACES_PROCESSOR=simple
- TEMPORAL_HOST=temporal
- OTEL_HOST=collector
- INTERCEPTORS_RR_PATH=/var/app/rr
command: [ "/usr/local/bin/wait-for-temporal.sh", "temporal", "/var/app/rr", "serve" ]
command: [ "/usr/local/bin/wait-for-temporal.sh", "/var/app/rr", "serve" ]

networks:
temporal-network:
Expand Down
17 changes: 11 additions & 6 deletions docker/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
FROM php:8.3-cli
ARG TEMPORAL_CLI_IMAGE=temporalio/temporal:1.10.0@sha256:003508da05989e7cf0d583cfce521c4bb2732e733574e3040db8f1284783baa2
FROM ${TEMPORAL_CLI_IMAGE} AS temporal-cli

FROM php:8.4-cli

RUN apt-get update && apt-get install -y --no-install-recommends \
nano \
Expand All @@ -14,26 +17,28 @@ RUN docker-php-ext-install zip \
&& docker-php-ext-enable opcache sockets mbstring

# Protobuf and GRPC
ENV PROTOBUF_VERSION "3.25.1"
ENV PROTOBUF_VERSION="3.25.1"
ARG PHP_EXTENSION_JOBS=2
RUN pecl channel-update pecl.php.net
RUN pecl install protobuf-${PROTOBUF_VERSION} grpc \
RUN MAKEFLAGS="-j${PHP_EXTENSION_JOBS}" pecl install protobuf-${PROTOBUF_VERSION} grpc \
&& docker-php-ext-enable protobuf grpc

# Install Temporal CLI
COPY --from=temporalio/admin-tools /usr/local/bin/tctl /usr/local/bin/tctl
COPY --from=temporal-cli /usr/local/bin/temporal /usr/local/bin/temporal

# Install Composer
COPY --from=composer /usr/bin/composer /usr/local/bin/composer

# Wait for Temporal service to star up
# Wait for Temporal service to start up
COPY wait-for-temporal.sh /usr/local/bin
RUN chmod +x /usr/local/bin/wait-for-temporal.sh

# Copy application codebase
WORKDIR /var/app
COPY app/ /var/app

RUN composer install
ENV COMPOSER_ALLOW_SUPERUSER=1
RUN composer install --no-interaction

# Load binaries
RUN vendor/bin/dload get --no-interaction
18 changes: 13 additions & 5 deletions wait-for-temporal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@

set -e

shift
cmd="$@"
if [ "$#" -eq 0 ]; then
>&2 echo "Usage: wait-for-temporal.sh command [arguments...]"
exit 2
fi

until tctl --namespace default namespace describe; do
attempt=1
until temporal operator namespace describe --namespace default --command-timeout 5s >/dev/null; do
if [ "$attempt" -ge 60 ]; then
>&2 echo "Temporal namespace is unavailable after 60 attempts - exiting"
exit 1
fi
>&2 echo "Temporal namespace is unavailable - sleeping"
sleep 10
sleep 2
attempt=$((attempt + 1))
done

>&2 echo "Temporal is up - executing command"
exec $cmd
exec "$@"
Loading