minor refactor
parent
aed887b584
commit
9184475e68
@ -1,21 +0,0 @@
|
||||
# Examples
|
||||
|
||||
In this folder you can find some example Dockerfile syntax extensions.
|
||||
|
||||
## Noop
|
||||
|
||||
This is the most basic example. It just adds a new instruction `NOOP` which does nothing (i.e. it is ignored). With this extension, the following Dockerfile would success fully compile:
|
||||
|
||||
```dockerfile
|
||||
# syntax = edrevo/noop-dockerfile
|
||||
|
||||
NOOP
|
||||
|
||||
FROM alpine
|
||||
|
||||
NOOP
|
||||
|
||||
WORKDIR /
|
||||
|
||||
RUN echo "Hello World"
|
||||
```
|
@ -1,40 +0,0 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use buildkit_proto::moby::buildkit::v1::frontend::CacheOptionsEntry as CacheOptionsEntryProto;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
||||
pub struct CacheOptionsEntry {
|
||||
#[serde(rename = "Type")]
|
||||
pub cache_type: CacheType,
|
||||
|
||||
#[serde(rename = "Attrs")]
|
||||
pub attrs: HashMap<String, String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum CacheType {
|
||||
Local,
|
||||
Registry,
|
||||
Inline,
|
||||
}
|
||||
|
||||
impl Into<CacheOptionsEntryProto> for CacheOptionsEntry {
|
||||
fn into(self) -> CacheOptionsEntryProto {
|
||||
CacheOptionsEntryProto {
|
||||
r#type: self.cache_type.into(),
|
||||
attrs: self.attrs,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<String> for CacheType {
|
||||
fn into(self) -> String {
|
||||
match self {
|
||||
CacheType::Local => "local".into(),
|
||||
CacheType::Registry => "registry".into(),
|
||||
CacheType::Inline => "inline".into(),
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum OptionValue {
|
||||
Flag(bool),
|
||||
Single(String),
|
||||
Multiple(Vec<String>),
|
||||
}
|
@ -1,123 +0,0 @@
|
||||
mod default;
|
||||
mod deserializer;
|
||||
|
||||
pub use self::deserializer::from_env;
|
||||
|
||||
pub mod common;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::path::PathBuf;
|
||||
|
||||
use super::*;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq)]
|
||||
#[serde(untagged)]
|
||||
#[serde(field_identifier, rename_all = "lowercase")]
|
||||
enum Debug {
|
||||
All,
|
||||
LLB,
|
||||
Frontend,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
struct CustomOptions {
|
||||
filename: Option<PathBuf>,
|
||||
verbosity: u32,
|
||||
|
||||
#[serde(default)]
|
||||
debug: Vec<Debug>,
|
||||
|
||||
#[serde(default)]
|
||||
cache_imports: Vec<common::CacheOptionsEntry>,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_options() {
|
||||
let env = vec![
|
||||
(
|
||||
"BUILDKIT_FRONTEND_OPT_0".into(),
|
||||
"filename=/path/to/Dockerfile".into(),
|
||||
),
|
||||
(
|
||||
"BUILDKIT_FRONTEND_OPT_1".into(),
|
||||
"debug=llb,frontend".into(),
|
||||
),
|
||||
(
|
||||
"BUILDKIT_FRONTEND_OPT_2".into(),
|
||||
r#"cache-imports=[{"Type":"local","Attrs":{"src":"cache"}}]"#.into(),
|
||||
),
|
||||
(
|
||||
"BUILDKIT_FRONTEND_OPT_3".into(),
|
||||
"verbosity=12345678".into(),
|
||||
),
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
from_env::<CustomOptions, _>(env.into_iter()).unwrap(),
|
||||
CustomOptions {
|
||||
filename: Some(PathBuf::from("/path/to/Dockerfile")),
|
||||
verbosity: 12_345_678,
|
||||
|
||||
debug: vec![Debug::LLB, Debug::Frontend],
|
||||
|
||||
cache_imports: vec![common::CacheOptionsEntry {
|
||||
cache_type: common::CacheType::Local,
|
||||
attrs: vec![("src".into(), "cache".into())].into_iter().collect()
|
||||
}],
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn env_variable_names() {
|
||||
let env = vec![
|
||||
(
|
||||
"ANOTHER_OPT_0".into(),
|
||||
"filename=/path/to/Dockerfile".into(),
|
||||
),
|
||||
(
|
||||
"ANOTHER_OPT_2".into(),
|
||||
r#"cache-imports=[{"Type":"local","Attrs":{"src":"cache"}}]"#.into(),
|
||||
),
|
||||
("BUILDKIT_FRONTEND_OPT_1".into(), "debug=all".into()),
|
||||
(
|
||||
"BUILDKIT_FRONTEND_OPT_2".into(),
|
||||
"verbosity=12345678".into(),
|
||||
),
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
from_env::<CustomOptions, _>(env.into_iter()).unwrap(),
|
||||
CustomOptions {
|
||||
filename: None,
|
||||
verbosity: 12_345_678,
|
||||
debug: vec![Debug::All],
|
||||
cache_imports: vec![],
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_cache() {
|
||||
let env = vec![
|
||||
("BUILDKIT_FRONTEND_OPT_1".into(), "cache-imports=".into()),
|
||||
(
|
||||
"BUILDKIT_FRONTEND_OPT_2".into(),
|
||||
"verbosity=12345678".into(),
|
||||
),
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
from_env::<CustomOptions, _>(env.into_iter()).unwrap(),
|
||||
CustomOptions {
|
||||
filename: None,
|
||||
verbosity: 12_345_678,
|
||||
debug: vec![],
|
||||
cache_imports: vec![],
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue