Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ build: go ocb
build-fips: go ocb
@./scripts/build.sh -d "${DISTRIBUTIONS}" -b ${OTELCOL_BUILDER} -f true

generate: generate-sources generate-goreleaser
generate: generate-sources generate-msi generate-goreleaser

generate-msi: go
@./scripts/generate-msi.sh -d "${DISTRIBUTIONS}"

generate-goreleaser: go
@./scripts/generate-goreleaser.sh -d "${DISTRIBUTIONS}" -g ${GO}
Expand Down
111 changes: 111 additions & 0 deletions cmd/msi/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package main

import (
"bytes"
"encoding/json"
"flag"
"fmt"
"log"
"os"
"text/template"
)

type Guids struct {
ProductUpgradeCode string `json:"product_upgrade_code"`
ComponentGuid string `json:"component_guid"`
}

type DistGuids struct {
Standard Guids `json:"standard"`
Fips Guids `json:"fips"`
}

const (
HostDistro = "nrdot-collector-host"
K8sDistro = "nrdot-collector-k8s"
CoreDistro = "nrdot-collector"
templateFilename = "cmd/msi/windows-installer.wxs.tmpl"
)

var (
distFlag = flag.String("d", "", "Collector distributions to build")
fipsFlag = flag.Bool("f", false, "FIPS")
)

func main() {
flag.Parse()

if len(*distFlag) == 0 {
log.Fatal("no distribution to template")
}

// Get GUIDs

// Parse the base template
baseTemplate, err := template.New("base").Delims("<<", ">>").ParseFiles(templateFilename)
if err != nil {
panic(err)
}

guids := getMsiGuids(*distFlag, *fipsFlag)

// Data for the base template
data := map[string]interface{}{
"InstallerName": getInstallerName(*distFlag, *fipsFlag),
"ProductUpgradeCode": guids.ProductUpgradeCode,
"ComponentGUID": guids.ComponentGuid,
}

// Execute the base template to generate a new template
var generatedTemplateContent bytes.Buffer
err = baseTemplate.ExecuteTemplate(&generatedTemplateContent, "base", data)
if err != nil {
panic(err)
}

err = baseTemplate.ExecuteTemplate(os.Stdout, "base", data)
if err != nil {
panic(err)
}
}

func getInstallerName(dist string, fips bool) string {
name := ""
switch dist {
case CoreDistro:
name = "Core"
case HostDistro:
name = "Host"
case K8sDistro:
name = "K8s"
default:
log.Fatal("Unknown Distribution:", dist)
}
if fips {
name += " (FIPS)"
}
return name
}

func getMsiGuids(dist string, fips bool) Guids {
filename := fmt.Sprintf("./distributions/%s/msi-guids.json", *distFlag)
data, err := os.ReadFile(filename)
if err != nil {
panic(err)
}

var distGuids DistGuids
err = json.Unmarshal(data, &distGuids)
if err != nil {
panic(err)
}

if fips {
return distGuids.Fips
} else {
return distGuids.Standard
}
}
99 changes: 99 additions & 0 deletions cmd/msi/windows-installer.wxs.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<< define "base" ->>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product
Name="NRDOT Collector ({{ .Version }}) - << .InstallerName >> distribution"
Id="*"
UpgradeCode="<< .ProductUpgradeCode >>"
Version="{{ .Version }}"
Manufacturer="OpenTelemetry"
Language="1033">

<Package
InstallerVersion="200"
Compressed="yes"
Comments="Windows Installer Package"
InstallScope="perMachine"/>
<Media Id="1" Cabinet="product.cab" EmbedCab="yes"/>
<Icon Id="ProductIcon" SourceFile="opentelemetry.ico"/> <!-- TODO: Add NR Icon? -->
<Property Id="ARPPRODUCTICON" Value="ProductIcon"/>
<Property Id="ARPHELPLINK" Value="https://support.newrelic.com/s/"/>
<Property Id="ARPURLINFOABOUT" Value="https://opentelemetry.io/"/> <!-- TODO: Find the appropriate Info URL-->
<Property Id="ARPNOREPAIR" Value="1"/>
<Property Id="ARPNOMODIFY" Value="1"/>

<MajorUpgrade
DowngradeErrorMessage="A later version of NRDOT is already installed. Setup will now exit."/>

<Feature Id="Feature" Level="1">
<ComponentRef Id="ApplicationComponent"/>
</Feature>

<Property Id="COLLECTOR_SVC_ARGS"/>
<CustomAction
Id="SetCollectorSvcArgs"
Property="COLLECTOR_SVC_ARGS"
Value="--config &quot;[INSTALLDIR]config.yaml&quot;"/>

<Property Id="NEW_RELIC_LICENSE_KEY"/>

<InstallExecuteSequence>
<Custom Action="SetCollectorSvcArgs" Before="InstallFiles">NOT COLLECTOR_SVC_ARGS</Custom>
</InstallExecuteSequence>

<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFiles64Folder">
<Directory Id="INSTALLDIR" Name="{{ .Binary }}">
<!-- TODO: The UpgradeCode in Product is Contribs. We need to generate our own. -->
<Component Id="ApplicationComponent" Guid="<< .ComponentGUID >>">
<!-- Files to include -->
<File
Id="{{ replace .Binary "-" "_"}}.exe"
Name="{{ .Binary }}.exe"
Source="{{ .Binary }}.exe"
KeyPath="yes"/>
<File
Id="config.yaml"
Name="config.yaml"
Source="config.yaml"/>

<Environment
Action="set"
Name="NEW_RELIC_LICENSE_KEY"
Value="[NEW_RELIC_LICENSE_KEY]"
/>

<ServiceInstall
Id="Sevice"
Name="{{ .Binary }}"
DisplayName="NRDOT Collector << .InstallerName >>"
Description="NRDOT << .InstallerName >> Distribution of the OpenTelemetry Collector"
Type="ownProcess"
Vital="yes"
Start="auto"
Account="LocalSystem"
ErrorControl="normal"
Arguments="[COLLECTOR_SVC_ARGS]"
Interactive="no"/>
<ServiceControl
Id="StartStopRemoveService"
Name="{{ .Binary }}"
Start="install"
Stop="both"
Remove="uninstall"
Wait="yes"/>

<RegistryKey
Root="HKLM"
Key="SYSTEM\CurrentControlSet\Services\EventLog\Application\{{ .Binary }}">
<RegistryValue
Type="expandable"
Name="EventMessageFile"
Value="%SystemRoot%\System32\EventCreate.exe"/>
</RegistryKey>
</Component>
</Directory>
</Directory>
</Directory>
</Product>
</Wix>
<< end >>
13 changes: 12 additions & 1 deletion distributions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,21 @@ done
```

#### Packages
If a distribution provides linux packages (refer to its README), you can follow the instructions below to install them (using the `host` distribution as an example).
If a distribution provides windows installers or linux packages (refer to its README), you can follow the instructions below to install them (using the `host` distribution as an example).

> Note: `systemd` is required for automatic service configuration.

#### MSI Installation
```powershell
set collector_distro="nrdot-collector-host"
set collector_version="1.5.0"
set collector_arch="x64"
set license_key="YOUR_LICENSE_KEY"

iwr "https://github.com/newrelic/nrdot-collector-releases/releases/download/${collector_version}/${collector_distro}_${collector_version}_windows_${collector_arch}.msi" -OutFile "collector.msi"
msiexec /i "collector.msi" NEW_RELIC_LICENSE_KEY="$license_key"
```

##### DEB Installation
```bash
export collector_distro="nrdot-collector-host"
Expand Down
10 changes: 10 additions & 0 deletions distributions/nrdot-collector-host/msi-guids.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"standard": {
"product_upgrade_code": "TEMP-PRODUCT-CODE-HOST",
"component_guid": "TEMP-COMPONENT-GUID-HOST"
},
"fips": {
"product_upgrade_code": "TEMP-PRODUCT-CODE-HOST-FIPS",
"component_guid": "TEMP-COMPONENT-GUID-HOST-FIPS"
}
}
97 changes: 97 additions & 0 deletions distributions/nrdot-collector-host/windows-installer-fips.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product
Name="NRDOT Collector ({{ .Version }}) - Host (FIPS) distribution"
Id="*"
UpgradeCode="TEMP-PRODUCT-CODE-HOST-FIPS"
Version="{{ .Version }}"
Manufacturer="OpenTelemetry"
Language="1033">

<Package
InstallerVersion="200"
Compressed="yes"
Comments="Windows Installer Package"
InstallScope="perMachine"/>
<Media Id="1" Cabinet="product.cab" EmbedCab="yes"/>
<Icon Id="ProductIcon" SourceFile="opentelemetry.ico"/> <!-- TODO: Add NR Icon? -->
<Property Id="ARPPRODUCTICON" Value="ProductIcon"/>
<Property Id="ARPHELPLINK" Value="https://support.newrelic.com/s/"/>
<Property Id="ARPURLINFOABOUT" Value="https://opentelemetry.io/"/> <!-- TODO: Find the appropriate Info URL-->
<Property Id="ARPNOREPAIR" Value="1"/>
<Property Id="ARPNOMODIFY" Value="1"/>

<MajorUpgrade
DowngradeErrorMessage="A later version of NRDOT is already installed. Setup will now exit."/>

<Feature Id="Feature" Level="1">
<ComponentRef Id="ApplicationComponent"/>
</Feature>

<Property Id="COLLECTOR_SVC_ARGS"/>
<CustomAction
Id="SetCollectorSvcArgs"
Property="COLLECTOR_SVC_ARGS"
Value="--config &quot;[INSTALLDIR]config.yaml&quot;"/>

<Property Id="NEW_RELIC_LICENSE_KEY"/>

<InstallExecuteSequence>
<Custom Action="SetCollectorSvcArgs" Before="InstallFiles">NOT COLLECTOR_SVC_ARGS</Custom>
</InstallExecuteSequence>

<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFiles64Folder">
<Directory Id="INSTALLDIR" Name="{{ .Binary }}">
<!-- TODO: The UpgradeCode in Product is Contribs. We need to generate our own. -->
<Component Id="ApplicationComponent" Guid="TEMP-COMPONENT-GUID-HOST-FIPS">
<!-- Files to include -->
<File
Id="{{ replace .Binary "-" "_"}}.exe"
Name="{{ .Binary }}.exe"
Source="{{ .Binary }}.exe"
KeyPath="yes"/>
<File
Id="config.yaml"
Name="config.yaml"
Source="config.yaml"/>

<Environment
Action="set"
Name="NEW_RELIC_LICENSE_KEY"
Value="[NEW_RELIC_LICENSE_KEY]"
/>

<ServiceInstall
Id="Sevice"
Name="{{ .Binary }}"
DisplayName="NRDOT Collector Host (FIPS)"
Description="NRDOT Host (FIPS) Distribution of the OpenTelemetry Collector"
Type="ownProcess"
Vital="yes"
Start="auto"
Account="LocalSystem"
ErrorControl="normal"
Arguments="[COLLECTOR_SVC_ARGS]"
Interactive="no"/>
<ServiceControl
Id="StartStopRemoveService"
Name="{{ .Binary }}"
Start="install"
Stop="both"
Remove="uninstall"
Wait="yes"/>

<RegistryKey
Root="HKLM"
Key="SYSTEM\CurrentControlSet\Services\EventLog\Application\{{ .Binary }}">
<RegistryValue
Type="expandable"
Name="EventMessageFile"
Value="%SystemRoot%\System32\EventCreate.exe"/>
</RegistryKey>
</Component>
</Directory>
</Directory>
</Directory>
</Product>
</Wix>
Loading
Loading