-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
bug: environment variable ${{ENV_VAR:=}}
in apisix.yaml
fails to resolve when using APISIX standalone mode in Docker
#10530
Comments
@kayx23 While you exec and pass on the string with |
For the above screenshot I actually went into the container and echo the configs into apisix.yaml. I only updated the command before creating this issue. Just edited it back. Sorry for the confusion. |
Can you try with ${} instead of ${{}}. I can assure that my env variable is getting picked up passed inside ${} @kayx23 |
In yaml files? But all the docs and test cases suggest in config.yaml and apisix.yaml the env vars get picked up with the ${{...}} syntax. If the env var isn't set, there's even a syntax to support fallback values. ${..} is indeed what you would usually use in, say, a shell command, to resolve env vars. But I think it doesn't address the question here. |
apisix.yaml
fails to resolveapisix.yaml
fails to resolve
I'm also having the same issue using the
in all cases, I have made sure that the variable is loaded into the container either by using an outside env set ( From what I gathered from the logs there is the following error:
which indicates that even though the environment variable is set it needs some way to be loaded or be accessed through nginx explicitly |
apisix.yaml
fails to resolveapisix.yaml
fails to resolve
@kayx23
The answer in the http://nginx.org/en/docs/ngx_core_module.html#env then update apisix.yaml will work some reference: |
Interesting... thanks for looking into it! @hanqingwu I'll look into this a bit more later. I'm wondering why |
Just localized the issue a bit more and it doesn't seem to relate to @hanqingwu 's findings too much. It has something to do with whether you export the env var or not:
I installed APISIX on the host machine and tested with Successful Test with
|
cc: @markokocic |
yes , if you first set apisix.yaml then start apisix , env var works. |
apisix.yaml
fails to resolveapisix.yaml
fails to resolve
Well, it still doesn't work with environment variables set in a standard docker way. The fact that docker is the standard and probably most common way of running Apisix, this should either be fixed or explicitly mentioned in documentation that docker -e or env files don't work. |
Hi @markokocic , I updated the doc comfortable knowing that apsix.yaml does support env var, but perhaps shouldn't have closed this issue with the doc PR. Based on @hanqingwu 's suggestions above, I suppose the next step could be to try to mount the apisix.yaml (with initial configurations that use env var) to the container at startup, though I haven't had the chance to give this a go. We could reopen the issue if everyone thinks it's fitting. |
Hi @kayx23 , that was exactly what I tried in #10509 (comment) |
apisix.yaml
fails to resolveapisix.yaml
fails to resolve when using APISIX standalone mode in Docker
apisix.yaml
fails to resolve when using APISIX standalone mode in Docker${{ENV_VAR:=}}
in apisix.yaml
fails to resolve when using APISIX standalone mode in Docker
@markokocic Ok I see. Could you share the complete docker compose file here if you still have it? We could update the issue description with it. Happy year end btw! |
@kayx23 I think we should document a reliable way to use ENV VARS in yaml for docker based deployments, what say? |
@shreemaan-abhishek can be documented if it works.... |
hi @kayx23 here's my setup full example. I think we are a bit closer to finding out the underlying problem. docker-compose-standalone.yml:
apisix_conf/apisix-standalone.yaml:
As you can see, I defined EP_MYHOST_1 and EP_MYHOST_2 environment variables in a standard docker way. After that, I started docker with When I ran the following right after starting docker, I got success:
However, if I after that change the config file to use EP_MYHOST_2 instead of EP_MYHOST_1 like so:
the config gets reloaded successfully, but the environment variable can't be resolved any more, although it is properly defined. If I edit it back to EP_MYHOST_1, it works again. Looks like something gets wrong after reloading the config file. It seems like it can resolve env variables only if they are present in that file from the beginning, making the whole config reload feature confusing and not practical. At the beginning, I was thinking environment variable resolution didn't work at all because I was starting with the empty config file and editing and reloading it incrementally, thinking it wouldn't matter if the variable was there from the start or not. |
#10530 (comment) EDIT: Or perhaps you tested with other installation method. |
If you look at my comments, both env variables are defined in the same standard docker way in docker compose. However, looks like Apisix will resolve only variable that were present in apisix.yml when Apisix is started. The variables that are defined in docker compose, but added to apisix.yml after Apisix is started, will be somehow ignored after the config reload task. |
@shreemaan-abhishek the comment you took a screenshot of mentioned I directly installed on the host. I ran into a sed-related error starting APISIX in standalone mode with mounted volume, which blocked me from testing further: apache/apisix-docker#529 @markokocic 's latest comments are good summaries on the matter. It now seems to not be so Docker related and in line with what @hanqingwu described. Essentially, one would need to The next step would be to evaluate whether this leads to only a doc improvement, or more. |
env directive should be used in nginx.conf. then os.getenv work well it is a reliable way . for reference: |
Yes. You need to When apisix starts in standalone mode, it adds the env vars from |
Shouldn't this be done automatically after detecting that config changed and before re-reading the config? |
reloading apisix everytime the config changes sounds like a very bad bad idea. |
I'll consider it resolved. #10530 (comment) |
I will close this once #10755 is merged. |
looks like we can close this issue now, thanks @shreemaan-abhishek |
Latest Update
Please see #10530 (comment)
Current Behavior
From the tests it seems that
apisix.yaml
supports the injection of environment variables.Hence I previously opened #10509 for doc improvement. However, it's been noted from manual testing that env var in
apisix.yaml
did not get resolved when deploying APISIX in standalone mode in Docker.Steps to Reproduce
docker run -d \ --name apisix-standalone \ -p9080:9080 -p9443:9443 -p9090:9092 \ -e APISIX_STAND_ALONE=true \ -e UPSTREAM_NODE_HTTPBIN="httpbin.org" \ apache/apisix
Go into the container (docker exec -it apisix-standalone bash) and update apisix.yaml:
Send a request to the route, if should not go through. Furthermore in logs you see
failed to resolve variables
:Comments
Because these tests pass, I do suspect it might have something to do with the docker environment. However as seen the screenshot above, the env var was also correctly set in the container.
Environment
APISIX v3.7.0 Docker image
The text was updated successfully, but these errors were encountered: