Support local installation for *nix systems too. (#3549)

* Support local installation for *nix systems too.

The powershell installation supports `-LocalPath` allowing users to provide the zip manually which is great for airgapped environments.

The bash installation script did not support something similar. This now allows the archive to passed in through `LOCAL_PATH` or a folder with the prepared
archives `DOWNLOAD_DIR`
This commit is contained in:
Martijn Laarman 2024-07-30 11:47:22 +02:00 committed by GitHub
parent fe82d53ace
commit bcda90aa90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 38 additions and 15 deletions

View File

@ -31,6 +31,8 @@ This component adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h
- `OTEL_EXPORTER_OTLP_LOGS_HEADERS`,
- `OTEL_EXPORTER_OTLP_LOGS_TIMEOUT`,
- `OTEL_EXPORTER_OTLP_LOGS_PROTOCOL`.
- Support for air-gapped installations through `DOWNLOAD_DIR` or `LOCAL_PATH`
arguments to `otel-dotnet-auto-install.sh`.
### Changed

View File

@ -200,16 +200,31 @@ chmod +x $HOME/.otel-dotnet-auto/instrument.sh
OTEL_SERVICE_NAME=myapp OTEL_RESOURCE_ATTRIBUTES=deployment.environment=staging,service.version=1.0.0 ./MyNetApp
```
NOTE: for air-gapped environments you can provide either the installation archive directly with:
```sh
LOCAL_PATH=<PATH_TO_ARCHIVE> sh ./otel-dotnet-auto-install.sh
```
or the folder with the archives, this has the added benefit that the install script will determine
the correct archive to choose.
```sh
DOWNLOAD_DIR=<PATH_TO_FOLDER_WITH_ARCHIVES> sh ./otel-dotnet-auto-install.sh
```
`otel-dotnet-auto-install.sh` script
uses environment variables as parameters:
| Parameter | Description | Required | Default value |
|-------------------------|------------------------------------------------------------------|----------|---------------------------|
| `OTEL_DOTNET_AUTO_HOME` | Location where binaries are to be installed | No | `$HOME/.otel-dotnet-auto` |
| `OS_TYPE` | Possible values: `linux-glibc`, `linux-musl`, `macos`, `windows` | No | *Calculated* |
| `ARCHITECTURE` | Possible values for Linux: `x64`, `arm64` | No | *Calculated* |
| `TMPDIR` | Temporary directory used when downloading the files | No | `$(mktemp -d)` |
| `VERSION` | Version to download | No | `1.6.0` |
| Parameter | Description | Required | Default value |
|-------------------------|---------------------------------------------------------------------------------|----------|-----------------------------|
| `OTEL_DOTNET_AUTO_HOME` | Location where binaries are to be installed | No | `$HOME/.otel-dotnet-auto` |
| `OS_TYPE` | Possible values: `linux-glibc`, `linux-musl`, `macos`, `windows` | No | *Calculated* |
| `ARCHITECTURE` | Possible values for Linux: `x64`, `arm64` | No | *Calculated* |
| `TMPDIR` | (deprecated) prefer `DOWNLOAD_DIR` | No | `$(mktemp -d)` |
| `DOWNLOAD_DIR` | Folder to download the archive to. Will use local archive if it already exists | No | `$TMPDIR` or `$(mktemp -d)` |
| `LOCAL_PATH` | Full path the archive to use for installation. (ideal for air-gapped scenarios) | No | *Calculated* |
| `VERSION` | Version to download | No | `1.6.0` |
[instrument.sh](../instrument.sh) script
uses environment variables as parameters:

View File

@ -47,9 +47,10 @@ case "$ARCHITECTURE" in
esac
test -z "$OTEL_DOTNET_AUTO_HOME" && OTEL_DOTNET_AUTO_HOME="$HOME/.otel-dotnet-auto"
test -z "$TMPDIR" && TMPDIR="$(mktemp -d)"
test -z "$VERSION" && VERSION="v{{VERSION}}"
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"
@ -58,11 +59,16 @@ if echo "$OS_TYPE" | grep -q "linux"; then
ARCHIVE="opentelemetry-dotnet-instrumentation-$OS_TYPE-$ARCHITECTURE.zip"
fi
TMPFILE="$TMPDIR/$ARCHIVE"
(
cd "$TMPDIR"
echo "Downloading $VERSION for $OS_TYPE..."
curl -sSfLo "$TMPFILE" "$RELEASES_URL/download/$VERSION/$ARCHIVE"
)
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 "$TMPFILE" -d "$OTEL_DOTNET_AUTO_HOME"
unzip -q "$LOCAL_PATH" -d "$OTEL_DOTNET_AUTO_HOME"