Skip to content

Commit d65e551

Browse files
committed
add support Docker
1 parent 5dfdaa5 commit d65e551

File tree

12 files changed

+174
-34
lines changed

12 files changed

+174
-34
lines changed

README-EN.md

+25-7
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ Output:
5858
Type: File
5959
Path: 'E:\SmartSql-Starter'
6060
Parameters:
61-
DocDir: 'E:\SmartSql-Starter\doc'
61+
BuildDir: 'E:\SmartSql-Starter\build'
62+
DockerImage: 'smartsql.starter'
6263

6364
# 构建任务
6465
Build:
@@ -68,23 +69,27 @@ Build:
6869
# Parameters:
6970
# Dirs: '.'
7071

71-
MakeDic-Doc:
72+
MakeBuildDir:
7273
Type: Process
7374
Parameters:
7475
FileName: powershell
75-
Args: mkdir '{{Project.Parameters.DocDir}}'
76+
Args: mkdir '{{Project.Parameters.BuildDir}}'
7677
Copy:
7778
Type: Process
7879
Parameters:
7980
FileName: powershell
80-
Args: cp '{{Project.ConfigPath}}' '{{Project.Parameters.DocDir}}'
81+
Args: cp '{{Project.ConfigPath}}' '{{Project.Parameters.BuildDir}}'
8182

8283
Scaffolding:
8384
Type: MultiTemplate
8485
Output:
8586
Path: '.'
8687
Parameters:
8788
Templates: [{Key: 'Sln.cshtml',Output: {Name: '{{Project.Module}}',Extension: '.sln'}},
89+
{Key: 'Sln-Directory.Build.cshtml',Output: {Name: 'Directory.Build',Extension: '.props'}},
90+
{Key: 'Sln-Version.cshtml',Output: {Path: 'build',Name: 'version',Extension: '.props'}},
91+
{Key: 'Sln-Dockerfile.cshtml',Output: {Name: 'Dockerfile',Extension: ''}},
92+
{Key: 'Sln-DockerIgnore.cshtml',Output: {Name: '.dockerignore',Extension: ''}},
8893
{Key: "Proj-Entity.cshtml",Output: {Path: 'src/{{Project.Module}}.Entity',Name: '{{Project.Module}}.Entity',Extension: '.csproj'}},
8994
{Key: "Proj-Repository.cshtml",Output: {Path: 'src/{{Project.Module}}.Repository',Name: '{{Project.Module}}.Repository',Extension: '.csproj'}},
9095
{Key: "Proj-Service.cshtml",Output: {Path: 'src/{{Project.Module}}.Service',Name: '{{Project.Module}}.Service',Extension: '.csproj'}},
@@ -104,8 +109,7 @@ Build:
104109
{Key: "API/QueryByPageResponse.cshtml",Output: {Path: 'src/{{Project.Module}}.API/Messages',Name: 'QueryByPageResponse',Extension: '.cs'}},
105110
{Key: "API/ResponseMessage.cshtml",Output: {Path: 'src/{{Project.Module}}.API/Messages',Name: 'ResponseMessage',Extension: '.cs'}},
106111
{Key: "SqlMapConfig.cshtml",Output: {Path: 'src/{{Project.Module}}.Repository',Name: 'SmartSqlMapConfig',Extension: '.xml'}},
107-
{Key: "SqlMapConfig.cshtml",Output: {Path: 'src/{{Project.Module}}.Repository',Name: 'SmartSqlMapConfig.Development',Extension: '.xml'}}
108-
]
112+
{Key: "SqlMapConfig.cshtml",Output: {Path: 'src/{{Project.Module}}.Repository',Name: 'SmartSqlMapConfig.Development',Extension: '.xml'}}]
109113

110114
Entity:
111115
Type: Table
@@ -248,6 +252,20 @@ Build:
248252
WorkingDirectory: '{{Project.Output.Path}}'
249253
Args: dotnet restore
250254

255+
# BuildDocker:
256+
# Type: Process
257+
# Parameters:
258+
# FileName: powershell
259+
# WorkingDirectory: '{{Project.Output.Path}}'
260+
# Args: docker build -t {{Project.Parameters.DockerImage}}:v1.0.0 .
261+
262+
# RunDocker:
263+
# Type: Process
264+
# Parameters:
265+
# FileName: powershell
266+
# WorkingDirectory: '{{Project.Output.Path}}'
267+
# Args: docker run --name {{Project.Parameters.DockerImage}} --rm -d -p 8008:80 {{Project.Parameters.DockerImage}}:v1.0.0 .
268+
251269
# Publish:
252270
# Type: Process
253271
# Parameters:
@@ -271,7 +289,7 @@ Build:
271289
# Parameters:
272290
# FileName: C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
273291
# CreateNoWindow: false
274-
# Args: http://localhost:5000/swagger
292+
# Args: http://localhost:8008/swagger
275293
```
276294

277295
### Build file parameter overview

README.md

+25-7
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ Output:
5858
Type: File
5959
Path: 'E:\SmartSql-Starter'
6060
Parameters:
61-
DocDir: 'E:\SmartSql-Starter\doc'
61+
BuildDir: 'E:\SmartSql-Starter\build'
62+
DockerImage: 'smartsql.starter'
6263

6364
# 构建任务
6465
Build:
@@ -68,23 +69,27 @@ Build:
6869
# Parameters:
6970
# Dirs: '.'
7071

71-
MakeDic-Doc:
72+
MakeBuildDir:
7273
Type: Process
7374
Parameters:
7475
FileName: powershell
75-
Args: mkdir '{{Project.Parameters.DocDir}}'
76+
Args: mkdir '{{Project.Parameters.BuildDir}}'
7677
Copy:
7778
Type: Process
7879
Parameters:
7980
FileName: powershell
80-
Args: cp '{{Project.ConfigPath}}' '{{Project.Parameters.DocDir}}'
81+
Args: cp '{{Project.ConfigPath}}' '{{Project.Parameters.BuildDir}}'
8182

8283
Scaffolding:
8384
Type: MultiTemplate
8485
Output:
8586
Path: '.'
8687
Parameters:
8788
Templates: [{Key: 'Sln.cshtml',Output: {Name: '{{Project.Module}}',Extension: '.sln'}},
89+
{Key: 'Sln-Directory.Build.cshtml',Output: {Name: 'Directory.Build',Extension: '.props'}},
90+
{Key: 'Sln-Version.cshtml',Output: {Path: 'build',Name: 'version',Extension: '.props'}},
91+
{Key: 'Sln-Dockerfile.cshtml',Output: {Name: 'Dockerfile',Extension: ''}},
92+
{Key: 'Sln-DockerIgnore.cshtml',Output: {Name: '.dockerignore',Extension: ''}},
8893
{Key: "Proj-Entity.cshtml",Output: {Path: 'src/{{Project.Module}}.Entity',Name: '{{Project.Module}}.Entity',Extension: '.csproj'}},
8994
{Key: "Proj-Repository.cshtml",Output: {Path: 'src/{{Project.Module}}.Repository',Name: '{{Project.Module}}.Repository',Extension: '.csproj'}},
9095
{Key: "Proj-Service.cshtml",Output: {Path: 'src/{{Project.Module}}.Service',Name: '{{Project.Module}}.Service',Extension: '.csproj'}},
@@ -104,8 +109,7 @@ Build:
104109
{Key: "API/QueryByPageResponse.cshtml",Output: {Path: 'src/{{Project.Module}}.API/Messages',Name: 'QueryByPageResponse',Extension: '.cs'}},
105110
{Key: "API/ResponseMessage.cshtml",Output: {Path: 'src/{{Project.Module}}.API/Messages',Name: 'ResponseMessage',Extension: '.cs'}},
106111
{Key: "SqlMapConfig.cshtml",Output: {Path: 'src/{{Project.Module}}.Repository',Name: 'SmartSqlMapConfig',Extension: '.xml'}},
107-
{Key: "SqlMapConfig.cshtml",Output: {Path: 'src/{{Project.Module}}.Repository',Name: 'SmartSqlMapConfig.Development',Extension: '.xml'}}
108-
]
112+
{Key: "SqlMapConfig.cshtml",Output: {Path: 'src/{{Project.Module}}.Repository',Name: 'SmartSqlMapConfig.Development',Extension: '.xml'}}]
109113

110114
Entity:
111115
Type: Table
@@ -248,6 +252,20 @@ Build:
248252
WorkingDirectory: '{{Project.Output.Path}}'
249253
Args: dotnet restore
250254

255+
# BuildDocker:
256+
# Type: Process
257+
# Parameters:
258+
# FileName: powershell
259+
# WorkingDirectory: '{{Project.Output.Path}}'
260+
# Args: docker build -t {{Project.Parameters.DockerImage}}:v1.0.0 .
261+
262+
# RunDocker:
263+
# Type: Process
264+
# Parameters:
265+
# FileName: powershell
266+
# WorkingDirectory: '{{Project.Output.Path}}'
267+
# Args: docker run --name {{Project.Parameters.DockerImage}} --rm -d -p 8008:80 {{Project.Parameters.DockerImage}}:v1.0.0 .
268+
251269
# Publish:
252270
# Type: Process
253271
# Parameters:
@@ -271,7 +289,7 @@ Build:
271289
# Parameters:
272290
# FileName: C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
273291
# CreateNoWindow: false
274-
# Args: http://localhost:5000/swagger
292+
# Args: http://localhost:8008/swagger
275293
```
276294

277295
### 构建文件参数概览

build/version.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<VersionMajor>2</VersionMajor>
44
<VersionMinor>2</VersionMinor>
5-
<VersionPatch>2</VersionPatch>
5+
<VersionPatch>8</VersionPatch>
66
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
77
</PropertyGroup>
88
</Project>

doc/SmartCode.yml

+25-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Output:
1414
Type: File
1515
Path: 'E:\SmartSql-Starter'
1616
Parameters:
17-
DocDir: 'E:\SmartSql-Starter\doc'
17+
BuildDir: 'E:\SmartSql-Starter\build'
18+
DockerImage: 'smartsql.starter'
1819

1920
# 构建任务
2021
Build:
@@ -24,23 +25,27 @@ Build:
2425
# Parameters:
2526
# Dirs: '.'
2627

27-
MakeDic-Doc:
28+
MakeBuildDir:
2829
Type: Process
2930
Parameters:
3031
FileName: powershell
31-
Args: mkdir '{{Project.Parameters.DocDir}}'
32+
Args: mkdir '{{Project.Parameters.BuildDir}}'
3233
Copy:
3334
Type: Process
3435
Parameters:
3536
FileName: powershell
36-
Args: cp '{{Project.ConfigPath}}' '{{Project.Parameters.DocDir}}'
37+
Args: cp '{{Project.ConfigPath}}' '{{Project.Parameters.BuildDir}}'
3738

3839
Scaffolding:
3940
Type: MultiTemplate
4041
Output:
4142
Path: '.'
4243
Parameters:
4344
Templates: [{Key: 'Sln.cshtml',Output: {Name: '{{Project.Module}}',Extension: '.sln'}},
45+
{Key: 'Sln-Directory.Build.cshtml',Output: {Name: 'Directory.Build',Extension: '.props'}},
46+
{Key: 'Sln-Version.cshtml',Output: {Path: 'build',Name: 'version',Extension: '.props'}},
47+
{Key: 'Sln-Dockerfile.cshtml',Output: {Name: 'Dockerfile',Extension: ''}},
48+
{Key: 'Sln-DockerIgnore.cshtml',Output: {Name: '.dockerignore',Extension: ''}},
4449
{Key: "Proj-Entity.cshtml",Output: {Path: 'src/{{Project.Module}}.Entity',Name: '{{Project.Module}}.Entity',Extension: '.csproj'}},
4550
{Key: "Proj-Repository.cshtml",Output: {Path: 'src/{{Project.Module}}.Repository',Name: '{{Project.Module}}.Repository',Extension: '.csproj'}},
4651
{Key: "Proj-Service.cshtml",Output: {Path: 'src/{{Project.Module}}.Service',Name: '{{Project.Module}}.Service',Extension: '.csproj'}},
@@ -60,8 +65,7 @@ Build:
6065
{Key: "API/QueryByPageResponse.cshtml",Output: {Path: 'src/{{Project.Module}}.API/Messages',Name: 'QueryByPageResponse',Extension: '.cs'}},
6166
{Key: "API/ResponseMessage.cshtml",Output: {Path: 'src/{{Project.Module}}.API/Messages',Name: 'ResponseMessage',Extension: '.cs'}},
6267
{Key: "SqlMapConfig.cshtml",Output: {Path: 'src/{{Project.Module}}.Repository',Name: 'SmartSqlMapConfig',Extension: '.xml'}},
63-
{Key: "SqlMapConfig.cshtml",Output: {Path: 'src/{{Project.Module}}.Repository',Name: 'SmartSqlMapConfig.Development',Extension: '.xml'}}
64-
]
68+
{Key: "SqlMapConfig.cshtml",Output: {Path: 'src/{{Project.Module}}.Repository',Name: 'SmartSqlMapConfig.Development',Extension: '.xml'}}]
6569

6670
Entity:
6771
Type: Table
@@ -204,6 +208,20 @@ Build:
204208
WorkingDirectory: '{{Project.Output.Path}}'
205209
Args: dotnet restore
206210

211+
# BuildDocker:
212+
# Type: Process
213+
# Parameters:
214+
# FileName: powershell
215+
# WorkingDirectory: '{{Project.Output.Path}}'
216+
# Args: docker build -t {{Project.Parameters.DockerImage}}:v1.0.0 .
217+
218+
# RunDocker:
219+
# Type: Process
220+
# Parameters:
221+
# FileName: powershell
222+
# WorkingDirectory: '{{Project.Output.Path}}'
223+
# Args: docker run --name {{Project.Parameters.DockerImage}} --rm -d -p 8008:80 {{Project.Parameters.DockerImage}}:v1.0.0 .
224+
207225
# Publish:
208226
# Type: Process
209227
# Parameters:
@@ -227,4 +245,4 @@ Build:
227245
# Parameters:
228246
# FileName: C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
229247
# CreateNoWindow: false
230-
# Args: http://localhost:5000/swagger
248+
# Args: http://localhost:8008/swagger

src/SmartCode.App/BuildTasks/MultiTemplateBuildTask.cs

+15-9
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,37 @@ public async Task Build(BuildContext context)
5151
{
5252
throw new SmartCodeException($"Build:{context.BuildKey},Output can not be null!");
5353
}
54+
55+
Output output = new Output
56+
{
57+
Path = context.Output.Path,
58+
Mode = context.Output.Mode,
59+
Name = context.Output.Name,
60+
Extension = context.Output.Extension
61+
};
5462
if (outputKVs.Value(nameof(Output.Path), out string outputPath))
5563
{
56-
context.Output.Path = outputPath;
64+
output.Path = outputPath;
5765
}
5866
if (outputKVs.Value(nameof(Output.Mode), out CreateMode outputMode))
5967
{
60-
context.Output.Mode = outputMode;
68+
output.Mode = outputMode;
6169
}
62-
if (String.IsNullOrEmpty(context.Output.Path))
70+
if (String.IsNullOrEmpty(output.Path))
6371
{
6472
throw new SmartCodeException($"Build:{context.BuildKey},Template:{templateKey},can not find Output.Path!");
6573
}
6674
if (!outputKVs.Value(nameof(Output.Name), out string outputName))
6775
{
6876
throw new SmartCodeException($"Build:{context.BuildKey},Template:{templateKey},can not find Output.Name!");
6977
}
70-
context.Output.Name = outputName;
78+
output.Name = outputName;
7179

72-
if (!outputKVs.Value(nameof(Output.Extension), out string extension))
80+
if (outputKVs.Value(nameof(Output.Extension), out string extension))
7381
{
74-
throw new SmartCodeException($"Build:{context.BuildKey},Template:{templateKey},can not find Output.Extension!");
82+
output.Extension = extension;
7583
}
76-
context.Output.Extension = extension;
77-
78-
await _pluginManager.Resolve<IOutput>(context.Output.Type).Output(context);
84+
await _pluginManager.Resolve<IOutput>(context.Output.Type).Output(context, output);
7985
}
8086
}
8187
}

src/SmartCode.App/Outputs/FileOutput.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Text;
66
using System.Threading.Tasks;
77
using HandlebarsDotNet;
8+
using SmartCode.Configuration;
89

910
namespace SmartCode.App.Outputs
1011
{
@@ -31,9 +32,12 @@ public void Initialize(IDictionary<string, object> parameters)
3132
Initialized = true;
3233
}
3334

34-
public async Task Output(BuildContext context)
35+
public async Task Output(BuildContext context, Output output = null)
3536
{
36-
var output = context.Output;
37+
if (output == null)
38+
{
39+
output = context.Output;
40+
}
3741
_logger.LogInformation($"------ Mode:{output.Mode},Build:{context.BuildKey} Start! ------");
3842

3943
var outputPath = Handlebars.Compile(output.Path)(context);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@using SmartCode
2+
@model BuildContext
3+
@{
4+
var project = Model.Project;
5+
}
6+
7+
<Project>
8+
<Import Project="build\version.props" />
9+
<PropertyGroup Label="Package">
10+
<Product>@project.Module</Product>
11+
<Copyright>2019 @project.Module, Inc.</Copyright>
12+
<PackageId>$(AssemblyName)</PackageId>
13+
<Authors>@project.Author</Authors>
14+
<Description>
15+
16+
</Description>
17+
</PropertyGroup>
18+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@using SmartCode
2+
@model BuildContext
3+
@{
4+
var project = Model.Project;
5+
}
6+
7+
.vs
8+
.git
9+
doc/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@using SmartCode
2+
@model BuildContext
3+
@{
4+
var project = Model.Project;
5+
var apiProjectName = $"{project.Module}.API";
6+
}
7+
8+
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
9+
WORKDIR /app
10+
EXPOSE 80
11+
EXPOSE 443
12+
13+
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS publish
14+
WORKDIR /src
15+
COPY /src .
16+
RUN dotnet publish "@(apiProjectName)/@(apiProjectName).csproj" -c Release -o /app
17+
18+
FROM base AS final
19+
WORKDIR /app
20+
COPY --from=publish /app .
21+
ENTRYPOINT ["dotnet", "@(apiProjectName).dll"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@using SmartCode
2+
@model BuildContext
3+
@{
4+
var project = Model.Project;
5+
}
6+
7+
<Project>
8+
<PropertyGroup>
9+
<VersionMajor>1</VersionMajor>
10+
<VersionMinor>0</VersionMinor>
11+
<VersionPatch>0</VersionPatch>
12+
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
13+
</PropertyGroup>
14+
</Project>

0 commit comments

Comments
 (0)