-
-
Notifications
You must be signed in to change notification settings - Fork 167
Provide further Octane support for Caddyfile #604
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
base: main
Are you sure you want to change the base?
Conversation
Specify the `CADDY_SERVER_WORKER_DIRECTIVE` and `CADDY_SERVER_WATCH_DIRECTIVES` directives that are populated by Laravel Octane
|
Thanks a ton for chiming in on this @aSeriousDeveloper! I always appreciate reviewing your PRs. I am a novice with Laravel Octane, so I am still learning the ropes what's the best user experience. To my understanding, there are two Caddyfiles being presented: Classic Mode: /etc/frankenphp/Caddyfile (provided by ServerSideUp)
Worker Mode: Use the official Laravel Caddyfile
My first approach (not saying it's 100% right)I documented to use the following command on start up: services:
php:
image: serversideup/php:8.4-frankenphp
ports:
- "80:8080"
volumes:
- .:/var/www/html/
# Start Octane in worker mode
command: ["php", "artisan", "octane:start", "--server=frankenphp", "--port=8080"]
# Set healthcheck to use our native healthcheck script for Octane
healthcheck:
test: ["CMD", "healthcheck-octane"]
start_period: 10sNote Notice how I'm NOT specifying a Caddyfile. This will use Laravel's default Caddyfile. If we suggest to just use Laravel's default CaddyfileThere are pros and cons to this approach: Pros
Cons
Next stepsLet me know your thoughts what you think makes sense. I am very interested in having a community discussion on this. I can easily add extra variables that you propose, but my only hesitation is if Laravel starts changing variables with newer versions of Octane that only are available in Laravel 13+, then this could turn into a lot of maintenance and documentation for people who are running Laravel 12 or lower. Thoughts? |
|
@jaydrogers Yeah good point on wanting it to be more easily configurable & not have compatibility problems. However, I do still want some of the improved Caddyfile features... Not entirely sure what the best-fit solution would be in this case, some spitball suggestions though: Injecting as much as possible using Octanes exposed environment variablesNamely, the Then again, loading a bunch of config via an environment variable (even if you just do it via import) feels wonky. Advising to change the config to the one provided hereThis means they get the specialised config provided, and if we include the extra env variables, then they get the Octane config too. However, it runs into the problem you mentioned of future compatibility, so ehhh. Providing a secret, third configNot sure on this one, but either provide the config as an additional one alongside the existing one within the image (feels bloated), or through something like Spin Pro means you can have it there for those who want it. Namely, if it were part of Spin Pro or something like that, you can have it automatically included within the Dockerfile / Docker Compose. It'd effectively be the same config included here but with the added environment variables as much as possible, as well as maybe cut back on what becomes redundant? Such as not needing the SSL mode configs anymore as it'll always be behind a reverse proxy. |
|
I love this discussion! We're definitely on the same page. Maybe we start here when you said:
What features from the Server Side Up Caddyfile do you feel are missing in the default Octane configuration (specifically in the use case of running Octane). I know we provide a lot of caching and security stuff, but is all our stuff compatible with Octane (or even worker mode in general)? 😅 |
|
I think it's mostly because I don't wanna lose anything that was previously added, but the big ones that stand out are:
Honestly overall though, I think it's mostly just peace of mind, outside of the Cloudflare proxying which I do very much like the concept of. Then again, isn't this also supported by a Caddy Module? |
|
You're right... We've gotta bring these variables in. I don't want to lose that either 🤣 I am in the middle of a project today, but I will have more thought on this tomorrow. Feel free to add more notes to this PR if you have additional thoughts too. |
The big thing for me is also the Cloudflare proxy trust (along with also trusting our Docker network and own AWS EC2 IPv6 range). Right now I use a custom Caddyfile and a custom Caddy build with Octane. This uses the Cloudlfare IPs module linked above, along with the My thought is that Octane doesn't really need much to be changed in the Here are the relevant snippets of what I have done until now:
|
Yeah this is largely true. The core pieces of Octane are essentially just loading the worker. However the additional crux for me comes from the specific variables it also references for building its config. (Also, another feature I neglected to directly mention, the support it includes for Mercure via the Having an imported config would probably solve some of the issues, but I was thinking: Considering this image & the caddyfile are still within beta, what would be solved and what problems would be caused if we more directly emulated Octane's config? Looking at it, probably wouldn't solve much and would be pretty annoying to do, but I thought I'd mention at least. But looking again, specific areas that clash are:
There's other bits that are different between the files but they can be more easily reconciled through just setting environment variables. Considering all that, if we did wanna make these two work together, it probably would require either rejigging our own Caddyfile heavily to have it mesh properly (including renaming our environment variables to clash less), or to have a dedicated Caddyfile for Octane? Alternatively, maybe it's possible to place a PR into Laravel to change their Caddyfile variables to be more Octane specific? They use generic Caddy names but unless these variables are merged somehow that just causes whatever you've set to get overridden. |
|
Man, I am really torn on this. I think for the v4.0 release (which I am hoping to move to stable this week 🤞), we'll just stick with our documented process on using the official Laravel Octane Caddyfile: services:
php:
image: serversideup/php:8.4-frankenphp
ports:
- "80:8080"
volumes:
- .:/var/www/html/
# Start Octane in worker mode
command: ["php", "artisan", "octane:start", "--server=frankenphp", "--port=8080"]
# Set healthcheck to use our native healthcheck script for Octane
healthcheck:
test: ["CMD", "healthcheck-octane"]
start_period: 10sOctane enhancements in the futureOnce v4.0 is out, then we can either:
Octane is very important so this would likely be a v4.1 or v4.2 thing. Thoughts? |
|
@jaydrogers I agree, I think it makes sense to go with what's there now for 4.0 and improve in anther release. (As one of my teachers used to say, "don't let the perfect be the enemy of the good".) Regarding your two suggested options: theoretically it would be nice to have a single unified base configuration with as few differences as possible (i.e. your first option). However, as @aSeriousDeveloper points out, Octane expects certain variables to do certain things, so it's more likely that a separate file which takes those things into account probably makes more sense (i.e. your second option). |
|
I agree with the above. I think I might include my secret third option of making a PR to Octane to rename their environment variables to something more specific to itself. That would make it a fair bit easier to integrate with it, but the viability of this depends entirely on the PR actually getting accepted lol. |
|
Thanks! I appreciate you both giving me the confidence to launch v4.0.0. Shortly after, we'll have PHP 8.5 support. In regards to improving Octane support, I am very interested in making sure we're offering a "batteries included" experience with Octane. So please let me know if you have any ideas on this discussion. I feel as we continue to build and learn with these new technologies, the solution will basically present itself of what we'll need to do. I'll be sure to implement something following the principles of something that "just works" out of the box 😃 Please keep me posted as you learn more. I am beyond grateful to have both of your contributions! |
Laravel Octane
Laravel Octane has its own Caddyfile. It uses various variables that are populated during the startup command.
Typically, this means you need to perform your own overrides to this image's FrankenPHP config to make the two work together. Fortunately, this is pretty simple using the following steps:
The Problem
This all works pretty well, up until you want to enable worker mode or specify the number of workers. This is because we're overriding the Caddyfile config with environment variables. This is acceptable within the file itself, but if we attempt to do the same thing within our
FRANKENPHP_CONFIGenvironment variable, we get the folowing:The Fix
To fix this issue, we need to directly include the environment variables within the file. Therefore, this PR does exactly that. This PR adds 2 environment variables that can be overridden to the
frankenphpconfig:CADDY_SERVER_WORKER_DIRECTIVECADDY_SERVER_WATCH_DIRECTIVESIf they're empty, they should be safely ignored. However, this'll mean they can be populated separately, either automatically by Octane, or manually by the user.
Additionally, if the
workerornumdirectives are already specified elsewhere, it still works! Thewatchdirective will simply append to the watchlist, whilenumI believe cascades to the last specified value.Extra Stuff
The Octane config does specify a few other environment variables:
CADDY_SERVER_EXTRA_DIRECTIVESCADDY_SERVER_ADMIN_HOSTCADDY_SERVER_ADMIN_PORTBut these may be more difficult to add in, either because they've already been specified in this Caddyfile (eg
CADDY_SERVER_EXTRA_DIRECTIVES), or because they require overriding / changes other parts of the Caddyfile if we wanted to make them work.