Skip to content

Commit

Permalink
Add MSI build script and templates for Windows infrastructure agent
Browse files Browse the repository at this point in the history
  • Loading branch information
simlarsen committed Dec 19, 2024
1 parent 282373b commit 663f151
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 1 deletion.
4 changes: 3 additions & 1 deletion InfrastructureAgent/.goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ before:
- go mod download
env:
- CGO_ENABLED=0

nfpms:
# note that this is an array of nfpm configs
- #
Expand Down Expand Up @@ -68,7 +69,8 @@ nfpms:
- bash
- coreutils
- systemd



builds:
- binary: oneuptime-infrastructure-agent
main: ./
Expand Down
64 changes: 64 additions & 0 deletions InfrastructureAgent/build-msi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

# sudo apt update
# sudo apt install -y msitools


# Exit script on any error
set -e

# Variables
OUTPUT_DIR="./dist/windows"
APP_NAME="oneuptime-infrastructure-agent"
# Take version from --version argument

APP_VERSION=$1

# Log version
echo "Building MSI for version: $APP_VERSION"

# Paths to binaries
BINARIES=(
"./dist/oneuptime_windows_amd64_v1/oneuptime-infrastructure-agent.exe"
"./dist/oneuptime_windows_arm64/oneuptime-infrastructure-agent.exe"
)

# Architecture mappings
ARCHES=("amd64" "arm64")

# Ensure output directory exists
mkdir -p "$OUTPUT_DIR"

# Check if wixl is installed
if ! command -v wixl &> /dev/null; then
echo "Error: wixl is not installed. Please install it using 'sudo apt install -y msitools'."
exit 1
fi

# Generate MSI files for each binary
for i in "${!BINARIES[@]}"; do
BINARY="${BINARIES[$i]}"
ARCH="${ARCHES[$i]}"
WXS_INPUT_FILE="./windows/app-$ARCH-template.wxs"
WXS_OUTPUT_FILE="./windows/app-$ARCH.wxs"
MSI_FILE="$OUTPUT_DIR/$APP_NAME-$APP_VERSION-$ARCH.msi"

# log binary and arch
echo "Building MSI for binary: $BINARY and arch: $ARCH"

# Update the WXS file with the correct binary
sed "s|binary_placeholder|$BINARY|g" $WXS_INPUT_FILE > "$WXS_OUTPUT_FILE"

# Update version in WXS file
sed -i "s|version_placeholder|$APP_VERSION|g" "$WXS_OUTPUT_FILE"

echo "Packaging $BINARY into $MSI_FILE..."
wixl -o "$MSI_FILE" "$WXS_OUTPUT_FILE"

if [ $? -eq 0 ]; then
echo "MSI successfully created: $MSI_FILE"
else
echo "Error: Failed to create MSI for $ARCH."
exit 1
fi
done
24 changes: 24 additions & 0 deletions InfrastructureAgent/windows/app-amd64-template.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="OneUptime Infrastructure Agent (amd64)" Language="1033" Version="version_placeholder" Manufacturer="HackerBay, Inc." UpgradeCode="4ea4efc3-2b63-4afd-b1a9-ab47e626b752">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of OneUptime Infrastructure Agent is already installed." />
<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />

<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="OneUptimeAgent" />
</Directory>
</Directory>

<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="MainExecutable" Guid="2fffc00b-249b-4425-9bbb-524689362a81">
<File Source="binary_placeholder" />
</Component>
</ComponentGroup>

<Feature Id="ProductFeature" Title="OneUptime Infrastructure Agent (amd64)" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Product>
</Wix>
24 changes: 24 additions & 0 deletions InfrastructureAgent/windows/app-arm64-template.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="OneUptime Infrastructure Agent (arm64)" Language="1033" Version="version_placeholder" Manufacturer="HackerBay, Inc." UpgradeCode="e2c6daee-3273-43ab-bef1-09cc0960c356">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />

<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="OneUptimeAgent" />
</Directory>
</Directory>

<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="MainExecutable" Guid="PUT-ARM64-GUID-HERE">
<File Source="binary_placeholder" />
</Component>
</ComponentGroup>

<Feature Id="ProductFeature" Title="OneUptime Infrastructure Agent (arm64)" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Product>
</Wix>

0 comments on commit 663f151

Please sign in to comment.