Skip to content

Commit

Permalink
Distribution packaging continued (#135)
Browse files Browse the repository at this point in the history
Continues #133 

This now puts all required distributions under
`.artifacts/elastic-distribution`.

This includes `elastic-*.zip` versions of the auto instrumentation zips.
These zips include
	* our plugin dll (twice for -windows.zip).
	* `_instrument.sh` a copy of the original `instrument.sh`
	* `instrument.sh` which sets our plugin var and calls `_instrument.sh`

This also includes elastic versions of the installation bash script and
the powershell module to instrument and install/update on windows.

These files should now upload as part of our release and uploaded as
artifacts on each commit in main.

Locally to build the distributables call:

```
./build.sh redistribute
````

To validate the distribution there is now a new dockerfile that
validates our install and instrumentation scripts:

```bash
docker build -t distribution.autoinstrumentation:latest -f examples/Example.AutoInstrumentation/distribution.Dockerfile  . && \
         docker run -it --rm -p 5000:8080 --name distri --platform linux/arm64 distribution.autoinstrumentation:latest
```


The latter will also form the basis for more integration tests which
i'll follow up with
  • Loading branch information
Mpdreamz authored Jul 31, 2024
1 parent f842bb7 commit 28ec302
Show file tree
Hide file tree
Showing 11 changed files with 332 additions and 34 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/bootstrap/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ runs:
restore-keys: |
${{ runner.os }}-nuget
# ensures we don't hit GitHub releases all the time to download the OpenTelemetry auto instrumentation assets
# if not available they will be download in .artifacts/otel-distribution/{otel-version}
- name: Cache OpenTelemetry Distribution
uses: actions/cache@v4
with:
path: .artifacts/otel-distribution
key: otel-distribution

- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ jobs:
- name: Bootstrap Action Workspace
id: bootstrap
uses: ./.github/workflows/bootstrap

- name: Test
run: ./build.sh test --test-suite=skip-e2e

# We still run the full release build on pull-requests this ensures packages are validated ahead of time
- name: Release
run: ./build.sh release --test-suite=skip-e2e
run: ./build.sh release -c
19 changes: 17 additions & 2 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ permissions:
env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
RELEASE_PACKAGES: ".artifacts/package/release/*.nupkg"
RELEASE_DISTRO: ".artifacts/elastic-distribution/*"

jobs:
release:
Expand All @@ -25,14 +26,28 @@ jobs:
id: bootstrap
uses: ./.github/workflows/bootstrap

- run: ./build.sh release --test-suite=skip-e2e
- name: Test
run: ./build.sh test --test-suite=skip-e2e

- run: ./build.sh release -c
name: Release

- uses: actions/upload-artifact@v4
with:
name: elastic-distribution
path: ${{ env.RELEASE_DISTRO }}

- name: Generate build provenance
- name: Generate build provenance (Distribution)
uses: actions/attest-build-provenance@5e9cb68e95676991667494a6a4e59b8a2f13e1d0 # v1.3.3
with:
subject-path: "${{ github.workspace }}/${{ env.RELEASE_DISTRO }}"

- name: Generate build provenance (Packages)
uses: actions/attest-build-provenance@5e9cb68e95676991667494a6a4e59b8a2f13e1d0 # v1.3.3
with:
subject-path: "${{ github.workspace }}/${{ env.RELEASE_PACKAGES }}"


# Push to feedz.io
- name: publish canary packages to feedz.io
run: dotnet nuget push '${{ env.RELEASE_PACKAGES }}' -k ${{ secrets.FEEDZ_IO_API_KEY }} -s ${{ secrets.FEEDZ_IO_API_URL }} --skip-duplicate --no-symbols
Expand Down
16 changes: 14 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ env:
JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
SLACK_CHANNEL: "#apm-agent-dotnet"
RELEASE_PACKAGES: ".artifacts/package/release/*.nupkg"
RELEASE_DISTRO: ".artifacts/elastic-distribution/*"

jobs:
release:
Expand All @@ -31,10 +32,21 @@ jobs:
id: bootstrap
uses: ./.github/workflows/bootstrap

- run: ./build.sh release --test-suite=skip-all
- run: ./build.sh release
name: Release

- name: Generate build provenance
- name: Attach Distribution to release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload ${{ github.ref_name }} "${{ env.RELEASE_DISTRO }}"
- name: Generate build provenance (Distribution)
uses: actions/attest-build-provenance@5e9cb68e95676991667494a6a4e59b8a2f13e1d0 # v1.3.3
with:
subject-path: "${{ github.workspace }}/${{ env.RELASE_DISTRO }}"

- name: Generate build provenance (Packages)
uses: actions/attest-build-provenance@5e9cb68e95676991667494a6a4e59b8a2f13e1d0 # v1.3.3
with:
subject-path: "${{ github.workspace }}/${{ env.RELEASE_PACKAGES }}"
Expand Down
74 changes: 74 additions & 0 deletions build/patch-dotnet-auto-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/sh
set -e

# guess OS_TYPE if not provided
if [ -z "$OS_TYPE" ]; then
case "$(uname -s | tr '[:upper:]' '[:lower:]')" in
cygwin_nt*|mingw*|msys_nt*)
OS_TYPE="windows"
;;
linux*)
if [ "$(ldd /bin/ls | grep -m1 'musl')" ]; then
OS_TYPE="linux-musl"
else
OS_TYPE="linux-glibc"
fi
;;
darwin*)
OS_TYPE="macos"
;;
esac
fi

case "$OS_TYPE" in
"linux-glibc"|"linux-musl"|"macos"|"windows")
;;
*)
echo "Set the operating system type using the OS_TYPE environment variable. Supported values: linux-glibc, linux-musl, macos, windows." >&2
exit 1
;;
esac

# guess OS architecture if not provided
if [ -z "$ARCHITECTURE" ]; then
case $(uname -m) in
x86_64) ARCHITECTURE="x64" ;;
aarch64) ARCHITECTURE="arm64" ;;
esac
fi

case "$ARCHITECTURE" in
"x64"|"arm64")
;;
*)
echo "Set the architecture type using the ARCHITECTURE environment variable. Supported values: x64, arm64." >&2
exit 1
;;
esac

test -z "$OTEL_DOTNET_AUTO_HOME" && OTEL_DOTNET_AUTO_HOME="$HOME/.otel-dotnet-auto"
test -z "$VERSION" && VERSION="v1.7.0"

DOWNLOAD_DIR="${DOWNLOAD_DIR:=${TMPDIR:=$(mktemp -d)}}"

RELEASES_URL="https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/releases"
ARCHIVE="opentelemetry-dotnet-instrumentation-$OS_TYPE.zip"

# In case of Linux, use architecture in the download path
if echo "$OS_TYPE" | grep -q "linux"; then
ARCHIVE="opentelemetry-dotnet-instrumentation-$OS_TYPE-$ARCHITECTURE.zip"
fi

LOCAL_PATH="${LOCAL_PATH:=$DOWNLOAD_DIR/$ARCHIVE}"
if [ ! -f "${LOCAL_PATH}" ]; then
(
cd "$DOWNLOAD_DIR"
echo "Downloading $VERSION for $OS_TYPE ($LOCAL_PATH)..."
curl -sSfLo "$LOCAL_PATH" "$RELEASES_URL/download/$VERSION/$ARCHIVE"
)
else
echo "Using local installation archive: $LOCAL_PATH"
fi

rm -rf "$OTEL_DOTNET_AUTO_HOME"
unzip -q "$LOCAL_PATH" -d "$OTEL_DOTNET_AUTO_HOME"
50 changes: 38 additions & 12 deletions build/scripts/BuildInformation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,47 @@ module BuildInformation
open System
open System.IO
open System.Threading
open System.Xml.Linq
open System.Xml.XPath
open Fake.Core
open Proc.Fs
open Fake.Tools.Git

type Paths =
static member Root =
let mutable dir = DirectoryInfo(".")
while dir.GetFiles("*.sln").Length = 0 do dir <- dir.Parent
Environment.CurrentDirectory <- dir.FullName
dir

static member RelativePathToRoot path = Path.GetRelativePath(Paths.Root.FullName, path)

static member ArtifactFolder = DirectoryInfo(Path.Combine(Paths.Root.FullName, ".artifacts"))
static member ArtifactPath t = DirectoryInfo(Path.Combine(Paths.ArtifactFolder.FullName, t))

static member private SrcFolder = DirectoryInfo(Path.Combine(Paths.Root.FullName, "src"))
static member SrcPath (t: string list) = DirectoryInfo(Path.Combine([Paths.SrcFolder.FullName] @ t |> List.toArray))


type BuildConfiguration =
static member ValidateAssemblyName = false
static member GenerateApiChanges = false
static member OpenTelemetryAutoInstrumentationVersion = SemVer.parse("1.7.0")




type Software =
static member Organization = "elastic"
static member Repository = "elastic-otel-dotnet"
static member GithubMoniker = $"%s{Software.Organization}/%s{Software.Repository}"
static member SignKey = "069ca2728db333c1"

static let queryPackageRef upstreamPackage distroPackage =
let path = Paths.SrcPath [distroPackage; $"{distroPackage}.csproj"]
let project = XDocument.Load(path.FullName)
let packageRef = project.XPathSelectElement($"//PackageReference[@Include = '{upstreamPackage}']")
let upstreamVersion = packageRef.Attribute("Version").Value
SemVer.parse(upstreamVersion)

static let restore =
Lazy<unit>((fun _ -> exec { run "dotnet" "tool" "restore" }), LazyThreadSafetyMode.ExecutionAndPublication)
Expand All @@ -35,20 +62,19 @@ type Software =
}
SemVer.parse <| $"%s{output.Line}+%s{sha}"
, LazyThreadSafetyMode.ExecutionAndPublication)

static member Version = restore.Value; versionInfo.Value

type Paths =
static member private Root =
let mutable dir = DirectoryInfo(".")
while dir.GetFiles("*.sln").Length = 0 do dir <- dir.Parent
Environment.CurrentDirectory <- dir.FullName
dir

static member OpenTelemetryAutoInstrumentationVersion =
let upstreamPackage = "OpenTelemetry.AutoInstrumentation";
let distroPackage = $"Elastic.{upstreamPackage}"
queryPackageRef upstreamPackage distroPackage

static member RelativePathToRoot path = Path.GetRelativePath(Paths.Root.FullName, path)
static member OpenTelemetryVersion =
let upstreamPackage = "OpenTelemetry";
let distroPackage = $"Elastic.{upstreamPackage}"
queryPackageRef upstreamPackage distroPackage

static member ArtifactFolder = DirectoryInfo(Path.Combine(Paths.Root.FullName, ".artifacts"))
static member ArtifactPath t = DirectoryInfo(Path.Combine(Paths.ArtifactFolder.FullName, t))

type OS =
| OSX | Windows | Linux
Expand Down
2 changes: 2 additions & 0 deletions build/scripts/CommandLine.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type TestSuite = All | Unit | Integration | E2E | Skip_All | Skip_E2E
type Build =
| [<CliPrefix(CliPrefix.None);SubCommand>] Clean
| [<CliPrefix(CliPrefix.None);SubCommand>] Version
| [<CliPrefix(CliPrefix.None);Hidden;SubCommand>] Compile
| [<CliPrefix(CliPrefix.None);SubCommand>] Build
| [<CliPrefix(CliPrefix.None);SubCommand>] Test

Expand Down Expand Up @@ -64,6 +65,7 @@ with
| ValidateLicenses
| ValidatePackages
| GenerateReleaseNotes
| Compile
| Redistribute
| GenerateApiChanges -> "Undocumented, dependent target"

Expand Down
Loading

0 comments on commit 28ec302

Please sign in to comment.