Skip to content

Commit

Permalink
New commands in FileBuilder as per Issue #177 #178
Browse files Browse the repository at this point in the history
ENV, ARG, ENTRYPOINT, LABEL, USER, VOLUME.
Also support for the new parameters on FROM, COPY.
  • Loading branch information
mariotoffia committed Mar 17, 2021
1 parent 0b37d76 commit 08fe0ce
Showing 1 changed file with 86 additions and 2 deletions.
88 changes: 86 additions & 2 deletions Ductus.FluentDocker/Builders/FileBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,30 @@ public FileBuilder WorkingFolder(TemplateString workingFolder)
return this;
}

/// <summary>
/// Specified a simplified from command with the image name (and optional tag name) only!
/// </summary>
/// <param name="from">The image and optional tag name.</param>
/// <returns>Itself for fluent access.</returns>
public FileBuilder UseParent(string from)
{
_config.Commands.Add(new FromCommand(from));
return this;
}

/// <summary>
/// Specifies the _FROM_ command.
/// </summary>
/// <param name="imageAndTag">The image to derive from and a optional (colon) tag, e.g. myimg:mytag</param>
/// <param name="asName">An optional alias.</param>
/// <param name="platform">An optional platform such linux/amd64 or windows/amd64.</param>
/// <returns>Itself for fluent access.</returns>
public FileBuilder From(TemplateString imageAndTag, TemplateString asName = null, TemplateString platform = null)
{
_config.Commands.Add(new FromCommand(imageAndTag, asName, platform));
return this;
}

public FileBuilder Maintainer(string maintainer)
{
_config.Commands.Add(new MaintainerCommand(maintainer));
Expand Down Expand Up @@ -127,9 +145,22 @@ public FileBuilder WithHealthCheck(string cmd, string interval = null, string ti
return this;
}

public FileBuilder Copy(TemplateString source, TemplateString dest)
/// <summary>
/// This generates the _COPY_ command.
/// </summary>
/// <param name="source">From directory.</param>
/// <param name="dest">To directory.</param>
/// <param name="chownUserAndGroup">Optional --chown user:group.</param>
/// <param name="fromAlias">
/// Optional source location from earlier buildstage FROM ... AS alias. This will
/// generate --from=aliasname in the _COPY_ command and hence reference a earlier
/// _FROM ... AS aliasname_ buildstep as source.
/// </param>
/// <returns>Itself for fluent access.</returns>
public FileBuilder Copy(TemplateString source, TemplateString dest,
TemplateString chownUserAndGroup = null, TemplateString fromAlias = null)
{
_config.Commands.Add(new CopyCommand(source, dest));
_config.Commands.Add(new CopyCommand(source, dest, chownUserAndGroup, fromAlias));
return this;
}

Expand All @@ -145,6 +176,59 @@ public FileBuilder ExposePorts(params int[] ports)
return this;
}

/// <summary>
/// Adds a _ENV_ command to _dockerfile_. The value of each name value pair is automatically
/// double quoted. Hence, it is possible to write spaces etc in the string without double quoting it.
/// </summary>
/// <param name="nameValue">Name=value array.</param>
/// <returns>Itself for fluent access.</returns>
/// <remarks>The name value is separated by space on same line.</remarks>
public FileBuilder Environment(params TemplateString[] nameValue)
{
_config.Commands.Add(new EnvCommand(nameValue));
return this;
}

/// <summary>
/// Adds a _LABEL_ command to _dockerfile_. The value of each name value pair is automatically
/// double quoted. Hence, it is possible to write spaces etc in the string without double quoting it.
/// </summary>
/// <param name="nameValue">Name=value array.</param>
/// <returns>Itself for fluent access.</returns>
/// <remarks>The name value is separated by space on same line.</remarks>
public FileBuilder Label(params TemplateString[] nameValue)
{
_config.Commands.Add(new LabelCommand(nameValue));
return this;
}

/// <summary>
/// Adds a _ARG_ command in _dockerfile_ with the optional _defaultValue_.
/// </summary>
/// <param name="name">The name of the argument.</param>
/// <param name="defaultValue">Optional a default value for the argument.</param>
/// <returns>Itself for fluent access.</returns>
public FileBuilder Arguments(TemplateString name, TemplateString defaultValue = null) {
_config.Commands.Add(new ArgCommand(name, defaultValue));
return this;
}

public FileBuilder Entrypoint(string command, params string[] args)
{
_config.Commands.Add(new EntrypointCommand(command, args));
return this;
}

public FileBuilder User(TemplateString user, TemplateString group = null) {
_config.Commands.Add(new UserCommand(user, group));
return this;
}

public FileBuilder Volume(params TemplateString[] mountpoints) {
_config.Commands.Add(new VolumeCommand(mountpoints));
return this;
}

public FileBuilder Command(string command, params string[] args)
{
_config.Commands.Add(new CmdCommand(command, args));
Expand Down

0 comments on commit 08fe0ce

Please sign in to comment.