Skip to content

Commit ab04b54

Browse files
pjanottihughesjj
authored andcommitted
Make MSI more capable during setup
1 parent 48eafef commit ab04b54

File tree

11 files changed

+257
-44
lines changed

11 files changed

+257
-44
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ coverage_all.txt
2424
coverage_old.txt
2525
coverage.html
2626

27-
# Exclude folders to build MSI locally
27+
# Exclude folders used to build MSI locally
2828
/build/
2929
/work/
3030

3131
# Wix
3232
*.wixobj
3333
*.wixpdb
34-
# Exclude source file generated by Wix heat tool
35-
/internal/buildscripts/packaging/msi/configfiles.wxs
3634

3735
# Python
3836
venv/

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,17 @@ endif
214214
docker run --rm -v $(CURDIR):/repo -e PACKAGE=$* -e VERSION=$(VERSION) -e ARCH=$(ARCH) -e JMX_METRIC_GATHERER_RELEASE=$(JMX_METRIC_GATHERER_RELEASE) otelcol-fpm
215215

216216
.PHONY: msi
217-
msi:
217+
msi: msi-custom-actions
218218
ifneq ($(SKIP_COMPILE), true)
219219
$(MAKE) binaries-windows_amd64
220220
endif
221221
test -f ./dist/agent-bundle_windows_amd64.zip || (echo "./dist/agent-bundle_windows_amd64.zip not found! Either download a pre-built bundle to ./dist/, or run './internal/signalfx-agent/bundle/scripts/windows/make.ps1 bundle' on a windows host and copy it to ./dist/." && exit 1)
222222
./internal/buildscripts/packaging/msi/build.sh "$(VERSION)" "$(DOCKER_REPO)" "$(JMX_METRIC_GATHERER_RELEASE)"
223223

224+
.PHONY: msi-custom-actions
225+
msi-custom-actions:
226+
dotnet publish ./internal/buildscripts/packaging/msi/SplunkCustomActions/SplunkCustomActions.csproj -c Release -o ./internal/buildscripts/packaging/msi/SplunkCustomActions/bin/Release
227+
224228
.PHONY: update-examples
225229
update-examples:
226230
cd examples && $(MAKE) update-examples
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Ignore the .NET build outputs
2+
bin/
3+
obj/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup useLegacyV2RuntimeActivationPolicy="true">
4+
<supportedRuntime version="v4.0" />
5+
</startup>
6+
</configuration>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Copyright Splunk, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using Microsoft.Deployment.WindowsInstaller;
16+
17+
public class CustomActions
18+
{
19+
/// <summary>
20+
/// Custom action to check if the launch conditions are met.
21+
/// </summary>
22+
/// <param name="session">Carries information about the current installation session.</param>
23+
/// <returns>An action result that indicates success or failure of the check.</returns>
24+
[CustomAction]
25+
public static ActionResult CheckLaunchConditions(Session session)
26+
{
27+
// Check if it is uninstall, if so, skip any check.
28+
var removeValue = session["REMOVE"];
29+
session.Log("Info: REMOVE=" + removeValue);
30+
if (removeValue == "ALL")
31+
{
32+
return ActionResult.Success;
33+
}
34+
35+
// If SPLUNK_ACCESS_TOKEN is not set, fail the check.
36+
var splunkToken = session["SPLUNK_ACCESS_TOKEN"];
37+
session.Log("Info: SPLUNK_ACCESS_TOKEN=" + splunkToken);
38+
if (string.IsNullOrWhiteSpace(splunkToken))
39+
{
40+
LogAndShowError(session, "SPLUNK_ACCESS_TOKEN must be specified.");
41+
return ActionResult.Failure;
42+
}
43+
44+
// If SPLUNK_SETUP_COLLECTOR_MODE is not one of the expected values, fail the check.
45+
var collectorMode = session["SPLUNK_SETUP_COLLECTOR_MODE"] ?? string.Empty;
46+
session.Log("Info: SPLUNK_SETUP_COLLECTOR_MODE=" + collectorMode);
47+
if (collectorMode != "agent" && collectorMode != "gateway")
48+
{
49+
LogAndShowError(session, "SPLUNK_SETUP_COLLECTOR_MODE must be either 'agent' or 'gateway'.");
50+
return ActionResult.Failure;
51+
}
52+
53+
return ActionResult.Success;
54+
}
55+
56+
/// <summary>
57+
/// Set the values of "automatic" properties, i.e. properties that require some logic to be set.
58+
/// </summary>
59+
/// <param name="session">Carries information about the current installation session.</param>
60+
/// <returns>An action result that indicates success or failure of the operation.</returns>
61+
[CustomAction]
62+
public static ActionResult SetAutomaticProperties(Session session)
63+
{
64+
var listenInterface = session["SPLUNK_SETUP_LISTEN_INTERFACE"];
65+
if (string.IsNullOrWhiteSpace(listenInterface))
66+
{
67+
var collectorMode = session["SPLUNK_SETUP_COLLECTOR_MODE"];
68+
session["SPLUNK_SETUP_LISTEN_INTERFACE"] = collectorMode switch {
69+
"agent" => "127.0.0.1",
70+
"gateway" => "0.0.0.0",
71+
// It is an internal error if it doesn't match any of the expected values.
72+
_ => throw new InvalidOperationException("SPLUNK_SETUP_COLLECTOR_MODE must be either 'agent' or 'gateway'.")
73+
};
74+
}
75+
76+
return ActionResult.Success;
77+
}
78+
79+
/// <summary>
80+
/// Helper to log and show error messages if the installation fails.
81+
/// When running in silent mode no dialog is shown.
82+
/// <summary>
83+
/// <param name="session">Carries information about the current installation session.</param>
84+
/// <param name="message">The error message to log and show.</param>
85+
private static void LogAndShowError(Session session, string message)
86+
{
87+
session.Log("Error: " + message);
88+
if (session["UILevel"] != InstallUIOptions.Silent.ToString()) // 2 is the value for INSTALLUILEVEL_NONE
89+
{
90+
session.Message(InstallMessage.Error, new Record { FormatString = message });
91+
}
92+
}
93+
}
94+
95+
/*
96+
dotnet publish SplunkCustomActions.csproj --use-current-runtime -c Release -o bin\
97+
MakeSfxCA.exe $PWD\bin\SplunkCustomActions.CA.dll 'C:\Program Files (x86)\WiX Toolset v3.14\SDK\x64\sfxca.dll' $PWD\bin\SplunkCustomActions.dll $PWD\bin\Microsoft.Deployment.WindowsInstaller.dll $PWD\CustomAction.config
98+
*/
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<ImplicitUsings>enable</ImplicitUsings>
5+
<Nullable>enable</Nullable>
6+
<OutputType>Library</OutputType>
7+
<RootNamespace>SplunkCustomActions</RootNamespace>
8+
<TargetFramework>net462</TargetFramework>
9+
<LangVersion>Latest</LangVersion>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<Reference Include="Microsoft.Deployment.WindowsInstaller">
14+
<HintPath>$(MSBuildProgramFiles32)\WiX Toolset v3.14\SDK\Microsoft.Deployment.WindowsInstaller.dll</HintPath>
15+
</Reference>
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.5.002.0
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SplunkCustomActions", "SplunkCustomActions.csproj", "{CA568D0A-57DC-45B5-ADC7-EBBC06B6F580}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{CA568D0A-57DC-45B5-ADC7-EBBC06B6F580}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{CA568D0A-57DC-45B5-ADC7-EBBC06B6F580}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{CA568D0A-57DC-45B5-ADC7-EBBC06B6F580}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{CA568D0A-57DC-45B5-ADC7-EBBC06B6F580}.Release|Any CPU.Build.0 = Release|Any CPU
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
GlobalSection(ExtensibilityGlobals) = postSolution
22+
SolutionGuid = {EFE0FC55-9724-4F64-ABE7-2EF6A3E186BD}
23+
EndGlobalSection
24+
EndGlobal

internal/buildscripts/packaging/msi/make.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function Install-Tools {
3535
$ProgressPreference = $OriginalPref
3636

3737
choco install wixtoolset -y
38-
setx /m PATH "%PATH%;C:\Program Files (x86)\WiX Toolset v3.11\bin"
38+
setx /m PATH "%PATH%;C:\Program Files (x86)\WiX Toolset v3.14\bin"
3939
refreshenv
4040
}
4141

internal/buildscripts/packaging/msi/msi-builder/build.sh

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ set -euo pipefail
2020
PROJECT_DIR=${PROJECT_DIR:-/project}
2121
WORK_DIR=${WORK_DIR:-/work}
2222

23-
WXS_PATH="${PROJECT_DIR}/internal/buildscripts/packaging/msi/splunk-otel-collector.wxs"
23+
MSI_SRC_DIR="${PROJECT_DIR}/internal/buildscripts/packaging/msi"
24+
WXS_PATH="${MSI_SRC_DIR}/splunk-otel-collector.wxs"
2425
OTELCOL="${PROJECT_DIR}/bin/otelcol_windows_amd64.exe"
2526
AGENT_CONFIG="${PROJECT_DIR}/cmd/otelcol/config/collector/agent_config.yaml"
2627
GATEWAY_CONFIG="${PROJECT_DIR}/cmd/otelcol/config/collector/gateway_config.yaml"
2728
FLUENTD_CONFIG="${PROJECT_DIR}/internal/buildscripts/packaging/fpm/etc/otel/collector/fluentd/fluent.conf"
28-
FLUENTD_CONFD="${PROJECT_DIR}/internal/buildscripts/packaging/msi/fluentd/conf.d"
29-
SUPPORT_BUNDLE_SCRIPT="${PROJECT_DIR}/internal/buildscripts/packaging/msi/splunk-support-bundle.ps1"
30-
SPLUNK_ICON="${PROJECT_DIR}/internal/buildscripts/packaging/msi/splunk.ico"
29+
FLUENTD_CONFD="${MSI_SRC_DIR}/fluentd/conf.d"
30+
SUPPORT_BUNDLE_SCRIPT="${MSI_SRC_DIR}/splunk-support-bundle.ps1"
31+
SPLUNK_ICON="${MSI_SRC_DIR}/splunk.ico"
3132
OUTPUT_DIR="${PROJECT_DIR}/dist"
3233
JMX_METRIC_GATHERER_RELEASE="1.29.0"
3334

@@ -40,25 +41,25 @@ Description:
4041
By default, the MSI is saved as '${OUTPUT_DIR}/splunk-otel-collector-VERSION-amd64.msi'.
4142
4243
OPTIONS:
43-
--otelcol PATH: Absolute path to the otelcol exe.
44+
--otelcol PATH Absolute path to the otelcol exe.
4445
Defaults to '$OTELCOL'.
45-
--agent-config PATH: Absolute path to the agent config.
46+
--agent-config PATH Absolute path to the agent config.
4647
Defaults to '$AGENT_CONFIG'.
47-
--gateway-config PATH: Absolute path to the gateway config.
48+
--gateway-config PATH Absolute path to the gateway config.
4849
Defaults to '$GATEWAY_CONFIG'.
49-
--fluentd PATH: Absolute path to the fluentd config.
50+
--fluentd PATH Absolute path to the fluentd config.
5051
Defaults to '$FLUENTD_CONFIG'.
51-
--fluentd-confd PATH: Absolute path to the conf.d.
52+
--fluentd-confd PATH Absolute path to the conf.d.
5253
Defaults to '$FLUENTD_CONFD'.
53-
--support-bundle PATH: Absolute path to the support bundle script.
54+
--support-bundle PATH Absolute path to the support bundle script.
5455
Defaults to '$SUPPORT_BUNDLE_SCRIPT'.
55-
--jmx-metric-gatherer VERSION: The released version of the JMX Metric Gatherer JAR to include (will be downloaded).
56+
--jmx-metric-gatherer VERSION The released version of the JMX Metric Gatherer JAR to include (will be downloaded).
5657
Defaults to '$JMX_METRIC_GATHERER_RELEASE'.
57-
--splunk-icon PATH: Absolute path to the splunk.ico.
58+
--splunk-icon PATH Absolute path to the splunk.ico.
5859
Defaults to '$SPLUNK_ICON'.
59-
--output DIR: Directory to save the MSI.
60+
--output DIR Directory to save the MSI.
6061
Defaults to '$OUTPUT_DIR'.
61-
62+
--skip-build-dir-removal Skip removing the build directory before building the MSI.
6263
EOH
6364
}
6465

@@ -73,6 +74,7 @@ parse_args_and_build() {
7374
local splunk_icon="$SPLUNK_ICON"
7475
local output="$OUTPUT_DIR"
7576
local version=
77+
local skip_build_dir_removal=
7678

7779
while [ -n "${1-}" ]; do
7880
case $1 in
@@ -112,6 +114,9 @@ parse_args_and_build() {
112114
output="$2"
113115
shift 1
114116
;;
117+
--skip-build-dir-removal)
118+
skip_build_dir_removal=1
119+
;;
115120
-*)
116121
echo "Unknown option '$1'"
117122
echo
@@ -141,8 +146,10 @@ parse_args_and_build() {
141146
files_dir="${build_dir}/msi"
142147
msi_name="splunk-otel-collector-${version}-amd64.msi"
143148

144-
if [ -d "$build_dir" ]; then
149+
if [ -z "$skip_build_dir_removal" && -d "$build_dir" ]; then
145150
rm -rf "$build_dir"
151+
else
152+
echo "Skipping build directory removal"
146153
fi
147154

148155
mkdir -p "${files_dir}/fluentd/conf.d"
@@ -152,15 +159,16 @@ parse_args_and_build() {
152159
cp "$fluentd_config" "${files_dir}/fluentd/td-agent.conf"
153160
cp "${fluentd_confd}"/*.conf "${files_dir}/fluentd/conf.d/"
154161

155-
unzip -d "$files_dir" "${OUTPUT_DIR}/agent-bundle_windows_amd64.zip"
156-
rm -f "${OUTPUT_DIR}/agent-bundle_windows_amd64.zip"
162+
if [ -z "$skip_build_dir_removal" ]; then
163+
unzip -d "$files_dir" "${OUTPUT_DIR}/agent-bundle_windows_amd64.zip"
164+
rm -f "${OUTPUT_DIR}/agent-bundle_windows_amd64.zip"
157165

158-
download_jmx_metric_gatherer "$jmx_metric_gatherer_release" "$build_dir"
159-
jmx_metrics_jar="${build_dir}/opentelemetry-java-contrib-jmx-metrics.jar"
166+
download_jmx_metric_gatherer "$jmx_metric_gatherer_release" "$build_dir"
167+
else
168+
echo "Skipping unzipping agent bundle and downloading JMX Metric Gatherer"
169+
fi
160170

161-
# kludge to satisfy relative path in splunk-otel-collector.wxs
162-
mkdir -p ${WORK_DIR}/internal/buildscripts/packaging/msi
163-
cp "${splunk_icon}" "${WORK_DIR}/internal/buildscripts/packaging/msi/splunk.ico"
171+
jmx_metrics_jar="${build_dir}/opentelemetry-java-contrib-jmx-metrics.jar"
164172

165173
cd ${WORK_DIR}
166174
configFilesWsx="${build_dir}/configfiles.wsx"
@@ -172,6 +180,13 @@ parse_args_and_build() {
172180
collectorWixObj="${build_dir}/splunk-otel-collector.wixobj"
173181
candle -arch x64 -out "${collectorWixObj}" -dVersion="$version" -dOtelcol="$otelcol" -dJmxMetricsJar="$jmx_metrics_jar" "${WXS_PATH}"
174182

183+
customActionsDll="${MSI_SRC_DIR}/SplunkCustomActions/bin/Release/SplunkCustomActions.CA.dll"
184+
MakeSfxCA "${customActionsDll}" \
185+
"$WIX\SDK\x64\sfxca.dll" \
186+
"${MSI_SRC_DIR}/SplunkCustomActions/bin/Release/SplunkCustomActions.dll" \
187+
"${MSI_SRC_DIR}/SplunkCustomActions/bin/Release/Microsoft.Deployment.WindowsInstaller.dll" \
188+
"${MSI_SRC_DIR}/SplunkCustomActions/CustomAction.config"
189+
175190
msi="${build_dir}/${msi_name}"
176191
light -ext WixUtilExtension.dll -sval -out "${msi}" -b "${files_dir}" "${collectorWixObj}" "${configFilesWixObj}"
177192

0 commit comments

Comments
 (0)