-
Notifications
You must be signed in to change notification settings - Fork 8
/
DockerfileTemplate.cs
32 lines (27 loc) · 956 Bytes
/
DockerfileTemplate.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
namespace Brthor.Dockerize
{
public static class DockerfileTemplate
{
public static string Generate(DockerizeConfiguration config, string outputBinaryName)
{
var addUser = config.Username == null
? ""
: $@"RUN groupadd -r {config.Username} && useradd --no-log-init -u 1000 -m -r -g {config.Username} {config.Username}
RUN chown {config.Username}:{config.Username} /projectBinaries
USER {config.Username}:{config.Username}";
var chownOnAdd = config.Username == null
? ""
: $"--chown={config.Username}:{config.Username} ";
var dockerfileContent = $@"
FROM {config.BaseImage}
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1
RUN mkdir /projectBinaries
{addUser}
ADD {chownOnAdd}./publish/ /projectBinaries/
WORKDIR /projectBinaries/
CMD /projectBinaries/{outputBinaryName}
";
return dockerfileContent;
}
}
}