Comments (7)
Yes this is currently not possible. (As you might notice, testcontainers-rs
is still in an early stage 😄 )
I think similar to the arguments of an image, one could add a type to the image that defines, which environment variables it accepts:
testcontainers-rs/core/src/image.rs
Lines 17 to 27 in cc8fdbe
This would allow for a type-safe way to correctly pass the environment variables down to docker.
from testcontainers-rs.
@thomaseizinger
I think that the definition of new env vars should not be part of the image but of the CLI.
This exactly how it works in Docker,
I image it something like:
let image = ...;
// env vars on the CLI startup definition
let cli = clients::Cli::default().withEnv("USER", my_user).withEnv("PASSWORD", my_pass);
let node = docker.run(image);
If you agree I could prepare a PR
from testcontainers-rs.
The env vars are only useful though if the image also picks them up.
In fact, in "traditional" command line docker, env vars belong to containers, i.e. running images. I'd say those correspond to Image instances in testcontainers-rs
.
I think it would provide a huge benefit if an Image
defines the possible env vars (as linked above) and upon instantiation, you can pass in an instance of those.
This would make sure you cannot misspell the env variables.
Even if we don't put the types on the image, I don't think they should go on the Docker
instance. What if you start multiple different images with it? Then env vars would be set that are not picked up by the image.
from testcontainers-rs.
Pre-defining env var for each image removes a lot of flexibility. I think it should be up to the user to define and pass them.
I don't think mispelling of env var should be a concern of this library.
from testcontainers-rs.
I think that the definition of new env vars should not be part of the image but of the CLI.
They should be part of the run
API somehow but not the instance of the Cli
.
Possible ways:
- builder API returned from a method like
build_run
- extend list of arguments of
run
from testcontainers-rs.
Following the testcontainers Java approach, they could be specified directly in the image:
let image = MyImage{}.withEnv("USER", my_user).withEnv("PASSWORD", my_pass);
What do you think?
from testcontainers-rs.
Following the testcontainers Java approach, they could be specified directly in the image:
I am still wondering if we can make it typed somehow.
With an associated type on the image, you can have a method with_env(self, Self::Env) -> Self
.
Self::Env can be any type (also a HashMap) but it would probably be nice if we provide a simple Wrapper around HashMap that allows you to define arbitrary env variables.
For an image like postgres
, we could then define a type like:
struct PostgresEnv {
username: String,
password: String
}
I guess the questions to be answered are:
- is there value in having typed environment variables?
- is there a usecase for setting env variables on an image that we didn't know about before hand? (Considering that the versions of images are usually controlled by the image crate, we should know about the env variables of the image)
from testcontainers-rs.
Related Issues (20)
- Feature "creating images on-the-fly" missing HOT 1
- Connection Refused after exposing port HOT 3
- Reporting a vulnerability HOT 1
- The Contributing guide does not reflect images removal HOT 4
- WaitFor regular expression HOT 1
- Can not run docker image with custom args HOT 1
- Release 0.15 HOT 8
- is there any way to pass "platform" parameter when running docker images? HOT 6
- Support accessing container logs HOT 15
- parallel tests hang with multiple instances of rabbit as GenericImage HOT 1
- [Question] Why would testcontainers fail to create docker network under non-root user HOT 1
- [Discussion] Reason to maintain two different implementation? HOT 1
- [Question] How to specify a newer image for Postgres HOT 2
- Supports running image with `--user` option. HOT 9
- Container doesn't stop after test with std::sync::OnceLock HOT 2
- Concurrency issue: Connection reset by peer HOT 3
- Equivalent to TestContainers.exposeHostPorts? HOT 3
- Stop containers when tests are killed HOT 1
- Feature: Retries due to periodic failure of underlying `docker` commands (ex. `rm`)? HOT 3
- Allow changing the container command HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from testcontainers-rs.