Struct DofigenContext

Source
pub struct DofigenContext {
    pub offline: bool,
    pub update_file_resources: bool,
    pub update_url_resources: bool,
    pub update_docker_tags: bool,
    pub display_updates: bool,
    pub no_default_labels: bool,
    /* private fields */
}
Expand description

The representation of the Dofigen execution context

Fields§

§offline: bool§update_file_resources: bool§update_url_resources: bool§update_docker_tags: bool§display_updates: bool§no_default_labels: bool

Implementations§

Source§

impl DofigenContext

Source

pub fn image_updates( &self, previous: &DofigenContext, ) -> Vec<UpdateCommand<ImageName, DockerTag>>

Source

pub fn resource_updates( &self, previous: &DofigenContext, ) -> Vec<UpdateCommand<Resource, ResourceVersion>>

Source

pub fn parse_from_string(&mut self, input: &str) -> Result<Dofigen>

Parse an Dofigen from a string.

§Examples

Basic struct

use dofigen_lib::*;
use pretty_assertions_sorted::assert_eq_sorted;

let yaml = "
fromImage:
  path: ubuntu
";
let image: Dofigen = DofigenContext::new().parse_from_string(yaml).unwrap();
assert_eq_sorted!(
    image,
    Dofigen {
      stage: Stage {
        from: ImageName {
            path: String::from("ubuntu"),
            ..Default::default()
        }.into(),
        ..Default::default()
      },
     ..Default::default()
    }
);

Advanced image with builders and artifacts

use dofigen_lib::*;
use pretty_assertions_sorted::assert_eq_sorted;
use std::collections::HashMap;

let yaml = r#"
builders:
  builder:
    fromImage:
      path: ekidd/rust-musl-builder
    copy:
      - paths: ["*"]
    run:
      - cargo build --release
fromImage:
    path: ubuntu
copy:
  - fromBuilder: builder
    paths:
      - /home/rust/src/target/x86_64-unknown-linux-musl/release/template-rust
    target: /app
"#;
let image: Dofigen = DofigenContext::new().parse_from_string(yaml).unwrap();
assert_eq_sorted!(
    image,
    Dofigen {
        builders: HashMap::from([
            ("builder".to_string(), Stage {
                from: ImageName { path: "ekidd/rust-musl-builder".into(), ..Default::default() }.into(),
                copy: vec![CopyResource::Copy(Copy{paths: vec!["*".into()].into(), ..Default::default()}).into()].into(),
                run: Run {
                    run: vec!["cargo build --release".parse().unwrap()].into(),
                    ..Default::default()
                },
                ..Default::default()
            }),
        ]),
        stage: Stage {
            from: ImageName {
                path: "ubuntu".into(),
                ..Default::default()
            }.into(),
            copy: vec![CopyResource::Copy(Copy{
                from: FromContext::FromBuilder(String::from("builder")),
                paths: vec![String::from(
                    "/home/rust/src/target/x86_64-unknown-linux-musl/release/template-rust"
                )],
                options: CopyOptions {
                    target: Some(String::from("/app")),
                    ..Default::default()
                },
                ..Default::default()
            })].into(),
            ..Default::default()
        },
        ..Default::default()
    }
);
Source

pub fn parse_from_reader<R: Read>(&mut self, reader: R) -> Result<Dofigen>

Parse an Dofigen from an IO stream.

§Examples

Basic struct

use dofigen_lib::*;
use pretty_assertions_sorted::assert_eq_sorted;

let yaml = "
fromImage:
  path: ubuntu
";

let image: Dofigen = DofigenContext::new().parse_from_reader(yaml.as_bytes()).unwrap();
assert_eq_sorted!(
    image,
    Dofigen {
        stage: Stage {
            from: ImageName {
                path: String::from("ubuntu"),
                ..Default::default()
            }.into(),
            ..Default::default()
        },
        ..Default::default()
    }
);

Advanced image with builders and artifacts

use dofigen_lib::*;
use pretty_assertions_sorted::assert_eq_sorted;
use std::collections::HashMap;

let yaml = r#"
builders:
  builder:
    fromImage:
      path: ekidd/rust-musl-builder
    copy:
      - paths: ["*"]
    run:
      - cargo build --release
fromImage:
    path: ubuntu
copy:
  - fromBuilder: builder
    paths:
      - /home/rust/src/target/x86_64-unknown-linux-musl/release/template-rust
    target: /app
"#;
let image: Dofigen = DofigenContext::new().parse_from_reader(yaml.as_bytes()).unwrap();
assert_eq_sorted!(
    image,
    Dofigen {
        builders: HashMap::from([
            ("builder".to_string(), Stage {
                from: ImageName { path: "ekidd/rust-musl-builder".into(), ..Default::default() }.into(),
                copy: vec![CopyResource::Copy(Copy{paths: vec!["*".into()].into(), ..Default::default()}).into()].into(),
                run: Run {
                    run: vec!["cargo build --release".parse().unwrap()].into(),
                    ..Default::default()
                },
                ..Default::default()
            }),
        ]),
        stage: Stage {
            from: ImageName {
                path: String::from("ubuntu"),
                ..Default::default()
            }.into(),
            copy: vec![CopyResource::Copy(Copy {
                from: FromContext::FromBuilder(String::from("builder")),
                paths: vec![String::from(
                    "/home/rust/src/target/x86_64-unknown-linux-musl/release/template-rust"
                )],
                options: CopyOptions {
                    target: Some(String::from("/app")),
                    ..Default::default()
                },
                ..Default::default()
            })].into(),
            ..Default::default()
        },
        ..Default::default()
    }
);
Source

pub fn parse_from_resource(&mut self, resource: Resource) -> Result<Dofigen>

Parse an Dofigen from a Resource (File or Url)

§Example
use dofigen_lib::*;
use pretty_assertions_sorted::assert_eq_sorted;
use std::path::PathBuf;

let dofigen: Dofigen = DofigenContext::new().parse_from_resource(Resource::File(PathBuf::from("tests/cases/simple.yml"))).unwrap();
assert_eq_sorted!(
    dofigen,
    Dofigen {
        stage: Stage {
            from: ImageName {
                path: String::from("alpine"),
                ..Default::default()
            }.into(),
            ..Default::default()
        },
        ..Default::default()
    }
);
Source

pub fn clean_unused(&mut self)

Source

pub fn new() -> Self

Source

pub fn from( resources: HashMap<Resource, ResourceVersion>, images: HashMap<ImageName, DockerTag>, ) -> Self

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T