Skip to content

Commit f0a50f3

Browse files
authored
fix: Config generation settings and pathes (#115)
The properties are correctly checked during the target now and the default directory is set to the msbuild project directory instead of the solution dir.
1 parent 6438064 commit f0a50f3

File tree

4 files changed

+68
-71
lines changed

4 files changed

+68
-71
lines changed

docs/docs/ms_build.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# MS Build extensions
22

33
This project extends the default build process of dotnet with some
4-
code generation targets before the build.
4+
code generation targets after the build.
55

6-
You'll find those two files here:
6+
You'll find the configurations and targets here:
77

8-
- [KubeOps.props](https://github.com/buehler/dotnet-operator-sdk/blob/master/src/KubeOps/Build/KubeOps.props): defines the build properties
98
- [KubeOps.targets](https://github.com/buehler/dotnet-operator-sdk/blob/master/src/KubeOps/Build/KubeOps.targets): defines the additional build targets
109

10+
An example of such a target is:
11+
12+
[!code-xml[KubeOps.targets](../../src/KubeOps/Build/KubeOps.targets?range=2-17&dedent=4&highlight=2-7)]
13+
1114
They can be configured with the prop settings described below.
1215
The props file just defines the defaults.
1316

@@ -18,9 +21,9 @@ variables that you can add in a `<PropertyGroup>` in your `csproj` file:
1821

1922
| Property | Description | Default Value |
2023
| ---------------------- | -------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
21-
| KubeOpsDockerfilePath | The path of the dockerfile | $(SolutionDir)Dockerfile<br>or<br>$(MSBuildProjectDirectory)\Dockerfile |
24+
| KubeOpsDockerfilePath | The path of the dockerfile | $(MSBuildProjectDirectory)\Dockerfile |
2225
| KubeOpsDockerTag | Which dotnet sdk / run tag should be used | latest |
23-
| KubeOpsConfigRoot | The base directory for generated elements | $(SolutionDir)config<br>or<br>$(MSBuildProjectDirectory)\config |
26+
| KubeOpsConfigRoot | The base directory for generated elements | $(MSBuildProjectDirectory)\config |
2427
| KubeOpsCrdDir | The directory for the generated crds | \$(KubeOpsConfigRoot)\crds |
2528
| KubeOpsCrdFormat | Output format for crds | Yaml |
2629
| KubeOpsCrdUseOldCrds | Use V1Beta version of crd instead of V1<br>(for kubernetes version < 1.16) | false |

src/KubeOps/Build/KubeOps.props

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

src/KubeOps/Build/KubeOps.targets

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,91 @@
11
<Project DefaultTargets="GenerateAfterBuild">
22
<Target Name="GenerateDockerfile">
3-
<Message Text="Generating Dockerfile" Importance="high" />
4-
<Message Text="Dockerfile path: $(KubeOpsDockerfilePath)" Importance="normal" />
3+
<PropertyGroup>
4+
<!-- Configuration for Docker related commands -->
5+
<KubeOpsDockerfilePath Condition="'$(KubeOpsDockerfilePath)' == ''">$(MSBuildProjectDirectory)\Dockerfile</KubeOpsDockerfilePath>
6+
<KubeOpsDockerTag Condition="'$(KubeOpsDockerTag)' == ''">latest</KubeOpsDockerTag>
7+
</PropertyGroup>
8+
9+
<Message Text="Generating Dockerfile" Importance="high"/>
10+
<Message Text="Dockerfile path: $(KubeOpsDockerfilePath)" Importance="normal"/>
511

612
<Message Condition="Exists('$(KubeOpsDockerfilePath)')" Text="Dockerfile already exists. Don't overwrite."
7-
Importance="high" />
13+
Importance="high"/>
814
<Exec Condition="!Exists('$(KubeOpsDockerfilePath)')"
9-
Command="dotnet $(OutputPath)$(TargetFileName) generator docker --out $(KubeOpsDockerfilePath) --dotnet-tag $(KubeOpsDockerTag) --solution-dir $(SolutionDir) --target-file $(TargetFileName) --project-path $(ProjectPath)" />
15+
Command="dotnet $(OutputPath)$(TargetFileName) generator docker --out $(KubeOpsDockerfilePath) --dotnet-tag $(KubeOpsDockerTag) --solution-dir $(SolutionDir) --target-file $(TargetFileName) --project-path $(ProjectPath)"/>
1016
</Target>
1117

1218
<Target Name="GenerateCrds">
13-
<Message Text="Generating CRDs" Importance="high" />
14-
<Message Text="Configuration path: $(KubeOpsCrdDir)" Importance="normal" />
19+
<PropertyGroup>
20+
<!-- Configuration for the crd generation -->
21+
<KubeOpsCrdDir Condition="'$(KubeOpsCrdDir)' == ''">$(KubeOpsConfigRoot)\crds</KubeOpsCrdDir>
22+
<KubeOpsCrdFormat Condition="'$(KubeOpsCrdFormat)' == ''">Yaml</KubeOpsCrdFormat>
23+
<KubeOpsCrdUseOldCrds Condition="'$(KubeOpsCrdUseOldCrds)' == ''">false</KubeOpsCrdUseOldCrds>
24+
</PropertyGroup>
25+
26+
<Message Text="Generating CRDs" Importance="high"/>
27+
<Message Text="Configuration path: $(KubeOpsCrdDir)" Importance="normal"/>
1528

1629
<Exec Condition="'$(KubeOpsCrdUseOldCrds)' == 'false'"
17-
Command="dotnet $(OutputPath)$(TargetFileName) generator crds --out $(KubeOpsCrdDir) --format $(KubeOpsCrdFormat)" />
30+
Command="dotnet $(OutputPath)$(TargetFileName) generator crds --out $(KubeOpsCrdDir) --format $(KubeOpsCrdFormat)"/>
1831
<Exec Condition="'$(KubeOpsCrdUseOldCrds)' == 'true'"
19-
Command="dotnet $(OutputPath)$(TargetFileName) generator crds --out $(KubeOpsCrdDir) --format $(KubeOpsCrdFormat) --use-old-crds" />
32+
Command="dotnet $(OutputPath)$(TargetFileName) generator crds --out $(KubeOpsCrdDir) --format $(KubeOpsCrdFormat) --use-old-crds"/>
2033
</Target>
2134

2235
<Target Name="GenerateRbac">
23-
<Message Text="Generating Rbac roles" Importance="high" />
24-
<Message Text="Configuration path: $(KubeOpsRbacDir)" Importance="normal" />
36+
<PropertyGroup>
37+
<!-- Configuration for the rbac generation -->
38+
<KubeOpsRbacDir Condition="'$(KubeOpsRbacDir)' == ''">$(KubeOpsConfigRoot)\rbac</KubeOpsRbacDir>
39+
<KubeOpsRbacFormat Condition="'$(KubeOpsRbacFormat)' == ''">Yaml</KubeOpsRbacFormat>
40+
</PropertyGroup>
41+
42+
<Message Text="Generating Rbac roles" Importance="high"/>
43+
<Message Text="Configuration path: $(KubeOpsRbacDir)" Importance="normal"/>
2544

2645
<Exec
27-
Command="dotnet $(OutputPath)$(TargetFileName) generator rbac --out $(KubeOpsRbacDir) --format $(KubeOpsRbacFormat)" />
46+
Command="dotnet $(OutputPath)$(TargetFileName) generator rbac --out $(KubeOpsRbacDir) --format $(KubeOpsRbacFormat)"/>
2847
</Target>
2948

3049
<Target Name="GenerateOperator">
31-
<Message Text="Generating Operator yamls" Importance="high" />
32-
<Message Text="Configuration path: $(KubeOpsOperatorDir)" Importance="normal" />
50+
<PropertyGroup>
51+
<!-- Configuration for the operator manifest generation -->
52+
<KubeOpsOperatorDir Condition="'$(KubeOpsOperatorDir)' == ''">$(KubeOpsConfigRoot)\operator</KubeOpsOperatorDir>
53+
<KubeOpsOperatorFormat Condition="'$(KubeOpsOperatorFormat)' == ''">Yaml</KubeOpsOperatorFormat>
54+
</PropertyGroup>
55+
56+
<Message Text="Generating Operator yamls" Importance="high"/>
57+
<Message Text="Configuration path: $(KubeOpsOperatorDir)" Importance="normal"/>
3358

3459
<Exec
35-
Command="dotnet $(OutputPath)$(TargetFileName) generator operator --out $(KubeOpsOperatorDir) --format $(KubeOpsOperatorFormat)" />
60+
Command="dotnet $(OutputPath)$(TargetFileName) generator operator --out $(KubeOpsOperatorDir) --format $(KubeOpsOperatorFormat)"/>
3661
</Target>
3762

3863
<Target Name="GenerateInstaller">
39-
<Message Text="Generating Installer yamls" Importance="high" />
40-
<Message Text="Configuration path: $(KubeOpsInstallerDir)" Importance="normal" />
64+
<PropertyGroup>
65+
<!-- Configuration for the installer manifest generation -->
66+
<KubeOpsInstallerDir Condition="'$(KubeOpsInstallerDir)' == ''">$(KubeOpsConfigRoot)\install</KubeOpsInstallerDir>
67+
<KubeOpsInstallerFormat Condition="'$(KubeOpsInstallerFormat)' == ''">Yaml</KubeOpsInstallerFormat>
68+
</PropertyGroup>
69+
70+
<Message Text="Generating Installer yamls" Importance="high"/>
71+
<Message Text="Configuration path: $(KubeOpsInstallerDir)" Importance="normal"/>
4172

4273
<Message Condition="Exists('$(KubeOpsInstallerDir)')" Text="Installer dir exists, don't overwrite contents."
43-
Importance="high" />
74+
Importance="high"/>
4475
<Exec Condition="!Exists('$(KubeOpsInstallerDir)')"
45-
Command="dotnet $(OutputPath)$(TargetFileName) generator installer --out $(KubeOpsInstallerDir) --format $(KubeOpsInstallerFormat) --crds-dir $(KubeOpsCrdDir) --rbac-dir $(KubeOpsRbacDir) --operator-dir $(KubeOpsOperatorDir)" />
76+
Command="dotnet $(OutputPath)$(TargetFileName) generator installer --out $(KubeOpsInstallerDir) --format $(KubeOpsInstallerFormat) --crds-dir $(KubeOpsCrdDir) --rbac-dir $(KubeOpsRbacDir) --operator-dir $(KubeOpsOperatorDir)"/>
4677
</Target>
4778

4879
<Target Name="GenerateAfterBuild" AfterTargets="Build">
49-
<CallTarget Condition="'$(KubeOpsSkipDockerfile)' == ''" Targets="GenerateDockerfile" />
50-
<CallTarget Condition="'$(KubeOpsSkipCrds)' == ''" Targets="GenerateCrds" />
51-
<CallTarget Condition="'$(KubeOpsSkipRbac)' == ''" Targets="GenerateRbac" />
52-
<CallTarget Condition="'$(KubeOpsSkipOperator)' == ''" Targets="GenerateOperator" />
53-
<CallTarget Condition="'$(KubeOpsSkipInstaller)' == ''" Targets="GenerateInstaller" />
80+
<PropertyGroup>
81+
<!-- Configuration for the pathes where to store the generated yamls and elements -->
82+
<KubeOpsConfigRoot Condition="'$(KubeOpsConfigRoot)' == ''">$(MSBuildProjectDirectory)\config</KubeOpsConfigRoot>
83+
</PropertyGroup>
84+
85+
<CallTarget Condition="'$(KubeOpsSkipDockerfile)' == ''" Targets="GenerateDockerfile"/>
86+
<CallTarget Condition="'$(KubeOpsSkipCrds)' == ''" Targets="GenerateCrds"/>
87+
<CallTarget Condition="'$(KubeOpsSkipRbac)' == ''" Targets="GenerateRbac"/>
88+
<CallTarget Condition="'$(KubeOpsSkipOperator)' == ''" Targets="GenerateOperator"/>
89+
<CallTarget Condition="'$(KubeOpsSkipInstaller)' == ''" Targets="GenerateInstaller"/>
5490
</Target>
55-
</Project>
91+
</Project>

src/KubeOps/KubeOps.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
</ItemGroup>
3737

3838
<ItemGroup>
39-
<Content Include="Build\KubeOps.props">
40-
<PackagePath>build\</PackagePath>
41-
</Content>
4239
<Content Include="Build\KubeOps.targets">
4340
<PackagePath>build\</PackagePath>
4441
</Content>

0 commit comments

Comments
 (0)