From 663f15105126e0993dfc74079ef8a86166639b13 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Thu, 19 Dec 2024 19:44:39 +0000 Subject: [PATCH] Add MSI build script and templates for Windows infrastructure agent --- InfrastructureAgent/.goreleaser.yaml | 4 +- InfrastructureAgent/build-msi.sh | 64 +++++++++++++++++++ .../windows/app-amd64-template.wxs | 24 +++++++ .../windows/app-arm64-template.wxs | 24 +++++++ 4 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 InfrastructureAgent/build-msi.sh create mode 100644 InfrastructureAgent/windows/app-amd64-template.wxs create mode 100644 InfrastructureAgent/windows/app-arm64-template.wxs diff --git a/InfrastructureAgent/.goreleaser.yaml b/InfrastructureAgent/.goreleaser.yaml index 99e0590681..f49f13e8d8 100644 --- a/InfrastructureAgent/.goreleaser.yaml +++ b/InfrastructureAgent/.goreleaser.yaml @@ -14,6 +14,7 @@ before: - go mod download env: - CGO_ENABLED=0 + nfpms: # note that this is an array of nfpm configs - # @@ -68,7 +69,8 @@ nfpms: - bash - coreutils - systemd - + + builds: - binary: oneuptime-infrastructure-agent main: ./ diff --git a/InfrastructureAgent/build-msi.sh b/InfrastructureAgent/build-msi.sh new file mode 100644 index 0000000000..944e0469d0 --- /dev/null +++ b/InfrastructureAgent/build-msi.sh @@ -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 \ No newline at end of file diff --git a/InfrastructureAgent/windows/app-amd64-template.wxs b/InfrastructureAgent/windows/app-amd64-template.wxs new file mode 100644 index 0000000000..086d106389 --- /dev/null +++ b/InfrastructureAgent/windows/app-amd64-template.wxs @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/InfrastructureAgent/windows/app-arm64-template.wxs b/InfrastructureAgent/windows/app-arm64-template.wxs new file mode 100644 index 0000000000..adeb8354c3 --- /dev/null +++ b/InfrastructureAgent/windows/app-arm64-template.wxs @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + +