Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 3419a87

Browse files
William Liwilliaml33
authored andcommitted
Produce RPM packages
Reference from https://github.com/dotnet/core-setup/tree/master/src/pkg/packaging/rpm The goal is to have parity with Debian, but does not publish to the feed When run the script with rhel, it will produce rpm file in the package step and publish rpm to the blob storage
1 parent cda914a commit 3419a87

File tree

14 files changed

+682
-1
lines changed

14 files changed

+682
-1
lines changed

Microsoft.DotNet.Cli.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "package", "package", "{FD7D
6868
build\package\Installer.DEB.targets = build\package\Installer.DEB.targets
6969
build\package\Installer.MSI.targets = build\package\Installer.MSI.targets
7070
build\package\Installer.PKG.targets = build\package\Installer.PKG.targets
71+
build\package\Installer.RPM.props = build\package\Installer.RPM.props
72+
build\package\Installer.RPM.targets = build\package\Installer.RPM.targets
7173
build\package\Layout.targets = build\package\Layout.targets
7274
build\package\Nupkg.targets = build\package\Nupkg.targets
7375
EndProjectSection

build/FileExtensions.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
<Project>
22
<PropertyGroup>
33

4+
<IsRPMBasedDistro Condition=" $(HostRid.StartsWith('rhel')) ">True</IsRPMBasedDistro>
5+
46
<ArchiveExtension Condition=" '$(HostOSName)' == 'win' ">.zip</ArchiveExtension>
57
<ArchiveExtension Condition=" '$(HostOSName)' != 'win' ">.tar.gz</ArchiveExtension>
68

79
<InstallerExtension Condition=" '$(HostOSName)' == 'win' ">.msi</InstallerExtension>
810
<InstallerExtension Condition=" '$(HostOSName)' == 'osx' ">.pkg</InstallerExtension>
911
<InstallerExtension Condition=" '$(HostOSName)' == 'ubuntu' OR '$(OSName)' == 'debian' ">.deb</InstallerExtension>
12+
<InstallerExtension Condition=" '$(IsRPMBasedDistro)' == True ">.rpm</InstallerExtension>
1013

1114
<BundleExtension Condition=" '$(HostOSName)' == 'win' ">.exe</BundleExtension>
1215
<BundleExtension Condition=" '$(HostOSName)' == 'osx' ">$(InstallerExtension)</BundleExtension>
1316
<BundleExtension Condition=" '$(HostOSName)' == 'ubuntu' OR '$(OSName)' == 'debian' ">$(InstallerExtension)</BundleExtension>
17+
<BundleExtension Condition=" '$(IsRPMBasedDistro)' == True ">.rpm</BundleExtension>
1418

1519
<DynamicLibPrefix>lib</DynamicLibPrefix>
1620
<DynamicLibPrefix Condition=" '$(HostOSName)' == 'win' "></DynamicLibPrefix>

build/Package.targets

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
<Import Project="$(MSBuildThisFileDirectory)/package/Installer.DEB.proj" />
77
<Import Project="$(MSBuildThisFileDirectory)/package/Installer.MSI.targets" />
88
<Import Project="$(MSBuildThisFileDirectory)/package/Installer.PKG.targets" />
9+
<Import Project="$(MSBuildThisFileDirectory)/package/Installer.RPM.targets" />
910

1011
<Target Name="GenerateInstallers"
1112
Condition=" '$(SkipBuildingInstallers)' != 'true' "
12-
DependsOnTargets="Init;Layout;GeneratePkgs;GenerateDebs;GenerateMsis" />
13+
DependsOnTargets="Init;Layout;GeneratePkgs;GenerateDebs;GenerateMsis;GenerateRpms" />
1314

1415
<Target Name="Package"
1516
DependsOnTargets="BuildDotnetCliBuildFramework;

build/package/Installer.RPM.props

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<RpmConfigJsonName>rpm_config.json</RpmConfigJsonName>
5+
<TemplatesDir>$(RepoRoot)/packaging/rpm/templates</TemplatesDir>
6+
<ScriptsDir>$(RepoRoot)/packaging/rpm/scripts</ScriptsDir>
7+
</PropertyGroup>
8+
</Project>
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project='Installer.RPM.props'/>
4+
5+
<UsingTask TaskName="ReplaceFileContents" AssemblyFile="$(CLIBuildDll)"/>
6+
<UsingTask TaskName="BuildFPMToolPreReqs" AssemblyFile="$(CLIBuildDll)"/>
7+
8+
<PropertyGroup>
9+
<BuildRpmPackage Condition=" '$(IsRPMBasedDistro)' == 'True' ">True</BuildRpmPackage>
10+
</PropertyGroup>
11+
12+
<Target Name="GenerateRpms"
13+
DependsOnTargets="TestFPMTool;BuildRpms;TestSdkRpm"
14+
Condition=" '$(BuildRpmPackage)' == 'True' "
15+
Outputs="@(GeneratedInstallers)"/>
16+
17+
<Target Name="BuildRpms"
18+
DependsOnTargets="GenerateSdkRpm"
19+
Condition=" '$(BuildRpmPackage)' == 'True' and '$(FPMPresent)' == 'True' "/>
20+
21+
<Target Name="GenerateSdkRpm">
22+
<PropertyGroup>
23+
<RpmPackageVersion>$(SdkVersion)</RpmPackageVersion>
24+
<InputRoot>$(OutputDirectory)/sdk</InputRoot>
25+
<SdkInstallerFile>$(InstallerOutputDirectory)/$(DistroSpecificArtifactNameWithVersionCombinedHostHostFxrFrameworkSdk)$(InstallerExtension)</SdkInstallerFile>
26+
<RpmFile>$(SdkInstallerFile)</RpmFile>
27+
<ManPagesDir>$(RepoRoot)/Documentation/manpages</ManPagesDir>
28+
<ConfigJsonFile>$(RepoRoot)/packaging/rpm/dotnet-config.json</ConfigJsonFile>
29+
<RpmIntermediatesDir>$(IntermediateDirectory)/$(RpmPackageName)/$(RpmPackageVersion)</RpmIntermediatesDir>
30+
<RpmTestResultsXmlFile>$(RpmIntermediatesDir)/debian-testResults.xml</RpmTestResultsXmlFile>
31+
<RpmInstalledDirectory>/usr/share/dotnet</RpmInstalledDirectory>
32+
</PropertyGroup>
33+
34+
<PropertyGroup>
35+
<RpmLayoutDirectory>$(RpmIntermediatesDir)/RpmLayoutDirectory/</RpmLayoutDirectory>
36+
<RpmLayoutPackageRoot>$(RpmLayoutDirectory)package_root</RpmLayoutPackageRoot>
37+
<RpmLayoutSDK>$(RpmLayoutPackageRoot)/sdk</RpmLayoutSDK>
38+
<RpmLayoutDocs>$(RpmLayoutDirectory)docs</RpmLayoutDocs> <!-- Man Pages -->
39+
<RpmLayoutTemplates>$(RpmLayoutDirectory)templates</RpmLayoutTemplates> <!-- Copyright, Changelog -->
40+
<RpmLayoutScripts>$(RpmLayoutDirectory)scripts</RpmLayoutScripts>
41+
</PropertyGroup>
42+
43+
<PropertyGroup>
44+
<SdkRpmPackageVersion>$(SdkVersion)</SdkRpmPackageVersion>
45+
<SdkRpmPackageName>$(ArtifactNameCombinedHostHostFxrFrameworkSdk)-$(SdkRpmPackageVersion)</SdkRpmPackageName>
46+
<SharedFxRpmPackageVersion>$(SharedFrameworkVersion)</SharedFxRpmPackageVersion>
47+
<SharedFxRpmPackageName>dotnet-runtime-$(SharedFxRpmPackageVersion)</SharedFxRpmPackageName>
48+
<SharedFxRpmPackageName>$(SharedFxRpmPackageName.ToLower())</SharedFxRpmPackageName>
49+
<HostFxrRpmPackageVersion>$(HostFxrVersion)</HostFxrRpmPackageVersion>
50+
<HostFxrRpmPackageName>dotnet-hostfxr-$(HostFxrRpmPackageVersion)</HostFxrRpmPackageName>
51+
<HostFxrRpmPackageName>$(HostFxrRpmPackageName.ToLower())</HostFxrRpmPackageName>
52+
<HostRpmPackageName>dotnet-host</HostRpmPackageName>
53+
</PropertyGroup>
54+
55+
<PropertyGroup>
56+
<EndToEndTestProject>$(RepoRoot)/test/EndToEnd/EndToEnd.csproj</EndToEndTestProject>
57+
</PropertyGroup>
58+
59+
<RemoveDir Condition="Exists('$(RpmIntermediatesDir)')" Directories="$(RpmIntermediatesDir)"/>
60+
<MakeDir Directories="$(RpmIntermediatesDir)"/>
61+
62+
<!-- Create empty rpm layout -->
63+
<RemoveDir Condition="Exists('$(RpmLayoutDirectory)')" Directories="$(RpmLayoutDirectory)"/>
64+
<MakeDir Directories="$(RpmLayoutDirectory)"/>
65+
<MakeDir Directories="$(RpmLayoutPackageRoot)"/>
66+
<MakeDir Directories="$(RpmLayoutSDK)"/>
67+
<MakeDir Directories="$(RpmLayoutDocs)"/>
68+
<MakeDir Directories="$(RpmLayoutTemplates)"/>
69+
<MakeDir Directories="$(RpmLayoutScripts)"/>
70+
71+
<!-- Copy files to rpm layout -->
72+
<ItemGroup>
73+
<SDKFiles Include="$(InputRoot)/**/*"/>
74+
<SDKManpages Include="$(ManPagesDir)/**/*"/>
75+
<SDKTemplatesFiles Include="$(TemplatesDir)/**/*"/>
76+
<SDKScriptsFiles Include="$(ScriptsDir)/**/*"/>
77+
<AspNetRuntimeFilesInput Include="$(AspNetRuntimePackageStorePublishDirectory)/**/*" />
78+
</ItemGroup>
79+
80+
<Copy SourceFiles="@(SDKFiles)"
81+
DestinationFiles="@(SDKFiles->'$(RpmLayoutSDK)/%(RecursiveDir)%(Filename)%(Extension)')"
82+
OverwriteReadOnlyFiles="True"
83+
SkipUnchangedFiles="False"
84+
UseHardlinksIfPossible="False"/>
85+
86+
<Copy SourceFiles="@(SDKManpages)"
87+
DestinationFiles="@(SDKManpages->'$(RpmLayoutDocs)/%(RecursiveDir)%(Filename)%(Extension)')"
88+
OverwriteReadOnlyFiles="True"
89+
SkipUnchangedFiles="False"
90+
UseHardlinksIfPossible="False"/>
91+
92+
<Copy SourceFiles="@(SDKTemplatesFiles)"
93+
DestinationFiles="@(SDKTemplatesFiles->'$(RpmLayoutTemplates)/%(RecursiveDir)%(Filename)%(Extension)')"
94+
OverwriteReadOnlyFiles="True"
95+
SkipUnchangedFiles="False"
96+
UseHardlinksIfPossible="False"/>
97+
98+
<Copy SourceFiles="@(SDKScriptsFiles)"
99+
DestinationFiles="@(SDKScriptsFiles->'$(RpmLayoutScripts)/%(RecursiveDir)%(Filename)%(Extension)')"
100+
OverwriteReadOnlyFiles="True"
101+
SkipUnchangedFiles="False"
102+
UseHardlinksIfPossible="False"/>
103+
104+
<Copy SourceFiles="@(AspNetRuntimeFilesInput)"
105+
DestinationFiles="@(AspNetRuntimeFilesInput ->'$(RpmLayoutPackageRoot)/%(RecursiveDir)%(Filename)%(Extension)')"
106+
OverwriteReadOnlyFiles="True"
107+
SkipUnchangedFiles="False"
108+
UseHardlinksIfPossible="False"/>
109+
110+
<!-- Replace config json variables -->
111+
<ItemGroup>
112+
<SDKTokenValue Include="%SHARED_HOST_RPM_VERSION%">
113+
<ReplacementString>$(SharedFrameworkVersion)</ReplacementString>
114+
</SDKTokenValue>
115+
<SDKTokenValue Include="%SHARED_HOST_RPM_NAME%">
116+
<ReplacementString>$(SharedFxRpmPackageName)</ReplacementString>
117+
</SDKTokenValue>
118+
<SDKTokenValue Include="%SDK_NUGET_VERSION%">
119+
<ReplacementString>$(SdkVersion)</ReplacementString>
120+
</SDKTokenValue>
121+
<SDKTokenValue Include="%CLI_SDK_BRAND_NAME%">
122+
<ReplacementString>$(SdkBrandName)</ReplacementString>
123+
</SDKTokenValue>
124+
<SDKTokenValue Include="%SDK_RPM_PACKAGE_NAME%">
125+
<ReplacementString>$(SdkRpmPackageName)</ReplacementString>
126+
</SDKTokenValue>
127+
</ItemGroup>
128+
129+
<ItemGroup>
130+
<TestSdkRpmTaskEnvironmentVariables Include="PATH=$(RpmInstalledDirectory)$(PathListSeparator)$(PATH)" />
131+
<GeneratedInstallers Include="$(SdkInstallerFile)" />
132+
</ItemGroup>
133+
134+
<ReplaceFileContents InputFile="$(ConfigJsonFile)"
135+
DestinationFile="$(RpmLayoutDirectory)$(RpmConfigJsonName)"
136+
ReplacementItems="@(SDKTokenValue)"/>
137+
138+
<!-- Call the task to build the pre-reqs (parameters, copyright, changelog) for calling the FPM tool -->
139+
<BuildFPMToolPreReqs InputDir="$(RpmLayoutDirectory)"
140+
OutputDir="$(RpmIntermediatesDir)"
141+
PackageVersion="$(RpmPackageVersion)"
142+
ConfigJsonFile="$(RpmLayoutDirectory)$(RpmConfigJsonName)">
143+
<Output TaskParameter="FPMParameters" PropertyName="FPMCmdParameters"/>
144+
</BuildFPMToolPreReqs>
145+
146+
<!-- Build the RPM package by calling the FPM tool and passing the parameter list -->
147+
<Exec Command="fpm $(FPMCmdParameters)" WorkingDirectory="$(RpmIntermediatesDir)"/>
148+
149+
<!-- Copy package to output -->
150+
<ItemGroup>
151+
<GeneratedRpmFiles Remove="@(GeneratedRpmFiles)"/>
152+
<GeneratedRpmFiles Include="$(RpmIntermediatesDir)/*.rpm"/>
153+
</ItemGroup>
154+
155+
<Error Text="@(GeneratedRpmFiles->Count()) .rpm files generated." Condition="'@(GeneratedRpmFiles->Count())' != 1"/>
156+
157+
<Copy SourceFiles="@(GeneratedRpmFiles)"
158+
DestinationFiles="$(RpmFile)"
159+
OverwriteReadOnlyFiles="True"
160+
SkipUnchangedFiles="False"
161+
UseHardlinksIfPossible="False"/>
162+
163+
</Target>
164+
165+
<Target Name="TestFPMTool">
166+
167+
<!-- run FPM -->
168+
<Exec Command="fpm --help > /dev/null" ContinueOnError="True">
169+
<Output TaskParameter="ExitCode" PropertyName="FPMExitCode"/>
170+
</Exec>
171+
172+
<!-- Check if it returned 0 -->
173+
<PropertyGroup>
174+
<FPMPresent>false</FPMPresent>
175+
<FPMPresent Condition=" '$(FPMExitCode)' == '0' ">True</FPMPresent>
176+
</PropertyGroup>
177+
178+
<!-- Workaround for Jenkins machines that don't have the necessary packages https://github.com/dotnet/core-setup/issues/2260 -->
179+
<Message Condition=" '$(FPMPresent)' != 'True' "
180+
Text="FPM tool Not found, RPM packages will not be built."
181+
Importance="High"/>
182+
</Target>
183+
184+
<Target Name="TestSdkRpm"
185+
Condition=" '$(IsRPMBasedDistro)' == 'True' and '$(FPMPresent)' == 'True' "
186+
Inputs="$(DownloadedSharedHostInstallerFile);
187+
$(DownloadedHostFxrInstallerFile);
188+
$(DownloadedSharedFrameworkInstallerFile);
189+
$(RpmTestResultsXmlFile);"
190+
Outputs="$(RpmTestResultsXmlFile)" >
191+
192+
<!-- Install Dependencies and SDK Packages -->
193+
<Exec Command="sudo yum -y install $(DownloadedSharedHostInstallerFile)" />
194+
<Exec Command="sudo yum -y install $(DownloadedHostFxrInstallerFile)" />
195+
<Exec Command="sudo yum -y install $(DownloadedSharedFrameworkInstallerFile)" />
196+
197+
<Exec Command="sudo yum -y install $(SdkInstallerFile)" />
198+
199+
<!-- Run Tests -->
200+
<DotNetRestore ProjectPath="$(EndToEndTestProject)"
201+
ToolPath="$(RpmInstalledDirectory)" />
202+
203+
<DotNetTest ProjectPath="$(EndToEndTestProject)"
204+
EnvironmentVariables="@(TestSdkDebTaskEnvironmentVariables)"
205+
ToolPath="$(RpmInstalledDirectory)" />
206+
207+
<!-- Clean up Packages -->
208+
<Exec Command="sudo yum remove -y $(SdkRpmPackageName)" />
209+
<Exec Command="sudo yum remove -y $(SharedFxRpmPackageName)" />
210+
<Exec Command="sudo yum remove -y $(HostFxrRpmPackageName)" />
211+
<Exec Command="sudo yum remove -y $(HostRpmPackageName)" />
212+
</Target>
213+
</Project>

0 commit comments

Comments
 (0)