1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use contain_rs::*;
#[derive(ContainerImpl)]
#[container(
image = "docker.io/library/postgres",
health_check_command = "pg_isready"
)]
pub struct Postgres {
#[contain_rs(env_var = "POSTGRES_DB")]
db: Option<String>,
#[contain_rs(env_var = "POSTGRES_USER")]
user: Option<String>,
#[contain_rs(env_var = "POSTGRES_PASSWORD")]
password: String,
}
impl Default for Postgres {
fn default() -> Self {
Self {
db: None,
user: None,
password: "default_pw".to_string(),
}
}
}
impl Postgres {
pub fn with_password(mut self, password: &str) -> Self {
self.password = password.to_string();
self
}
pub fn with_user(mut self, user: &str) -> Self {
self.user = Some(user.to_string());
self
}
pub fn with_db(mut self, db: &str) -> Self {
self.db = Some(db.to_string());
self
}
}
#[cfg(test)]
mod test {
use contain_rs::{Client, Handle, Podman};
use crate::Postgres;
#[test]
fn test_run() {
let client = Podman::new();
let container = client.create(Postgres::default());
container.run_and_wait().unwrap();
}
}