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

docs: mention the support for env var in apisix.yaml #10509

Closed
kayx23 opened this issue Nov 17, 2023 · 7 comments · Fixed by #10727
Closed

docs: mention the support for env var in apisix.yaml #10509

kayx23 opened this issue Nov 17, 2023 · 7 comments · Fixed by #10727
Labels
doc Documentation things good first issue Good for newcomers

Comments

@kayx23
Copy link
Member

kayx23 commented Nov 17, 2023

Background

The doc currently only provides examples for the usage of env var in config.yaml. It could lead users to think only config.yaml supports env var and not apisix.yaml, which isn't true. apisix.yaml supports env var.

In additional, you can not only use env var in yaml values, but also keys. For details, see https://github.com/apache/apisix/blob/master/t/cli/test_standalone.sh

Desired State

Update https://apisix.apache.org/docs/apisix/profile/#using-environment-variables-in-the-configuration-file

Specifically, you should mention

  1. apisix.yaml supports env var
  2. env var can be used in yaml keys as well

Given how the section is currently presented, you might want to break the info into smaller sections with h3 ###.

@kayx23 kayx23 added the doc Documentation things label Nov 17, 2023
@kayx23 kayx23 added the help wanted Extra attention is needed label Nov 17, 2023
@markokocic
Copy link
Contributor

I'll pick this up tomorrow.

@kayx23
Copy link
Member Author

kayx23 commented Nov 20, 2023

Great! Thanks for jumping in on it.

@markokocic
Copy link
Contributor

hi @kayx23
I just tested again before updating the docs, and it looks that environment variable substitution is indeed not supported in standalone apisix.yaml

I craeted the following route:

  - uri: /b92/*
    upstream:
      nodes: 
        "${{EP_MYHOST_1:=}}:443": 1
      type: roundrobin
      scheme: https

and configured EP_MYHOST_1 environment variable in docker compose file by adding:

    environment:
      - EP_MYHOST_1=b92.net

I then started the container and logged in to the running container to confirm:

apisix@e9512d0cfdaa:/usr/local/apisix$ echo $EP_MYHOST_1
b92.net

However, when I try to access the route, I get the following response:

C:\Users\Marko.Kocic>curl http://localhost:9080/b92/
<html>
<head><title>503 Service Temporarily Unavailable</title></head>
<body>
<center><h1>503 Service Temporarily Unavailable</h1></center>
<hr><center>openresty</center>
<p><em>Powered by <a href="https://apisix.apache.org/">APISIX</a>.</em></p></body>
</html>

Apisix logs also shows the same error:

2023/11/21 08:39:25 [error] 38#38: *6194 [lua] upstream.lua:79: parse_domain_for_nodes(): dns resolver domain: ${{EP_MYHOST_1:=}}:443 error: failed to query the DNS server: dns server error: 3 name error, client: 10.89.0.7, server: _, request: "GET /b92/ HTTP/1.1", host: "localhost:9080"
2023/11/21 08:39:25 [error] 38#38: *6194 [lua] resolver.lua:80: parse_domain(): failed to parse domain: , error: failed to query the DNS server: dns server error: 3 name error, client: 10.89.0.7, server: _, request: "GET /b92/ HTTP/1.1", host: "localhost:9080"
2023/11/21 08:39:25 [error] 38#38: *6194 [lua] upstream.lua:79: parse_domain_for_nodes(): dns resolver domain:  error: failed to query the DNS server: dns server error: 3 name error, client: 10.89.0.7, server: _, request: "GET /b92/ HTTP/1.1", host: "localhost:9080"
2023/11/21 08:39:25 [error] 38#38: *6194 [lua] init.lua:551: handle_upstream(): failed to set upstream: no valid upstream node, client: 10.89.0.7, server: _, request: "GET /b92/ HTTP/1.1", host: "localhost:9080"
10.89.0.7 - - [21/Nov/2023:08:39:25 +0000] localhost:9080 "GET /b92/ HTTP/1.1" 503 269 0.522 "-" "curl/8.4.0" - - - "http://localhost:9080"

However, when I update apisix.yml file to use host name instead of a variable, everything works ok.

At this point, I tend to believe that the documentation is correct that it doesn't mention apisix.yml supporting environment variable substitution. Maybe it should be explicit about not supporting, since initially, I also wrongly believed that it should support it.

Or a feat ticket should be created to enable this support in apisix.yml.

@kayx23
Copy link
Member Author

kayx23 commented Nov 21, 2023

Thanks for checking. I'm not sure what went off in your test yet but I double checked the code and test -- it does look like apisix.yaml should support env var. It doesn't, then it's a bug.

Let me run some tests.

@kayx23
Copy link
Member Author

kayx23 commented Nov 21, 2023

I tested and could see in the log that APISIX attempts to resolve the variable but failed:

image

The env var was also properly set in the container as seen in the screenshot.

I started the container with:

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

So something's not right here.

But I do expect it to work: https://github.com/apache/apisix/blob/master/t/cli/test_standalone.sh#L72-L97

@kayx23
Copy link
Member Author

kayx23 commented Nov 27, 2023

Hi @markokocic, as the CLI tests pass just fine, I suspect this has something to do with Docker, though I cannot advise what the issue is atm.

To not make this doc effort stagnant, I would reference the CLI tests for this doc update. If you are in the spirit to check further, you can do the same experiment with APISIX installed on host. This should be the scenario covered by the test cases. What do you think?

@kayx23 kayx23 added good first issue Good for newcomers and removed help wanted Extra attention is needed labels Nov 29, 2023
@markokocic
Copy link
Contributor

hi @kayx23 I don't have a problem with updating docs, but would rather wait until the underlaying issue is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Documentation things good first issue Good for newcomers
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants