Skip to main content

nanite_docker/instruction/
mod.rs

1// A few notes about editing the instructions: (this is a code comment as it is only designed for contributors)
2// 1. Every instruction gets its own file - This makes maintaining all the instructions easier and avoids accidental modifications where they're not intended
3// 2. No generic representations, each instruction should own its own processes - This means that a single modification to ONE instruction doesn't change many
4// 3. Make each instruction well documentated where there is ambiguity - These instructions make up the majority of the public API, so people need to be 100% sure of what they do
5
6mod add;
7mod arg;
8mod cmd;
9mod copy;
10mod entrypoint;
11mod env;
12mod expose;
13mod healthcheck;
14mod label;
15mod maintainer;
16mod onbuild;
17mod run;
18mod shell;
19mod stopsignal;
20mod user;
21mod volume;
22mod workdir;
23
24// NOTE: This directly defines the public API
25// Editing this list of exports REQUIRES a major semver update
26pub use add::{Add, AddOpt};
27pub use arg::Arg;
28pub use cmd::Cmd;
29pub use copy::{Copy, CopyOpt};
30pub use entrypoint::Entrypoint;
31pub use env::Env;
32pub use expose::{Expose, ExposeProtocol};
33pub use healthcheck::{HealthCheck, HealthCheckOpt};
34pub use label::Label;
35pub use maintainer::Maintainer;
36pub use onbuild::OnBuild;
37pub use run::{
38    Run, RunMount, RunMountBind, RunMountBindOpts, RunMountCache, RunMountCacheOpts, RunMountSSH,
39    RunMountSSHOpts, RunMountSecret, RunMountSecretOpts, RunMountTmpfs, RunMountTmpfsOpts,
40    RunNetwork, RunSecurity, RunSharing,
41};
42pub use shell::Shell;
43pub use stopsignal::StopSignal;
44pub use user::User;
45pub use volume::Volume;
46pub use workdir::WorkDir;
47
48use core::fmt::{Display, Formatter};
49
50/// The Instruction is one of the 3 core units of the Dockerfile Rust Intermediate Representation
51/// It directly represents a typed version of Dockerfile [Instruction](https://docs.docker.com/reference/dockerfile/).
52/// Note that the `From` Instruction is not available, this is becuase each stage can only have one `From` instruction so it is defined in the stage
53#[derive(Debug, Clone)]
54pub enum Instruction {
55    Add(Add),
56    Arg(Arg),
57    Cmd(Cmd),
58    Copy(Copy),
59    Entrypoint(Entrypoint),
60    Env(Env),
61    Expose(Expose),
62    HealthCheck(HealthCheck),
63    Label(Label),
64    Maintainer(Maintainer),
65    OnBuild(OnBuild),
66    Run(Run),
67    Shell(Shell),
68    StopSignal(StopSignal),
69    User(User),
70    Volume(Volume),
71    Workdir(WorkDir),
72}
73
74impl Display for Instruction {
75    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
76        match self {
77            Self::Add(e) => write!(f, "{e}"),
78            Self::Arg(e) => write!(f, "{e}"),
79            Self::Cmd(e) => write!(f, "{e}"),
80            Self::Copy(e) => write!(f, "{e}"),
81            Self::Entrypoint(e) => write!(f, "{e}"),
82            Self::Env(e) => write!(f, "{e}"),
83            Self::Expose(e) => write!(f, "{e}"),
84            Self::HealthCheck(e) => write!(f, "{e}"),
85            Self::Label(e) => write!(f, "{e}"),
86            Self::Maintainer(e) => write!(f, "{e}"),
87            Self::OnBuild(e) => write!(f, "{e}"),
88            Self::Run(e) => write!(f, "{e}"),
89            Self::Shell(e) => write!(f, "{e}"),
90            Self::StopSignal(e) => write!(f, "{e}"),
91            Self::User(e) => write!(f, "{e}"),
92            Self::Volume(e) => write!(f, "{e}"),
93            Self::Workdir(e) => write!(f, "{e}"),
94        }
95    }
96}
97
98/// A selection of Instructions that can be placed prior to a FROM Statement in a Stage.
99#[derive(Debug, Clone)]
100pub enum PreFromInstruction {
101    Arg(Arg),
102    Label(Label),
103}
104impl Display for PreFromInstruction {
105    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
106        match self {
107            Self::Arg(e) => write!(f, "{e}"),
108            Self::Label(e) => write!(f, "{e}"),
109        }
110    }
111}