-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from mariotoffia/feature-filebuilder-misc
Add features to Docker FileBuilder
- Loading branch information
Showing
13 changed files
with
443 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"cSpell.words": [ | ||
"dont" | ||
"Ductus", | ||
"dont", | ||
"myimg", | ||
"mytag" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
namespace Ductus.FluentDocker.Extensions { | ||
public static class StringExtensions { | ||
|
||
/// <summary> | ||
/// This function will wrap the string s with string c (start and end) if | ||
/// not already existant. If already exist, it will leave it, hence it | ||
/// do not double wrap. | ||
/// </summary> | ||
/// <param name="s">The string to wrap.</param> | ||
/// <param name="c">The string to check and wrap with if not existing.</param> | ||
/// <returns>The wrapped string.</returns> | ||
public static string WrapWithChar(this string s, string c) { | ||
|
||
if (!s.StartsWith(c)) { | ||
s = c + s; | ||
} | ||
|
||
if (!s.EndsWith(c)) { | ||
s = s + c; | ||
} | ||
|
||
return s; | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
Ductus.FluentDocker/Model/Builders/FileBuilder/ArgCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Ductus.FluentDocker.Common; | ||
using Ductus.FluentDocker.Extensions; | ||
using Ductus.FluentDocker.Model.Common; | ||
|
||
namespace Ductus.FluentDocker.Model.Builders.FileBuilder | ||
{ | ||
public sealed class ArgCommand : ICommand | ||
{ | ||
public ArgCommand(TemplateString name, TemplateString defaultValue = null) | ||
{ | ||
if (null == name || string.IsNullOrEmpty(name.Rendered)) | ||
{ | ||
throw new FluentDockerException("Must, at least, specify the argument name in a ARG"); | ||
} | ||
|
||
|
||
Name = name.Rendered; | ||
|
||
if (null != defaultValue && !string.IsNullOrEmpty(defaultValue.Rendered)) | ||
{ | ||
DefaultValue = defaultValue.Rendered; | ||
} | ||
} | ||
|
||
public string Name { get; } | ||
public string DefaultValue { get; } | ||
|
||
public override string ToString() | ||
{ | ||
if (string.IsNullOrEmpty(DefaultValue)) | ||
{ | ||
return $"ARG {Name}"; | ||
} | ||
|
||
return $"ARG {Name}={DefaultValue}"; | ||
} | ||
} | ||
} |
45 changes: 40 additions & 5 deletions
45
Ductus.FluentDocker/Model/Builders/FileBuilder/CopyCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,54 @@ | ||
namespace Ductus.FluentDocker.Model.Builders.FileBuilder | ||
using Ductus.FluentDocker.Extensions; | ||
using Ductus.FluentDocker.Model.Common; | ||
|
||
namespace Ductus.FluentDocker.Model.Builders.FileBuilder | ||
{ | ||
public sealed class CopyCommand : ICommand | ||
{ | ||
public CopyCommand(string from, string to) | ||
/// <summary> | ||
/// This generates the _COPY_ command. | ||
/// </summary> | ||
/// <param name="from">From directory.</param> | ||
/// <param name="to">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> | ||
public CopyCommand(TemplateString from, TemplateString to, | ||
TemplateString chownUserAndGroup = null, TemplateString fromAlias = null) | ||
{ | ||
From = from; | ||
To = to; | ||
From = from.Rendered.WrapWithChar("\""); | ||
To = to.Rendered.WrapWithChar("\""); | ||
|
||
if (null != chownUserAndGroup && !string.IsNullOrEmpty(chownUserAndGroup.Rendered)) { | ||
Chown = chownUserAndGroup.Rendered; | ||
} | ||
|
||
if (null != fromAlias && !string.IsNullOrEmpty(fromAlias.Rendered)) { | ||
Alias = fromAlias.Rendered; | ||
} | ||
} | ||
|
||
public string From { get; } | ||
public string To { get; } | ||
public string Alias { get; } | ||
public string Chown { get; } | ||
|
||
public override string ToString() | ||
{ | ||
return $"COPY {From} {To}"; | ||
string s = "COPY"; | ||
|
||
if (!string.IsNullOrEmpty(Chown)) { | ||
s = $"{s} --chown={Chown}"; | ||
} | ||
|
||
if (!string.IsNullOrEmpty(Alias)) { | ||
s = $"{s} --from={Alias}"; | ||
} | ||
|
||
return $"{s} [{From},{To}]"; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Ductus.FluentDocker/Model/Builders/FileBuilder/EntrypointCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
|
||
namespace Ductus.FluentDocker.Model.Builders.FileBuilder | ||
{ | ||
public sealed class EntrypointCommand : ICommand | ||
{ | ||
public EntrypointCommand(string executable, params string[] args) | ||
{ | ||
Executable = executable; | ||
Arguments = args ?? Array.Empty<string>(); | ||
} | ||
|
||
public string Executable { get; } | ||
public string[] Arguments { get; } | ||
|
||
public override string ToString() | ||
{ | ||
return $"ENTRYPOINT [\"{Executable}{string.Join("\",\"", Arguments)}\"]"; | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Ductus.FluentDocker/Model/Builders/FileBuilder/EnvCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Ductus.FluentDocker.Extensions; | ||
using Ductus.FluentDocker.Model.Common; | ||
using System.Linq; | ||
|
||
namespace Ductus.FluentDocker.Model.Builders.FileBuilder | ||
{ | ||
public sealed class EnvCommand : ICommand | ||
{ | ||
public EnvCommand(params TemplateString[] nameValue) | ||
{ | ||
if (nameValue == null || 0 == nameValue.Length) { | ||
NameValue = new string[0]; | ||
} else { | ||
NameValue = NameValue = nameValue.WrapValue().ToArray(); | ||
} | ||
} | ||
|
||
public string[] NameValue { get; internal set; } | ||
|
||
public override string ToString() | ||
{ | ||
if (0 == NameValue.Length) { | ||
return ""; | ||
} | ||
|
||
return $"ENV {string.Join(" ", NameValue)}"; | ||
} | ||
} | ||
} |
Oops, something went wrong.