-
Notifications
You must be signed in to change notification settings - Fork 170
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
[cli] decouple apicast environment and 3scale configuration channel #590
Conversation
3ded468
to
751ab3f
Compare
* THREESCALE_DEPLOYMENT_ENV controls the 3scale proxy configuration channel (staging/production) * APICAST_ENVIRONMENT controls the APIcast settings (caching, ...) * APICAST_LOADED_ENVIRONMENTS can control always loaded APIcast environments
af1754e
to
ea10dc5
Compare
* so the environment configuration is default value * the cli options are just overrides It should be possible to run apicast staging/production and get all the caching configurations already set.
and allow per test setting of environment and use new test configuration loader (that does nothing)
e196165
to
786a5c2
Compare
* gateway needs some endpoint that returns to for the "boot" loader * some tests used to run in lazy mode, so keep it that way
@@ -0,0 +1 @@ | |||
staging.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.
Why sandbox
and why it's the same as staging?
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.
Because some configurations can still have THREESCALE_DEPLOYMENT_ENV=sandbox
. It was the original value in AMP 2.0 IIRC. We alias it now to staging
which makes more sense.
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.
👍
master_process = 'on', | ||
lua_code_cache = 'on', | ||
configuration_loader = 'lazy', | ||
configuration_cache = 0, |
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.
Why not os.getenv('APICAST_CONFIGURATION_CACHE') or 0
?
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.
I think our staging should always reload configuration. And because of the order of options
and context
in the start.lua
the CLI options take precedence. So setting APICAST_CONFIGURATION_CACHE
env would override this anyway.
That makes the production.lua os.getenv
a bit redundant, but I wanted it there as an example of what can be done. But if it is confusing I could change/remove it.
@@ -148,7 +148,7 @@ function _M:add(env) | |||
|
|||
local config = loadfile(path, 't', { | |||
print = print, inspect = require('inspect'), context = self._context, | |||
tonumber = tonumber, tostring = tostring, | |||
tonumber = tonumber, tostring = tostring, os = { getenv = resty_env.value }, |
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.
I think that overriding getenv
here can be a bit confusing.
Although I get that you're doing this to be able to use it in the environment files.
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.
Yep. I think it is more useful to expose resty_env.value
than plain resty_env.get
or os.getenv
.
And the only difference is that it does not return empty strings. Which is actually useful for default values.
env_to_nginx( | ||
'APICAST_CONFIGURATION_LOADER', | ||
env_to_apicast( | ||
'APICAST_CONFIGURATION_LOADER' => 'boot' |
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.
Was this allowed before or it's supported since Test::APIcast 0.08 ?
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.
This wasn't really working before Test::APIcast 0.08. env_to_nginx
was not working in Test::APIcast::Blackbox at all.
@@ -15,7 +15,7 @@ init_by_lua_block { | |||
-- This ENV variable is defined in the main nginx.conf.liquid and injected when including this partial. | |||
-- The content of the ENV variable is a Lua table, so when rendered it actually can run ipairs on it. | |||
for k,v in pairs({{ ENV }}) do | |||
if type(k) == 'string' and k ~= 'APICAST_CONFIGURATION_LOADER' then | |||
if type(k) == 'string' and not resty_env.value(k) then |
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.
I don't get this change. Can you explain it, please?
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.
It sets only missing/empty variables.
This leaves the flexibility of overriding the ENV when starting nginx and treating the {{ ENV }}
only as default values.
Because Test::APIcast runs APICAST_CONFIGURATION_LOADER=test bin/apicast
and expects it to work. But in cases where APICAST_CONFIGURATION_LOADER=boot
is already set in the ENV this would not apply and APICAST_CONFIGURATION_LOADER
would have value boot
during initialization. Basically ignoring what ENV it was started in.
So this change is for two reasons:
- I think it makes sense for ENV of the shell to take priority than what is in the config file
- Test::APIcast needs to start APIcast with APICAST_CONFIGURATION_LOADER=test when testing configuration with
--test
but then later start it withboot
when the config is started for real (with no APICAST_CONFIGURATION_LOADER - but that is already hardcoded in the config as the default).
THREESCALE_DEPLOYMENT_ENV
controls the 3scale proxy configurationchannel (staging/production) and can be passed as
-3 --channel
from the CLIAPICAST_ENVIRONMENT
controls the APIcast settings (caching, ...) and can be passed by-e --environment
from the CLIAPICAST_LOADED_ENVIRONMENTS
can control always loaded APIcast environments (internal use only)production
is still the default configuration channel, that loads theproduction
environment configuration which configures the configuration loader to "boot". In short this makes APIcast to requireTHREESCALE_PORTAL_ENDPOINT
or--configuration
when started without any other params. That makesbin/apicast
to not start because it is missing configuration.Needed for 3scale/apicast-cloud-hosted#1