-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added several dockerfile commands for Issue #177
ENV, ARG, ENTRYPOINT, LABEL, USER, VOLUME
- Loading branch information
1 parent
0074eac
commit 276065e
Showing
9 changed files
with
255 additions
and
0 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,6 @@ | ||
{ | ||
"cSpell.words": [ | ||
"Ductus", | ||
"dont" | ||
] | ||
} |
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}"; | ||
} | ||
} | ||
} |
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)}"; | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
Ductus.FluentDocker/Model/Builders/FileBuilder/LabelCommand.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,33 @@ | ||
using Ductus.FluentDocker.Extensions; | ||
using Ductus.FluentDocker.Model.Common; | ||
using System.Linq; | ||
|
||
namespace Ductus.FluentDocker.Model.Builders.FileBuilder | ||
{ | ||
public sealed class LabelCommand : ICommand | ||
{ | ||
public LabelCommand(params TemplateString[] nameValue) | ||
{ | ||
if (nameValue == null || 0 == nameValue.Length) | ||
{ | ||
NameValue = new string[0]; | ||
} | ||
else | ||
{ | ||
NameValue = nameValue.WrapValue().ToArray(); | ||
} | ||
} | ||
|
||
public string[] NameValue { get; internal set; } | ||
|
||
public override string ToString() | ||
{ | ||
if (0 == NameValue.Length) | ||
{ | ||
return ""; | ||
} | ||
|
||
return $"LABEL {string.Join(" ", NameValue)}"; | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
Ductus.FluentDocker/Model/Builders/FileBuilder/UserCommand.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 UserCommand : ICommand | ||
{ | ||
public UserCommand(TemplateString user, TemplateString group = null) | ||
{ | ||
if (null == user || string.IsNullOrEmpty(user.Rendered)) | ||
{ | ||
throw new FluentDockerException("Must specify username or user id"); | ||
} | ||
|
||
|
||
User = user.Rendered; | ||
|
||
if (null != group && !string.IsNullOrEmpty(group.Rendered)) | ||
{ | ||
Group = group.Rendered; | ||
} | ||
} | ||
|
||
public string User { get; } | ||
public string Group { get; } | ||
|
||
public override string ToString() | ||
{ | ||
if (string.IsNullOrEmpty(Group)) | ||
{ | ||
return $"USER {User}"; | ||
} | ||
|
||
return $"USER {User}:{Group}"; | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
Ductus.FluentDocker/Model/Builders/FileBuilder/VolumeCommand.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,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Ductus.FluentDocker.Extensions; | ||
using Ductus.FluentDocker.Model.Common; | ||
|
||
namespace Ductus.FluentDocker.Model.Builders.FileBuilder | ||
{ | ||
public sealed class VolumeCommand : ICommand | ||
{ | ||
public VolumeCommand(params TemplateString[] mountpoints) | ||
{ | ||
var list = new List<string>(); | ||
|
||
foreach (var s in mountpoints.Select(s => s.Rendered)) | ||
{ | ||
list.Add(s.WrapWithChar("\"")); | ||
} | ||
|
||
Mountpoints = list.ToArray(); | ||
} | ||
|
||
public string[] Mountpoints { get; } | ||
|
||
public override string ToString() | ||
{ | ||
return $"VOLUME [\"{string.Join(",", Mountpoints)}\"]"; | ||
} | ||
} | ||
} |