-
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
feat: support for reading environment variables from yaml configuration files #5244 #6505
Changes from 1 commit
21e23af
90bb471
ace1514
0c7f98b
a8eb15b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,70 @@ | ||||||||||||
#!/usr/bin/env bash | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's rename it to test_standalone.sh, so it can be used in other places later. |
||||||||||||
|
||||||||||||
# | ||||||||||||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||||||||||||
# contributor license agreements. See the NOTICE file distributed with | ||||||||||||
# this work for additional information regarding copyright ownership. | ||||||||||||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||||||||||||
# (the "License"); you may not use this file except in compliance with | ||||||||||||
# the License. You may obtain a copy of the License at | ||||||||||||
# | ||||||||||||
# http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||
# | ||||||||||||
# Unless required by applicable law or agreed to in writing, software | ||||||||||||
# distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||
# See the License for the specific language governing permissions and | ||||||||||||
# limitations under the License. | ||||||||||||
# | ||||||||||||
|
||||||||||||
. ./t/cli/common.sh | ||||||||||||
|
||||||||||||
# check supported environment variables in apisix.yaml | ||||||||||||
|
||||||||||||
yaml_config_variables_clean_up() { | ||||||||||||
wilson-1024 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
git checkout conf/config.yaml | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use the original clean up like: apisix/t/cli/test_serverless.sh Lines 21 to 25 in 380f762
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. Please review it again. |
||||||||||||
git checkout conf/apisix.yaml | ||||||||||||
} | ||||||||||||
|
||||||||||||
trap yaml_config_variables_clean_up EXIT | ||||||||||||
|
||||||||||||
echo ' | ||||||||||||
apisix: | ||||||||||||
enable_admin: false | ||||||||||||
config_center: yaml | ||||||||||||
' > conf/config.yaml | ||||||||||||
|
||||||||||||
echo ' | ||||||||||||
routes: | ||||||||||||
- | ||||||||||||
uri: ${{var_test_path}} | ||||||||||||
plugins: | ||||||||||||
proxy-rewrite: | ||||||||||||
uri: ${{var_test_proxy_rewrite_uri:=/apisix/nginx_status}} | ||||||||||||
upstream: | ||||||||||||
nodes: | ||||||||||||
"127.0.0.1:9091": 1 | ||||||||||||
type: roundrobin | ||||||||||||
#END | ||||||||||||
' > conf/apisix.yaml | ||||||||||||
|
||||||||||||
# check for resolve variables | ||||||||||||
var_test_path=/test make init | ||||||||||||
|
||||||||||||
if ! grep "env var_test_path=/test;" conf/nginx.conf > /dev/null; then | ||||||||||||
echo "failed: failed to resolve variables" | ||||||||||||
exit 1 | ||||||||||||
fi | ||||||||||||
|
||||||||||||
# variable is valid | ||||||||||||
var_test_path=/test make run | ||||||||||||
sleep 0.1 | ||||||||||||
code=$(curl -o /dev/null -s -m 5 -w %{http_code} http://127.0.0.1:9080/test) | ||||||||||||
if [ ! $code -eq 200 ]; then | ||||||||||||
echo "failed: variable is not valid" | ||||||||||||
exit 1 | ||||||||||||
fi | ||||||||||||
|
||||||||||||
make stop | ||||||||||||
|
||||||||||||
echo "passed: resolve variables" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put this in apisix/core/config_yaml.lua?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first I wanted to put this in apisix/core/config_yaml.lua, but because the file loads ngx variables, it needs to be loaded in the openresty environment. Can't run in CLI mode, so we can't put this in apisix/core/config_yaml.lua