Skip to content

Commit 2c4377a

Browse files
committed
feat: add .wxs files and .wxs file template / generator
1 parent f7e3135 commit 2c4377a

File tree

10 files changed

+653
-1
lines changed

10 files changed

+653
-1
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ build: go ocb
2727
build-fips: go ocb
2828
@./scripts/build.sh -d "${DISTRIBUTIONS}" -b ${OTELCOL_BUILDER} -f true
2929

30-
generate: generate-sources generate-goreleaser
30+
generate: generate-sources generate-msi generate-goreleaser
31+
32+
generate-msi: go
33+
@./scripts/generate-msi.sh -d "${DISTRIBUTIONS}"
3134

3235
generate-goreleaser: go
3336
@./scripts/generate-goreleaser.sh -d "${DISTRIBUTIONS}" -g ${GO}

cmd/msi/main.go

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package main
5+
6+
import (
7+
"bytes"
8+
"encoding/json"
9+
"flag"
10+
"fmt"
11+
"log"
12+
"os"
13+
"text/template"
14+
)
15+
16+
type Guids struct {
17+
ProductUpgradeCode string `json:"product_upgrade_code"`
18+
ComponentGuid string `json:"component_guid"`
19+
}
20+
21+
type DistGuids struct {
22+
Standard Guids `json:"standard"`
23+
Fips Guids `json:"fips"`
24+
}
25+
26+
const (
27+
HostDistro = "nrdot-collector-host"
28+
K8sDistro = "nrdot-collector-k8s"
29+
CoreDistro = "nrdot-collector"
30+
templateFilename = "cmd/msi/windows-installer.wxs.tmpl"
31+
)
32+
33+
var (
34+
distFlag = flag.String("d", "", "Collector distributions to build")
35+
fipsFlag = flag.Bool("f", false, "FIPS")
36+
)
37+
38+
func main() {
39+
flag.Parse()
40+
41+
if len(*distFlag) == 0 {
42+
log.Fatal("no distribution to template")
43+
}
44+
45+
// Get GUIDs
46+
47+
// Parse the base template
48+
baseTemplate, err := template.New("base").Delims("<<", ">>").ParseFiles(templateFilename)
49+
if err != nil {
50+
panic(err)
51+
}
52+
53+
guids := getMsiGuids(*distFlag, *fipsFlag)
54+
55+
// Data for the base template
56+
data := map[string]interface{}{
57+
"InstallerName": getInstallerName(*distFlag, *fipsFlag),
58+
"ProductUpgradeCode": guids.ProductUpgradeCode,
59+
"ComponentGUID": guids.ComponentGuid,
60+
}
61+
62+
// Execute the base template to generate a new template
63+
var generatedTemplateContent bytes.Buffer
64+
err = baseTemplate.ExecuteTemplate(&generatedTemplateContent, "base", data)
65+
if err != nil {
66+
panic(err)
67+
}
68+
69+
err = baseTemplate.ExecuteTemplate(os.Stdout, "base", data)
70+
if err != nil {
71+
panic(err)
72+
}
73+
}
74+
75+
func getInstallerName(dist string, fips bool) string {
76+
name := ""
77+
switch dist {
78+
case CoreDistro:
79+
name = "Core"
80+
case HostDistro:
81+
name = "Host"
82+
case K8sDistro:
83+
name = "K8s"
84+
default:
85+
log.Fatal("Unknown Distribution:", dist)
86+
}
87+
if fips {
88+
name += " (FIPS)"
89+
}
90+
return name
91+
}
92+
93+
func getMsiGuids(dist string, fips bool) Guids {
94+
filename := fmt.Sprintf("./distributions/%s/msi-guids.json", *distFlag)
95+
data, err := os.ReadFile(filename)
96+
if err != nil {
97+
panic(err)
98+
}
99+
100+
var distGuids DistGuids
101+
err = json.Unmarshal(data, &distGuids)
102+
if err != nil {
103+
panic(err)
104+
}
105+
106+
if fips {
107+
return distGuids.Fips
108+
} else {
109+
return distGuids.Standard
110+
}
111+
}

cmd/msi/windows-installer.wxs.tmpl

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<< define "base" ->>
2+
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
3+
<Product
4+
Name="NRDOT Collector ({{ .Version }}) - << .InstallerName >> distribution"
5+
Id="*"
6+
UpgradeCode="<< .ProductUpgradeCode >>"
7+
Version="{{ .Version }}"
8+
Manufacturer="OpenTelemetry"
9+
Language="1033">
10+
11+
<Package
12+
InstallerVersion="200"
13+
Compressed="yes"
14+
Comments="Windows Installer Package"
15+
InstallScope="perMachine"/>
16+
<Media Id="1" Cabinet="product.cab" EmbedCab="yes"/>
17+
<Icon Id="ProductIcon" SourceFile="opentelemetry.ico"/> <!-- TODO: Add NR Icon? -->
18+
<Property Id="ARPPRODUCTICON" Value="ProductIcon"/>
19+
<Property Id="ARPHELPLINK" Value="https://support.newrelic.com/s/"/>
20+
<Property Id="ARPURLINFOABOUT" Value="https://opentelemetry.io/"/> <!-- TODO: Find the appropriate Info URL-->
21+
<Property Id="ARPNOREPAIR" Value="1"/>
22+
<Property Id="ARPNOMODIFY" Value="1"/>
23+
24+
<MajorUpgrade
25+
DowngradeErrorMessage="A later version of NRDOT is already installed. Setup will now exit."/>
26+
27+
<Feature Id="Feature" Level="1">
28+
<ComponentRef Id="ApplicationComponent"/>
29+
</Feature>
30+
31+
<Property Id="COLLECTOR_SVC_ARGS"/>
32+
<CustomAction
33+
Id="SetCollectorSvcArgs"
34+
Property="COLLECTOR_SVC_ARGS"
35+
Value="--config &quot;[INSTALLDIR]config.yaml&quot;"/>
36+
37+
<Property Id="NEW_RELIC_LICENSE_KEY"/>
38+
39+
<InstallExecuteSequence>
40+
<Custom Action="SetCollectorSvcArgs" Before="InstallFiles">NOT COLLECTOR_SVC_ARGS</Custom>
41+
</InstallExecuteSequence>
42+
43+
<Directory Id="TARGETDIR" Name="SourceDir">
44+
<Directory Id="ProgramFiles64Folder">
45+
<Directory Id="INSTALLDIR" Name="{{ .Binary }}">
46+
<!-- TODO: The UpgradeCode in Product is Contribs. We need to generate our own. -->
47+
<Component Id="ApplicationComponent" Guid="<< .ComponentGUID >>">
48+
<!-- Files to include -->
49+
<File
50+
Id="{{ replace .Binary "-" "_"}}.exe"
51+
Name="{{ .Binary }}.exe"
52+
Source="{{ .Binary }}.exe"
53+
KeyPath="yes"/>
54+
<File
55+
Id="config.yaml"
56+
Name="config.yaml"
57+
Source="config.yaml"/>
58+
59+
<Environment
60+
Action="set"
61+
Name="NEW_RELIC_LICENSE_KEY"
62+
Value="[NEW_RELIC_LICENSE_KEY]"
63+
/>
64+
65+
<ServiceInstall
66+
Id="Sevice"
67+
Name="{{ .Binary }}"
68+
DisplayName="NRDOT Collector << .InstallerName >>"
69+
Description="NRDOT << .InstallerName >> Distribution of the OpenTelemetry Collector"
70+
Type="ownProcess"
71+
Vital="yes"
72+
Start="auto"
73+
Account="LocalSystem"
74+
ErrorControl="normal"
75+
Arguments="[COLLECTOR_SVC_ARGS]"
76+
Interactive="no"/>
77+
<ServiceControl
78+
Id="StartStopRemoveService"
79+
Name="{{ .Binary }}"
80+
Start="install"
81+
Stop="both"
82+
Remove="uninstall"
83+
Wait="yes"/>
84+
85+
<RegistryKey
86+
Root="HKLM"
87+
Key="SYSTEM\CurrentControlSet\Services\EventLog\Application\{{ .Binary }}">
88+
<RegistryValue
89+
Type="expandable"
90+
Name="EventMessageFile"
91+
Value="%SystemRoot%\System32\EventCreate.exe"/>
92+
</RegistryKey>
93+
</Component>
94+
</Directory>
95+
</Directory>
96+
</Directory>
97+
</Product>
98+
</Wix>
99+
<< end >>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"standard": {
3+
"product_upgrade_code": "TEMP-PRODUCT-CODE-HOST",
4+
"component_guid": "TEMP-COMPONENT-GUID-HOST"
5+
},
6+
"fips": {
7+
"product_upgrade_code": "TEMP-PRODUCT-CODE-HOST-FIPS",
8+
"component_guid": "TEMP-COMPONENT-GUID-HOST-FIPS"
9+
}
10+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
2+
<Product
3+
Name="NRDOT Collector ({{ .Version }}) - Host (FIPS) distribution"
4+
Id="*"
5+
UpgradeCode="TEMP-PRODUCT-CODE-HOST-FIPS"
6+
Version="{{ .Version }}"
7+
Manufacturer="OpenTelemetry"
8+
Language="1033">
9+
10+
<Package
11+
InstallerVersion="200"
12+
Compressed="yes"
13+
Comments="Windows Installer Package"
14+
InstallScope="perMachine"/>
15+
<Media Id="1" Cabinet="product.cab" EmbedCab="yes"/>
16+
<Icon Id="ProductIcon" SourceFile="opentelemetry.ico"/> <!-- TODO: Add NR Icon? -->
17+
<Property Id="ARPPRODUCTICON" Value="ProductIcon"/>
18+
<Property Id="ARPHELPLINK" Value="https://support.newrelic.com/s/"/>
19+
<Property Id="ARPURLINFOABOUT" Value="https://opentelemetry.io/"/> <!-- TODO: Find the appropriate Info URL-->
20+
<Property Id="ARPNOREPAIR" Value="1"/>
21+
<Property Id="ARPNOMODIFY" Value="1"/>
22+
23+
<MajorUpgrade
24+
DowngradeErrorMessage="A later version of NRDOT is already installed. Setup will now exit."/>
25+
26+
<Feature Id="Feature" Level="1">
27+
<ComponentRef Id="ApplicationComponent"/>
28+
</Feature>
29+
30+
<Property Id="COLLECTOR_SVC_ARGS"/>
31+
<CustomAction
32+
Id="SetCollectorSvcArgs"
33+
Property="COLLECTOR_SVC_ARGS"
34+
Value="--config &quot;[INSTALLDIR]config.yaml&quot;"/>
35+
36+
<Property Id="NEW_RELIC_LICENSE_KEY"/>
37+
38+
<InstallExecuteSequence>
39+
<Custom Action="SetCollectorSvcArgs" Before="InstallFiles">NOT COLLECTOR_SVC_ARGS</Custom>
40+
</InstallExecuteSequence>
41+
42+
<Directory Id="TARGETDIR" Name="SourceDir">
43+
<Directory Id="ProgramFiles64Folder">
44+
<Directory Id="INSTALLDIR" Name="{{ .Binary }}">
45+
<!-- TODO: The UpgradeCode in Product is Contribs. We need to generate our own. -->
46+
<Component Id="ApplicationComponent" Guid="TEMP-COMPONENT-GUID-HOST-FIPS">
47+
<!-- Files to include -->
48+
<File
49+
Id="{{ replace .Binary "-" "_"}}.exe"
50+
Name="{{ .Binary }}.exe"
51+
Source="{{ .Binary }}.exe"
52+
KeyPath="yes"/>
53+
<File
54+
Id="config.yaml"
55+
Name="config.yaml"
56+
Source="config.yaml"/>
57+
58+
<Environment
59+
Action="set"
60+
Name="NEW_RELIC_LICENSE_KEY"
61+
Value="[NEW_RELIC_LICENSE_KEY]"
62+
/>
63+
64+
<ServiceInstall
65+
Id="Sevice"
66+
Name="{{ .Binary }}"
67+
DisplayName="NRDOT Collector Host (FIPS)"
68+
Description="NRDOT Host (FIPS) Distribution of the OpenTelemetry Collector"
69+
Type="ownProcess"
70+
Vital="yes"
71+
Start="auto"
72+
Account="LocalSystem"
73+
ErrorControl="normal"
74+
Arguments="[COLLECTOR_SVC_ARGS]"
75+
Interactive="no"/>
76+
<ServiceControl
77+
Id="StartStopRemoveService"
78+
Name="{{ .Binary }}"
79+
Start="install"
80+
Stop="both"
81+
Remove="uninstall"
82+
Wait="yes"/>
83+
84+
<RegistryKey
85+
Root="HKLM"
86+
Key="SYSTEM\CurrentControlSet\Services\EventLog\Application\{{ .Binary }}">
87+
<RegistryValue
88+
Type="expandable"
89+
Name="EventMessageFile"
90+
Value="%SystemRoot%\System32\EventCreate.exe"/>
91+
</RegistryKey>
92+
</Component>
93+
</Directory>
94+
</Directory>
95+
</Directory>
96+
</Product>
97+
</Wix>

0 commit comments

Comments
 (0)