main.rs 2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use lazy_static::lazy_static;
use serde::Serialize;
use std::env;
use std::fs;
use std::process;
use tera::{Context, Result, Tera};

#[derive(Serialize)]
struct TmpltArgs {
    ffmpeg: bool,
    grok: bool,
    kakadu: bool,
    openjpeg: bool,
    turbojpeg: bool,
15
16
    version: String,
    port: String,
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
}

fn main() -> Result<()> {
    lazy_static! {
        pub static ref TEMPLATE: Tera = {
            match Tera::new("*.template") {
                Ok(t) => t,
                Err(e) => {
                    eprintln!("Error occurred: {}", &e);
                    process::exit(1);
                }
            }
        };
    };

    let mut tmplt_args = TmpltArgs {
        ffmpeg: false,
        grok: false,
        kakadu: false,
        openjpeg: false,
        turbojpeg: false,
38
39
        version: String::with_capacity(5),
        port: String::with_capacity(5),
40
41
42
43
44
45
46
47
48
49
50
51
52
    };

    for arg in env::args().skip(1) {
        if arg == "--ffmpeg" {
            tmplt_args.ffmpeg = true;
        } else if arg == "--grok" {
            tmplt_args.grok = true;
        } else if arg == "--kakadu" {
            tmplt_args.kakadu = true;
        } else if arg == "--openjpeg" {
            tmplt_args.openjpeg = true;
        } else if arg == "--turbojpeg" {
            tmplt_args.turbojpeg = true;
53
54
55
56
        } else if arg.starts_with("--version=") {
            tmplt_args.version = String::from(arg.split("=").nth(1).unwrap());
        } else if arg.starts_with("--port=") {
            tmplt_args.port = String::from(arg.split("=").nth(1).unwrap());
57
58
        }
    }
59
60
61
62
63
64
65
66
67
68

    if tmplt_args.version.is_empty() {
        eprintln!("Please declare Cantaloupe version with `--version=x.y.z`");
        process::exit(1);
    }
    if tmplt_args.port.is_empty() {
        eprintln!("Please declare Cantaloupe port with `--port=xxxxx`");
        process::exit(1);
    }

69
70
71
72
73
74
75
    let docker_image = TEMPLATE.render(
        "Dockerfile.template",
        &Context::from_serialize(&tmplt_args)?,
    )?;
    fs::write("Dockerfile", docker_image)?;
    Ok(())
}