Giter VIP home page Giter VIP logo

Comments (7)

thomaseizinger avatar thomaseizinger commented on May 31, 2024

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:

/// A type representing the arguments for an Image.
///
/// There are a couple of things regarding the arguments of images:
///
/// 1. Similar to the Default implementation of an Image, the Default instance
/// of its arguments should be meaningful!
/// 2. Implementations should be conservative about which arguments they expose. Many times,
/// users will either go with the default arguments or just override one or two. When defining
/// the arguments of your image, consider that the whole purpose is to facilitate integration
/// testing. Only expose those that actually make sense for this case.
type Args;

This would allow for a type-safe way to correctly pass the environment variables down to docker.

from testcontainers-rs.

ufoscout avatar ufoscout commented on May 31, 2024

@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.

thomaseizinger avatar thomaseizinger commented on May 31, 2024

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.

D4nte avatar D4nte commented on May 31, 2024

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.

thomaseizinger avatar thomaseizinger commented on May 31, 2024

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.

ufoscout avatar ufoscout commented on May 31, 2024

@thomaseizinger @D4nte

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.

thomaseizinger avatar thomaseizinger commented on May 31, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.