Skip to content

Commit

Permalink
Fix v2 branch building (#5969)
Browse files Browse the repository at this point in the history
## Summary of changes

The `release/2.x` branch is broken since I updated the VMs

## Reason for change

I updated VMs yesterday, which cleared the build cache. I knew that
would slow down release/2.x builds but I forgot it would completely
break them due to the centos7 mess.

## Implementation details

Backported some PRs to fix the layer caching etc

- #5770
- #5905
- #5933 (just the changes
in the alpine dockerfile)

## Test coverage

This is the test, hopefully it works 🤞
  • Loading branch information
andrewlock authored Aug 30, 2024
1 parent 58ba195 commit f071cf0
Show file tree
Hide file tree
Showing 17 changed files with 3,616 additions and 119 deletions.
20 changes: 15 additions & 5 deletions .azure-pipelines/steps/install-dotnet-sdk-manually.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ steps:
$channel = "${{ parameters.channel }}"
$sdkVersion = "${{ parameters.sdkVersion }}"
echo "Downloading dotnet-install.ps1"
Invoke-WebRequest -Uri "https://dot.net/v1/dotnet-install.ps1" -OutFile dotnet-install.ps1
$dotnetInstall = "$(System.DefaultWorkingDirectory)\tracer\build\_build\bootstrap\dotnet-install.ps1"
if (Test-Path $dotnetInstall -PathType Leaf) {
echo "Found dotnet-install.ps1 at '$dotnetInstall', skipping download"
} else {
echo "Downloading dotnet-install.ps1"
Invoke-WebRequest -Uri "https://dot.net/v1/dotnet-install.ps1" -OutFile dotnet-install.ps1
$dotnetInstall = ./dotnet-install.ps1
}
if( "${{ parameters.is64bit }}" -eq "true") {
$path = "$HOME\AppData\Local\Microsoft\dotnet"
Expand All @@ -39,12 +45,16 @@ steps:
echo "Installing dotnet ($arch) to $path"
if($sdkVersion) {
./dotnet-install.ps1 -Version $sdkVersion -Architecture $arch -NoPath:$True -InstallDir $path
& $dotnetInstall -Version $sdkVersion -Architecture $arch -NoPath:$True -InstallDir $path
} else {
./dotnet-install.ps1 -Channel $channel -Architecture $arch -NoPath:$True -InstallDir $path
& $dotnetInstall -Channel $channel -Architecture $arch -NoPath:$True -InstallDir $path
}
if (Test-Path ./dotnet-install.ps1 -PathType Leaf) {
echo "Removing temporary dotnet-install file"
rm ./dotnet-install.ps1
}
rm ./dotnet-install.ps1
echo "Install complete"
displayName: Install dotnet core sdk ${{ parameters.sdkVersion }} (64bit:${{ parameters.is64bit }} ${{ parameters.sdkVersion }})
retryCountOnTaskFailure: 5
1 change: 1 addition & 0 deletions Datadog.Trace.Minimal.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"solution": {
"path": "Datadog.Trace.sln",
"projects": [
"tracer\\build\\_build\\_build.csproj",
"tracer\\src\\Datadog.Trace.ClrProfiler.Managed.Loader\\Datadog.Trace.ClrProfiler.Managed.Loader.csproj",
"tracer\\src\\Datadog.Tracer.Native\\Datadog.Tracer.Native.DLL.vcxproj",
"tracer\\src\\Datadog.Tracer.Native\\Datadog.Tracer.Native.vcxproj",
Expand Down
161 changes: 107 additions & 54 deletions tracer/build/_build/Build.Steps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ partial class Build

[LazyPathExecutable(name: "cmake")] readonly Lazy<Tool> CMake;
[LazyPathExecutable(name: "make")] readonly Lazy<Tool> Make;
[LazyPathExecutable(name: "fpm")] readonly Lazy<Tool> Fpm;
[LazyPathExecutable(name: "gzip")] readonly Lazy<Tool> GZip;
[LazyPathExecutable(name: "tar")] readonly Lazy<Tool> Tar;
[LazyPathExecutable(name: "nfpm")] readonly Lazy<Tool> Nfpm;
[LazyPathExecutable(name: "cmd")] readonly Lazy<Tool> Cmd;
[LazyPathExecutable(name: "chmod")] readonly Lazy<Tool> Chmod;
[LazyPathExecutable(name: "objcopy")] readonly Lazy<Tool> ExtractDebugInfo;
Expand Down Expand Up @@ -843,75 +843,128 @@ async Task DownloadWafVersion(string libddwafVersion = null, string uncompressFo
.Requires(() => Version)
.Executes(() =>
{
var fpm = Fpm.Value;
var gzip = GZip.Value;
var tar = Tar.Value;
var nfpm = Nfpm.Value;
var (arch, ext) = GetUnixArchitectureAndExtension();
var workingDirectory = ArtifactsDirectory / $"linux-{UnixArchitectureIdentifier}";
EnsureCleanDirectory(workingDirectory);
const string packageName = "datadog-dotnet-apm";
// debian does not have a specific field for the license, instead you pack the license file in a specific location
// (See https://github.com/goreleaser/nfpm/issues/847 for discussion)
var debLicesnse =
$"""
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Source: https://github.com/DataDog/dd-trace-dotnet
Upstream-Name: {packageName}
Files:
*
Copyright: 2017 Datadog, Inc <[email protected]>
License: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
.
http://www.apache.org/licenses/LICENSE-2.0
.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Comment:
On Debian-based systems the full text of the Apache version 2.0 license can be
found in `/usr/share/common-licenses/Apache-2.0'.
""";
var debLicensePath = TempDirectory / "deb-license";
File.WriteAllText(debLicensePath, debLicesnse);
foreach (var packageType in LinuxPackageTypes)
{
Logger.Information("Creating '{PackageType}' package", packageType);
var assetsDirectory = TemporaryDirectory / arch / packageType;
var includeMuslArtifacts = packageType == "tar" && !IsAlpine && !IsArm64;
var isTar = packageType == "tar";
var muslArch = GetUnixArchitectureAndExtension(isOsx: false, isAlpine: true).Arch;
// On x64, for tar only, we package the linux-musl-x64 target as well, to simplify onboarding
PrepareMonitoringHomeLinuxForPackaging(assetsDirectory, arch, ext, muslArch, includeMuslArtifacts);
var args = new List<string>()
{
"-f",
"-s dir",
$"-t {packageType}",
$"-n {packageName}",
$"-v {Version}",
packageType == "tar" ? "" : "--prefix /opt/datadog",
$"--chdir {assetsDirectory}",
$"--after-install {BuildDirectory / "artifacts" / FileNames.AfterInstallScript}",
$"--after-remove {BuildDirectory / "artifacts" / FileNames.AfterRemoveScript}",
"--license \"Apache License 2.0\"",
"--description \"Datadog APM client library for .NET\"",
"--url \"https://github.com/DataDog/dd-trace-dotnet\"",
"--vendor \"Datadog <[email protected]>\"",
"--maintainer \"Datadog Packages <[email protected]>\"",
"createLogPath.sh",
"dd-dotnet.sh",
"netstandard2.0/",
"netcoreapp3.1/",
"net6.0/",
"Datadog.Trace.ClrProfiler.Native.so",
"libddwaf.so",
"continuousprofiler/",
"loader.conf",
$"{arch}/",
};
// on x64, we also include the musl assets in the glibc package
if (includeMuslArtifacts)
if (isTar)
{
args.Add("linux-musl-x64/");
}
var includeMuslArtifacts = !IsAlpine && !IsArm64;
var arguments = string.Join(" ", args);
fpm(arguments, workingDirectory: workingDirectory);
}
// On x64, for tar only, we package the linux-musl-x64 target as well, to simplify onboarding
PrepareMonitoringHomeLinuxForPackaging(assetsDirectory, arch, ext, muslArch, includeMuslArtifacts);
gzip($"-f {packageName}.tar", workingDirectory: workingDirectory);
// technically we don't need these scripts, but we've been including them in the tar, so keep doing that
var scriptsDir = assetsDirectory / ".scripts";
EnsureExistingDirectory(scriptsDir);
CopyFile(BuildDirectory / "artifacts" / FileNames.AfterInstallScript, scriptsDir / "after_install");
CopyFile(BuildDirectory / "artifacts" / FileNames.AfterRemoveScript, scriptsDir / "after_remove");
var suffix = RuntimeInformation.ProcessArchitecture == Architecture.X64
? string.Empty
: $".{RuntimeInformation.ProcessArchitecture.ToString().ToLower()}";
var tarOutputPath = (IsAlpine, RuntimeInformation.ProcessArchitecture) switch
{
(true, Architecture.X64) => workingDirectory / $"{packageName}-{Version}-musl.tar.gz",
(true, var a) => workingDirectory / $"{packageName}-{Version}-musl.{a.ToString().ToLower()}.tar.gz",
(false, Architecture.X64) => workingDirectory / $"{packageName}-{Version}.tar.gz",
(false, var a) => workingDirectory / $"{packageName}-{Version}.{a.ToString().ToLower()}.tar.gz",
};
var versionedName = IsAlpine
? $"{packageName}-{Version}-musl{suffix}.tar.gz"
: $"{packageName}-{Version}{suffix}.tar.gz";
tar($"-czvf {tarOutputPath} .", workingDirectory: assetsDirectory);
}
else
{
PrepareMonitoringHomeLinuxForPackaging(assetsDirectory, arch, ext, muslArch, includeMuslArtifacts: false);
var nFpmArch = RuntimeInformation.ProcessArchitecture switch
{
Architecture.X64 => "amd64",
Architecture.Arm64 => "arm64",
_ => throw new NotSupportedException($"Unsupported architecture: {RuntimeInformation.ProcessArchitecture}")
};
RenameFile(
workingDirectory / $"{packageName}.tar.gz",
workingDirectory / versionedName);
// language=yaml
var yaml =
$"""
name: "{packageName}"
arch: "{nFpmArch}"
platform: "linux"
version: "{Version}"
maintainer: "Datadog Packages <[email protected]>"
description: "Datadog APM client library for .NET"
vendor: "Datadog <[email protected]>"
homepage: "https://github.com/DataDog/dd-trace-dotnet"
# We were previously using "Apache License 2.0" but that's not technically correct
# As needs to be one of the standard fedora licences here: https://docs.fedoraproject.org/en-US/legal/allowed-licenses/
# and is not used directly by the deb package format: https://www.debian.org/doc/debian-policy/ch-docs.html
license: "Apache-2.0"
priority: extra
section: default
scripts:
postinstall: {BuildDirectory / "artifacts" / FileNames.AfterInstallScript}
postremove: {BuildDirectory / "artifacts" / FileNames.AfterRemoveScript}
rpm:
# The package group. This option is deprecated by most distros
# but we added it with fpm, so keeping it here for consistency
group: default
prefixes:
- /opt/datadog
contents:
- src: {assetsDirectory}/
dst: /opt/datadog
type: tree
- src: {debLicensePath}
dst: /usr/share/doc/{packageName}/copyright
packager: deb
file_info:
mode: 0644
""";
var npfmConfig = TempDirectory / "nfpm.yaml";
// overwrites if it exists
File.WriteAllText(npfmConfig, yaml);
nfpm($"package -f {npfmConfig} -p {packageType}", workingDirectory: workingDirectory);
}
}
return;
Expand Down Expand Up @@ -954,7 +1007,7 @@ void PrepareMonitoringHomeLinuxForPackaging(AbsolutePath assetsDirectory, string
HardLinkUtil.Value($"-v {archSpecificFile} {linkLocation}");
// Need to copy in the loader.conf file into the musl arch folder
if(includeMuslArtifacts)
if (includeMuslArtifacts)
{
// The files are identical in the glibc and musl folders, as they point to
// relative files, so we can just hardlink them
Expand Down
Loading

0 comments on commit f071cf0

Please sign in to comment.