Skip to content

Commit 4466449

Browse files
Build project in Docker, new folder structure (#17)
* Build project in Docker, new folder structure * Change 'image' to 'repo-name' * Try to fix CI
1 parent 262ca59 commit 4466449

File tree

21 files changed

+174
-361
lines changed

21 files changed

+174
-361
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: csharp
22
dotnet: 2.0.2
3+
mono: alpha
34
before_install:
45
- mkdir -p .nuget
56
- wget -O .nuget/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ Options:
5959
Azure IoT Edge Module (C#)
6060
Author: Summer Sun
6161
Options:
62-
-t|--target
63-
all
64-
deploy
65-
Default: all
66-
6762
-lx|--linux-x64
6863
bool - Optional
6964
Default: true
@@ -75,19 +70,23 @@ Options:
7570
-s|--skipRestore
7671
bool - Optional
7772
Default: false
73+
74+
-r|--repository
75+
string - Optional
76+
Default: <registry>/<repo-name>
7877
7978
-lang|--language
8079
string - Optional
8180
Default: C#
8281
8382
```
8483

85-
Parameter `-t` means you if want all Azure IoT Edge module files or just a deployment.json file.
86-
8784
Parameter `-lx` means you if want Dockerfile for linux-x64 or not. So does the `-wn` for windows-nano.
8885

8986
Parameter `-s` means if you want to skip the restore of packages referenced in module project.
9087

88+
Parameter `-r` means the Docker repository to host your Azure IoT Edge module.
89+
9190
Now create the Azure IoT Edge module by the template with name:
9291

9392
```

Test/Test.cs

Lines changed: 49 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ public void Dispose()
2828
public class Test : IClassFixture<DotNetFixture>
2929
{
3030
private DotNetFixture fixture;
31-
private const string TargetAll = "all";
32-
private const string TargetDeploy = "deploy";
3331
private const string CSharp = "C#";
3432
private const string FSharp = "F#";
3533
private const string ArchLinux64 = "linux64";
@@ -41,133 +39,86 @@ public Test(DotNetFixture fixture)
4139
}
4240

4341
public static Dictionary<string, List<string>> FlagFilesMapping = new Dictionary<string, List<string>>{
44-
{
45-
TargetAll, new List<string>()
46-
},
47-
{
48-
TargetDeploy, new List<string> {
49-
"deployment.json"
50-
}
51-
},
5242
{
5343
ArchLinux64, new List<string> {
54-
"Docker/linux-x64/Dockerfile",
55-
"Docker/linux-x64/Dockerfile.debug"
44+
"Dockerfile",
45+
"Dockerfile.amd64.debug"
5646
}
5747
},
5848
{
5949
ArchWindowsNano, new List<string> {
60-
"Docker/windows-nano/Dockerfile"
50+
"Dockerfile"
6151
}
6252
}
6353
};
6454

65-
private static string BeforeEach(string lang, string target, bool linux64 = true, bool windowsNano = true, bool skipRestore = false)
55+
private static string BeforeEach(string lang, string repository, bool linux64 = true, bool windowsNano = true, bool skipRestore = false)
6656
{
6757
var scaffoldName = Path.GetRandomFileName().Replace(".", "").ToString();
68-
if(lang == CSharp)
69-
{
70-
FlagFilesMapping[TargetAll] = new List<string> {scaffoldName + ".csproj", "Program.cs", ".gitignore"};
71-
}
72-
if(lang == FSharp)
73-
{
74-
FlagFilesMapping[TargetAll] = new List<string> {scaffoldName + ".fsproj", "Program.fs", ".gitignore"};
75-
}
76-
var command = "new aziotedgemodule -n " + scaffoldName + " -lang " + lang + " -t " + target + " -lx " + linux64 + " -wn " + windowsNano + " -s " + skipRestore;
58+
var command = "new aziotedgemodule -n " + scaffoldName + " -lang " + lang + " -lx " + linux64 + " -wn " + windowsNano + " -s " + skipRestore + " -r " + repository;
7759
Process.Start("dotnet", command).WaitForExit();
7860
return scaffoldName;
7961
}
8062

8163
[Theory]
82-
[InlineData(CSharp, TargetAll, true, true, true)]
83-
[InlineData(CSharp, TargetAll, true, true, false)]
84-
[InlineData(CSharp, TargetAll, true, false, true)]
85-
[InlineData(CSharp, TargetAll, true, false, false)]
86-
[InlineData(CSharp, TargetAll, false, true, true)]
87-
[InlineData(CSharp, TargetAll, false, true, false)]
88-
[InlineData(CSharp, TargetAll, false, false, true)]
89-
[InlineData(CSharp, TargetAll, false, false, false)]
90-
[InlineData(CSharp, TargetDeploy, true, true, true)]
91-
[InlineData(CSharp, TargetDeploy, true, true, false)]
92-
[InlineData(CSharp, TargetDeploy, true, false, true)]
93-
[InlineData(CSharp, TargetDeploy, true, false, false)]
94-
[InlineData(CSharp, TargetDeploy, false, true, true)]
95-
[InlineData(CSharp, TargetDeploy, false, true, false)]
96-
[InlineData(CSharp, TargetDeploy, false, false, true)]
97-
[InlineData(CSharp, TargetDeploy, false, false, false)]
98-
[InlineData(FSharp, TargetAll, true, true, true)]
99-
[InlineData(FSharp, TargetAll, true, true, false)]
100-
[InlineData(FSharp, TargetAll, true, false, true)]
101-
[InlineData(FSharp, TargetAll, true, false, false)]
102-
[InlineData(FSharp, TargetAll, false, true, true)]
103-
[InlineData(FSharp, TargetAll, false, true, false)]
104-
[InlineData(FSharp, TargetAll, false, false, true)]
105-
[InlineData(FSharp, TargetAll, false, false, false)]
106-
[InlineData(FSharp, TargetDeploy, true, true, true)]
107-
[InlineData(FSharp, TargetDeploy, true, true, false)]
108-
[InlineData(FSharp, TargetDeploy, true, false, true)]
109-
[InlineData(FSharp, TargetDeploy, true, false, false)]
110-
[InlineData(FSharp, TargetDeploy, false, true, true)]
111-
[InlineData(FSharp, TargetDeploy, false, true, false)]
112-
[InlineData(FSharp, TargetDeploy, false, false, true)]
113-
[InlineData(FSharp, TargetDeploy, false, false, false)]
114-
public void TestArchitecture(string lang, string target, bool linux64, bool windowsNano, bool skipRestore)
64+
[InlineData(CSharp, true, true, true)]
65+
[InlineData(CSharp, true, true, false)]
66+
[InlineData(CSharp, true, false, true)]
67+
[InlineData(CSharp, true, false, false)]
68+
[InlineData(CSharp, false, true, true)]
69+
[InlineData(CSharp, false, true, false)]
70+
[InlineData(CSharp, false, false, true)]
71+
[InlineData(CSharp, false, false, false)]
72+
[InlineData(FSharp, true, true, true)]
73+
[InlineData(FSharp, true, true, false)]
74+
[InlineData(FSharp, true, false, true)]
75+
[InlineData(FSharp, true, false, false)]
76+
[InlineData(FSharp, false, true, true)]
77+
[InlineData(FSharp, false, true, false)]
78+
[InlineData(FSharp, false, false, true)]
79+
[InlineData(FSharp, false, false, false)]
80+
public void TestArchitecture(string lang, bool linux64, bool windowsNano, bool skipRestore)
11581
{
116-
var scaffoldName = BeforeEach(lang, target, linux64, windowsNano, skipRestore);
117-
var filesToCheck = new List<string>();
118-
if(target == TargetDeploy)
82+
var repository = "test.azurecr.io/test";
83+
var scaffoldName = BeforeEach(lang, repository, linux64, windowsNano, skipRestore);
84+
var filesToCheck = new List<string> { ".gitignore", "module.json" };
85+
86+
if (skipRestore)
11987
{
120-
filesToCheck = FlagFilesMapping[TargetDeploy];
88+
Assert.True(!Directory.Exists(Path.Combine(scaffoldName, "obj")));
12189
}
122-
else if (target == TargetAll)
90+
else
12391
{
124-
if(skipRestore)
125-
{
126-
Assert.True(!Directory.Exists(Path.Combine(scaffoldName, "obj")));
127-
}
128-
else
129-
{
130-
Assert.True(Directory.Exists(Path.Combine(scaffoldName, "obj")));
131-
}
132-
133-
filesToCheck = FlagFilesMapping[TargetDeploy].Union(FlagFilesMapping[TargetAll]).ToList();
134-
135-
if (linux64)
136-
{
137-
filesToCheck.AddRange(FlagFilesMapping[ArchLinux64]);
138-
139-
}
140-
if (windowsNano)
141-
{
142-
filesToCheck.AddRange(FlagFilesMapping[ArchWindowsNano]);
143-
}
92+
Assert.True(Directory.Exists(Path.Combine(scaffoldName, "obj")));
14493
}
14594

146-
foreach (var file in filesToCheck)
95+
if (lang == CSharp)
14796
{
148-
Assert.True(File.Exists(Path.Combine(scaffoldName, file)));
97+
filesToCheck.AddRange(new List<string> { "Program.cs", scaffoldName + ".csproj" });
98+
}
99+
if (lang == FSharp)
100+
{
101+
filesToCheck.AddRange(new List<string> { "Program.fs", scaffoldName + ".fsproj" });
149102
}
150-
Directory.Delete(scaffoldName, true);
151-
}
152103

153-
[Theory]
154-
[InlineData(CSharp)]
155-
[InlineData(FSharp)]
156-
public void TestDeployUnnecessaryFiles(string lang)
157-
{
158-
var scaffoldName = BeforeEach(lang, TargetDeploy);
159-
var filesExistsToCheck = FlagFilesMapping[TargetDeploy];
160-
var filesNonExistsToCheck = FlagFilesMapping[ArchLinux64].Union(FlagFilesMapping[ArchWindowsNano]).Union(FlagFilesMapping[TargetAll]);
104+
if (linux64)
105+
{
106+
filesToCheck.AddRange(FlagFilesMapping[ArchLinux64]);
161107

162-
foreach (var file in filesExistsToCheck)
108+
}
109+
if (windowsNano)
163110
{
164-
Assert.True(File.Exists(Path.Combine(scaffoldName, file)));
111+
filesToCheck.AddRange(FlagFilesMapping[ArchWindowsNano]);
165112
}
166-
foreach (var file in filesNonExistsToCheck)
113+
114+
foreach (var file in filesToCheck)
167115
{
168-
Assert.True(!File.Exists(Path.Combine(scaffoldName, file)));
116+
Assert.True(File.Exists(Path.Combine(scaffoldName, file)));
169117
}
170-
Assert.True(!Directory.Exists(Path.Combine(scaffoldName, "obj")));
118+
119+
string text = File.ReadAllText(Path.Combine(scaffoldName, "module.json"));
120+
Assert.Contains(repository, text);
121+
171122
Directory.Delete(scaffoldName, true);
172123
}
173124
}

content/dotnet-template-azure-iot-edge-module/CSharp/.template.config/template.json

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,6 @@
1919
}
2020
],
2121
"symbols": {
22-
"target": {
23-
"type": "parameter",
24-
"datatype": "choice",
25-
"defaultValue": "all",
26-
"choices": [
27-
{
28-
"choice": "all"
29-
},
30-
{
31-
"choice": "deploy"
32-
}
33-
]
34-
},
3522
"linux-x64": {
3623
"type": "parameter",
3724
"datatype": "bool",
@@ -46,41 +33,40 @@
4633
"type": "parameter",
4734
"datatype": "bool",
4835
"defaultValue": "false"
36+
},
37+
"repository": {
38+
"type": "parameter",
39+
"defaultValue": "<registry>/<repo-name>",
40+
"replaces": "<repository>"
4941
}
5042
},
5143
"sources": [
5244
{
5345
"exclude": [
5446
".template.config/*",
55-
"Docker/**/*",
5647
"bin/**/*",
57-
"obj/**/*"
48+
"obj/**/*",
49+
"Dockerfile*"
5850
],
5951
"modifiers": [
6052
{
61-
"condition": "(windows-nano && target != 'deploy')",
53+
"condition": "(windows-nano || linux-x64)",
6254
"include": [
63-
"Docker/windows-nano/*"
55+
"Dockerfile"
6456
]
6557
},
6658
{
67-
"condition": "(linux-x64 && target != 'deploy')",
59+
"condition": "(linux-x64)",
6860
"include": [
69-
"Docker/linux-x64/*"
70-
]
71-
},
72-
{
73-
"condition": "(target == 'deploy')",
74-
"exclude": [
75-
"*.cs", "*.csproj", ".gitignore"
61+
"Dockerfile.amd64.debug"
7662
]
7763
}
7864
]
7965
}
8066
],
8167
"postActions": [
8268
{
83-
"condition": "(!skipRestore && target != 'deploy')",
69+
"condition": "(!skipRestore)",
8470
"description": "Restore NuGet packages required by this project.",
8571
"manualInstructions": [
8672
{

content/dotnet-template-azure-iot-edge-module/CSharp/Docker/linux-arm32v7/Dockerfile

Lines changed: 0 additions & 9 deletions
This file was deleted.

content/dotnet-template-azure-iot-edge-module/CSharp/Docker/linux-arm32v7/Dockerfile.debug

Lines changed: 0 additions & 15 deletions
This file was deleted.

content/dotnet-template-azure-iot-edge-module/CSharp/Docker/linux-x64/Dockerfile

Lines changed: 0 additions & 9 deletions
This file was deleted.

content/dotnet-template-azure-iot-edge-module/CSharp/Docker/linux-x64/Dockerfile.debug

Lines changed: 0 additions & 15 deletions
This file was deleted.

content/dotnet-template-azure-iot-edge-module/CSharp/Docker/windows-nano/Dockerfile

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM microsoft/dotnet:2.0-sdk AS build-env
2+
WORKDIR /app
3+
4+
COPY *.csproj ./
5+
RUN dotnet restore
6+
7+
COPY . ./
8+
RUN dotnet publish -c Release -o out
9+
10+
FROM microsoft/dotnet:2.0-runtime
11+
WORKDIR /app
12+
COPY --from=build-env /app/out ./
13+
ENTRYPOINT ["dotnet", "SampleModule.dll"]

0 commit comments

Comments
 (0)