-
-
Notifications
You must be signed in to change notification settings - Fork 799
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
Could CADDY_MERCURE_JWT_SECRET
be a runtime env var?
#702
Comments
Hi @norkunas! This warning (within this project and for this environment variable) can be ignored when building a container. It is intended only for running the container. Can you show your Caddyfile (how exactly mercure was disabled)? |
Hey!
That bothers me everytime because I get the same log maybe 5-10 times per docker command..
I know, but was just trying things to make it work..
I just commented the mercure part totally. Is there another way? |
To avoid these warnings, you can, for example, set some placeholder as the value of this environment variable during the build steps. For example: CADDY_MERCURE_JWT_SECRET=foobar docker compose ... build ... This environment variable value will not be used during the build, it will only eliminate warnings.
In my experience, disabling mercure by simply commenting out its configuration won't work. Mercure is connected in a different place. In the Caddyfile of this project, only its configuration is performed. And without configuring, mercure does not receive the parameters necessary for its operation, generating this error. If this is useful: in my projects, I disabled mercure by disabling access to it and changing its transport to I myself wondered how to correctly disable mercure via configuration. So far, I have only been able to figure out that mercure must be excluded from the FrankenPHP/Caddy build to disable it. |
Thanks, good to know. |
To clarify:
To avoid getting the warning during the build, you can simply use a placeholder as the value of this environment variable. If this warning appears when running the project, it is likely that this environment variable is not set. Are you currently getting this warning during build or run? |
I'm getting the warning during the run. My compose.prod.yaml contains: environment:
CADDY_MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET}
MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET}
MERCURE_SUBSCRIBER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET} |
@norkunas, Thanks for the information about the environment variable configuration in your compose.yaml file. What command do you use to run? |
My build action (it does not give any warning about CADDY_MERCURE_JWT_SECRET): jobs;
docker:
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v4
- name: Build and push Docker image
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
target: frankenphp_prod
push: true And the command which I run in server (which I've provided in my opening comment):
|
I have added a placeholder to the
|
@norkunas, can you show content of your ./start.sh file? Seems like the |
I add it third time 😁
I'm passing more env variables but not listed them here, and they are correctly read in backend |
Tried running with and without this environment variable:
Even a completely copied example does not trigger a warning: $ SERVER_NAME=... \
CADDY_MERCURE_JWT_SECRET=... \
docker compose -f compose.yaml -f compose.prod.yaml config >/dev/null (ran with dots as is 😄) It seems very likely that the environment variable is not being set. Or it is set somehow incorrectly. |
Then I don't understand why it does not properly take only this specific env var value :( Thanks for the help. Will try to reproduce with a clean sf app and a fresh mind tomorrow |
As the weirdest (and most security-questionable) way to test whether this environment variable is passed, try setting the variable via export CADDY_MERCURE_JWT_SECRET=...
SERVER_NAME=... \
docker compose -f compose.yaml -f compose.prod.yaml up -d |
and this works for some reason 🤔 when trying to build up a reproducer I've found a difference that I've been including additionally EDIT: too early for rejoice, phpinfo shows additional unrelated funny thing I have with APP_SECRET - it is always taken from |
@norkunas, maybe, as a guess, you have a commented line with one of the environment variables, or a backslash is missing at the end of one of the lines with environment variables? I have come across this more than once 😅 FIRST_VAR=foo \
#SECOND_VAR=bar \
THIRD_VAR=baz \
docker compose ... up -d ...
This template has a rather complex system of calculating environment variables. Environment variables are taken from the |
none of these :(
but for some reason app_secret doesn't take the one passed 😑 the two problematic env vars for me are |
In this case, the question is in the contents of the Testing via For debugging purposes, you can try replacing the |
As a simpler solution, I would suggest using a .env.local
Then change Docker Compose to this $ docker compose --env-file .env --env-file .env.local ... (see https://docs.docker.com/reference/cli/docker/compose/#options) or this COMPOSE_ENV_FILES=.env,.env.local docker compose ... (see https://docs.docker.com/compose/how-tos/environment-variables/envvars/#compose_env_files) |
But with these approaches all of the env vars will be passed to all containers? |
I've tried with .env file, and now via phpinfo I see that |
Interesting: if this environment variable is not forwarded in Docker Compose does not pass environment variables passed to it through. This command can be used to get the environment variables passed to the container in a more accurate way: docker compose ... run --rm --no-deps php env The environment variables passed to Docker Compose can be checked using the command (here FOO=... \
BAR=... \
BAZ=... \
env All Just in case: the |
But i see an inverted behavior - they are properly exposed in my container while previously they were not 😮 (expect one env variable which I've needed to left in my I don't properly understand the difference between:
😞 |
Environment variables from files listed in the Environment variables from files listed in the Basic environment variable behavior (true for both Docker Compose and Symfony): explicitly declared environment variables have higher priority than those declared in See https://docs.docker.com/compose/how-tos/environment-variables/envvars-precedence/ Examples of interacting with Docker Compose environment variablesDocker Compose's environment only$ cat .env
$ cat compose.yaml
services:
printenv:
image: busybox:latest
environment:
FORWARDED_VALUE: ${FORWARDED_VALUE:-2}
COMBINED_VALUE: "plain:${PLAIN_VALUE:-1};forwarded:${FORWARDED_VALUE:-2}"
FINAL_VALUE: "3"
command: ["printenv"]
$ docker compose run --rm printenv
FORWARDED_VALUE=2
COMBINED_VALUE=plain:1;forwarded:2
FINAL_VALUE=3 Explicitly declared environment variables without
|
Thank you @7-zete-7 for a thorough explanation, will see if i'll be able to fix my issues |
I build the end docker image in the github actions. It is working properly, but I was disabled mercure.
Now after enabling it, i get:
But I always provide it:
For some reason I was getting this even before enabling mercure:
WARN[0000] The "CADDY_MERCURE_JWT_SECRET" variable is not set. Defaulting to a blank string.
Now I have tried to add
ARG CADDY_MERCURE_JWT_SECRET
andENV CADDY_MERCURE_JWT_SECRET=$CADDY_MERCURE_JWT_SECRET
toDockerfile
and then to the github action (set also the secret for repo):but that didn't help.
The text was updated successfully, but these errors were encountered: