-
Notifications
You must be signed in to change notification settings - Fork 35
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
Make environment variables available inside local server #146
Comments
hello! so, i am a bit hesitant to add this because the environment variables in a Compute@Edge program are predefined in the production environment. these variables are specified here, in case that's helpful: https://developer.fastly.com/reference/compute/ecp-env/ for situations like this i might suggest using an Edge Dictionary, which can contain this sort of runtime configuration. this isn't especially well documented at the moment, but the let me know if this answers your question @GeeWee! |
Yeah I absolutely understand why you're a bit hesitant as you wouldn't be able to read the variables inside the production environment. We actually do use dictionaries reasonably heavily for something similar. Let me perhaps try to outline the situation we're in a little bit.
However, I'd like to be able to swap out the contents of my database key in a, preferably easy way, that means I can run parallel tests.
What are your thoughts? |
after a bit more thought, going with environment variables feels like it won't be the workable answer to this. keeping the environment in which a Wasm program runs in parity with production is an important goal for Viceroy, so i'd like for us to look elsewhere. the to that effect, @GeeWee, i opened up #148 to hopefully accommodate this. this should let you pass a string directly into a and to help you on your journeys, this should look vaguely like this (note that today this still involves writing a config to disk, until the branch above lands.) use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use viceroy_lib::config::Backend;
fn example_invocation() {
// Load the wasm module into an execution context
let mut ctx = viceroy_lib::ExecuteCtx::new("./program.wasm")
.unwrap()
.with_log_stderr(true)
.with_log_stdout(true);
let backend = Backend {
uri: "http://127.0.0.1:8080".parse().unwrap(),
override_host: None,
};
let mut backends = HashMap::new();
backends.insert("backend1".to_owned(), Arc::new(backend));
ctx = ctx
.with_backends(backends.clone())
.with_config_path(PathBuf::from("./fastly.toml"));
tokio::spawn(async move {
viceroy_lib::ViceroyService::new(ctx)
.serve("127.0.0.1:8081".parse().unwrap())
.await
.unwrap()
});
let response = reqwest::get("http://127.0.0.1:8081").await.unwrap();
} edit: clippy lints have helpfully reminded me that the config structure implements |
Totally understand your reasoning. |
thank you for pointing that out, i'd forgotten about the need to place an example of the configuration is included in the PR description over there, but i wanted to ask if this would solve your problems @GeeWee? my hope is that this should give you a more convenient avenue to define distinct values in each of your test iterations 🙂 |
Yes! #150 and the already existing |
In our test suite I have a few places I'd like to e.g. toggle some authentication logic based on environment variables.
This currently seems impossible, as Viceroy only exposes the environment variables it has predefined such as
FASTLY_HOSTNAME
, but it is not possible to set your own env variables and have them be accessible insidefastly compute serve
The text was updated successfully, but these errors were encountered: