Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add built-in Mercure support #89

Merged
merged 6 commits into from Dec 1, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion Dockerfile
Expand Up @@ -5,7 +5,7 @@

# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
ARG PHP_VERSION=7.4
ARG CADDY_VERSION=2.1.1
ARG CADDY_VERSION=2

# "php" stage
FROM php:${PHP_VERSION}-fpm-alpine AS symfony_php
Expand Down Expand Up @@ -109,12 +109,16 @@ CMD ["php-fpm"]
FROM caddy:${CADDY_VERSION}-builder-alpine AS symfony_caddy_builder

RUN xcaddy build \
--with github.com/dunglas/mercure@main \
--with github.com/dunglas/mercure/caddy@main \
--with github.com/dunglas/vulcain/caddy

FROM caddy:${CADDY_VERSION} AS symfony_caddy

WORKDIR /srv/app

ENV MERCURE_DEMO="demo /srv/mercure-assets/"
COPY --from=dunglas/mercure:v0.11 /srv/public /srv/mercure-assets/
COPY --from=symfony_caddy_builder /usr/bin/caddy /usr/bin/caddy
COPY --from=symfony_php /srv/app/public public/
COPY docker/caddy/Caddyfile /etc/caddy/Caddyfile
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -14,8 +14,9 @@ A [Docker](https://www.docker.com/)-based installer and runtime for the [Symfony

* Production, development and CI ready
* Automatic HTTPS (in dev and in prod!)
* HTTP/2, HTTP/3 and [Server Push](https://symfony.com/doc/current/web_link.html) support
* [Vulcain](https://vulcain.rocks)-enabled
* HTTP/2, HTTP/3 and [Preload](https://symfony.com/doc/current/web_link.html) support
* Built-in [Mercure](https://symfony.com/doc/current/mercure.html) hub
* [Vulcain](https://vulcain.rocks) support
* Just 2 services (PHP FPM and Caddy server)
* Super-readable configuration

Expand Down
6 changes: 6 additions & 0 deletions docker-compose.prod.yml
Expand Up @@ -5,3 +5,9 @@ services:
php:
environment:
APP_ENV: prod

caddy:
environment:
MERCURE_DEMO: # Disable the demo
MERCURE_PUBLISHER_JWT: ${MERCURE_PUBLISHER_JWT}
MERCURE_SUBSCRIBER_JWT: ${MERCURE_SUBSCRIBER_JWT}
6 changes: 5 additions & 1 deletion docker-compose.yml
Expand Up @@ -17,14 +17,18 @@ services:
environment:
# Run "composer require symfony/orm-pack" to install and configure Doctrine ORM
DATABASE_URL: postgresql://${POSTGRES_USER:-symfony}:${POSTGRES_PASSWORD:-ChangeMe}@database:5432/${POSTGRES_DB:-app}?serverVersion=${POSTGRES_VERSION:-13}
# Run "composer require symfony/mercure-bundle" to install and configure the Mercure integration
MERCURE_PUBLISH_URL: ${MERCURE_URL:-http://caddy/.well-known/mercure}
SYMFONY_VERSION:

caddy:
build:
context: .
target: symfony_caddy
environment:
SERVER_NAME: ${SERVER_NAME:-localhost}
SERVER_NAME: ${SERVER_NAME:-localhost, caddy:80}
MERCURE_PUBLISHER_JWT: ${MERCURE_PUBLISHER_JWT:-!ChangeMe!}
MERCURE_SUBSCRIBER_JWT: ${MERCURE_SUBSCRIBER_JWT:-!ChangeMe!}
restart: unless-stopped
ports:
- "80:80"
Expand Down
14 changes: 14 additions & 0 deletions docker/caddy/Caddyfile
Expand Up @@ -8,6 +8,20 @@ log

route {
root * /srv/app/public
mercure {
# Transport to use (default to Bolt)
transport_url bolt:///data/mercure.db
# Enable the demo endpoint (disable it in production!)
{$MERCURE_DEMO}
# Publisher JWT key
publisher_jwt {$MERCURE_PUBLISHER_JWT}
# Subscriber JWT key
subscriber_jwt {$MERCURE_SUBSCRIBER_JWT}
# Allow anonymous subscribers (double-check that it's what you want)
anonymous
# Enable the subscription API (double-check that it's what you want)
subscriptions
}
vulcain
push
php_fastcgi php:9000
Expand Down
6 changes: 4 additions & 2 deletions docs/build.md
Expand Up @@ -17,6 +17,8 @@ For instance, use the following command to use the `master` branch of Symfony:

## Customizing the Server Name

Use the `SERVER_NAME` environment variable to define your custom server name.
Use the `SERVER_NAME` environment variable to define your custom server name(s).

$ SERVER_NAME=symfony.wip docker-compose up --build
$ SERVER_NAME="symfony.wip, caddy:80" docker-compose up --build

If you use Mercure, keep `caddy:80` in the list to allow the PHP container to request the caddy service.
1 change: 1 addition & 0 deletions docs/extra-services.md
Expand Up @@ -6,4 +6,5 @@ the recipe will automatically modify the `Dockerfile` and `docker-compose.yml` t
The currently supported packages are:

* `symfony/orm-pack`: install a PostgreSQL service
* `symfony/mercure-bundle`: use the Mercure.rocks module shipped with Caddy
* `symfony/messenger`: install a RabbitMQ service