Skip to content

Commit

Permalink
Added wix file and build step to create msi
Browse files Browse the repository at this point in the history
  • Loading branch information
james-bebbington committed Jun 30, 2020
1 parent 12b3d9c commit 6a1d522
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 3 deletions.
29 changes: 28 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ workflows:
only: /^v([0-9])+.([0-9])+.([0-9])+.*/
- cross-compile:
requires:
- build
- setup-and-lint
filters:
tags:
only: /^v([0-9])+.([0-9])+.([0-9])+.*/
Expand Down Expand Up @@ -101,6 +101,12 @@ workflows:
filters:
tags:
only: /^v([0-9])+.([0-9])+.([0-9])+.*/
- windows-msi:
requires:
- cross-compile
filters:
tags:
only: /^v([0-9])+.([0-9])+.([0-9])+.*/
- publish-stable:
requires:
- cross-compile
Expand All @@ -109,6 +115,7 @@ workflows:
- gosec
- coverage
- windows-test
- windows-msi
filters:
branches:
ignore: /.*/
Expand All @@ -122,6 +129,7 @@ workflows:
- gosec
- coverage
- windows-test
- windows-msi
filters:
branches:
only: master
Expand Down Expand Up @@ -284,3 +292,22 @@ jobs:
command: |
sudo npm install -g markdown-link-check
bash .circleci/check-links/check-links.sh
windows-msi:
executor:
name: win/default
shell: powershell.exe
steps:
- attach_to_workspace
- run:
name: Install Wix Toolset
command: .\packaging\msi\make.ps1 Install-Tools
- run:
name: Build MSI
command: .\packaging\msi\make.ps1 New-MSI
- run:
name: Validate MSI
command: .\packaging\msi\make.ps1 Confirm-MSI
- persist_to_workspace:
root: ~/
paths: project/bin
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ coverage.txt
coverage_all.txt
coverage_old.txt
coverage.html

# Wix
*.wixobj
*.wixpdb
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ install-tools:

.PHONY: otelcol
otelcol:
GO111MODULE=on CGO_ENABLED=0 go build -o ./bin/otelcol_$(GOOS)_$(GOARCH) $(BUILD_INFO) ./cmd/otelcol
GO111MODULE=on CGO_ENABLED=0 go build -o ./bin/otelcol_$(GOOS)_$(GOARCH)$(EXTENSION) $(BUILD_INFO) ./cmd/otelcol

.PHONY: run
run:
Expand Down Expand Up @@ -201,7 +201,7 @@ binaries-linux_arm64:

.PHONY: binaries-windows_amd64
binaries-windows_amd64:
GOOS=windows GOARCH=amd64 $(MAKE) binaries
GOOS=windows GOARCH=amd64 EXTENSION=.exe $(MAKE) binaries

# Definitions for ProtoBuf generation.

Expand Down
53 changes: 53 additions & 0 deletions packaging/msi/make.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

<#
.SYNOPSIS
Makefile like build commands for the Collector on Windows.
Usage: .\make.ps1 <Command> [-<Param> <Value> ...]
Example: .\make.ps1 New-MSI -Config "./my-config.yaml"
.PARAMETER Target
Build target to run (Install-Tools, New-MSI)
#>
Param(
[Parameter(Mandatory=$true, ValueFromRemainingArguments=$true)][string]$Target
)

$ErrorActionPreference = "Stop"

function Install-Tools {
choco install wixtoolset -y
setx /m PATH "%PATH%;C:\Program Files (x86)\WiX Toolset v3.11\bin"
refreshenv
}

function New-MSI(
[string]$Config="./examples/otel-local-config.yaml"
) {
$Version = If($env:VERSION) { $env:VERSION } else { "0.0.1" }
candle -arch x64 -dVersion="$Version" -dConfig="$Config" packaging/msi/opentelemetry-collector.wxs
light opentelemetry-collector.wixobj
Move-Item -Force opentelemetry-collector.msi bin/opentelemetry-collector.msi
}

function Confirm-MSI {
msiexec /i bin/opentelemetry-collector.msi /qn
Stop-Service otelcol
Start-Service otelcol
msiexec /x bin/opentelemetry-collector.msi /qn
}

$sb = [scriptblock]::create("$Target")
Invoke-Command -ScriptBlock $sb
56 changes: 56 additions & 0 deletions packaging/msi/opentelemetry-collector.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" UpgradeCode="B7C263DD-95A5-436A-A025-DCA5200C2BE3" Name="OpenTelemetry Collector" Version="$(var.Version)" Manufacturer="OpenTelemetry" Language="1033">
<Package InstallerVersion="200" Compressed="yes" Comments="Windows Installer Package"/>
<Media Id="1" Cabinet="product.cab" EmbedCab="yes"/>
<Icon Id="ProductIcon" SourceFile="./packaging/msi/opentelemetry.ico"/>
<Property Id="ARPPRODUCTICON" Value="ProductIcon"/>
<Property Id="ARPHELPLINK" Value="https://opentelemetry.io/"/>
<Property Id="ARPURLINFOABOUT" Value="https://opentelemetry.io/"/>
<Property Id="ARPNOREPAIR" Value="1"/>
<Property Id="ARPNOMODIFY" Value="1"/>

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

<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFiles64Folder">
<Directory Id="INSTALLDIR" Name="OpenTelemetry Collector">
<Component Id="ApplicationComponent" Guid="1207C3C4-1830-4DC8-8A7B-2BD7DBE45BC3">
<!-- Files to include -->
<File Id="ExecutableFile" Name="otelcol.exe" KeyPath="yes" Source="./bin/otelcol_windows_amd64.exe"/>
<File Id="DefaultConfigFile" Name="config.yaml" Source="$(var.Config)" />
<!-- Since we may have overwritten the config file (see below), we need to explicitly remove it on uninstall -->
<RemoveFile Id="RemoveConfigFile" Name="config.yaml" On="uninstall" />

<ServiceInstall
Id="Sevice"
Name="otelcol"
DisplayName="OpenTelemetry Collector"
Description="Collects, processes, and exports telemetry from various configurable sources."
Type="ownProcess"
Vital="yes"
Start="auto"
Account="LocalSystem"
ErrorControl="normal"
Arguments=" --config=&quot;[INSTALLDIR]config.yaml&quot;"
Interactive="no" />
<ServiceControl
Id="StartStopRemoveService"
Name="otelcol"
Start="install"
Stop="both"
Remove="uninstall"
Wait="yes" />
</Component>
</Directory>
</Directory>
</Directory>

<!-- If CONFIG is supplied as a custom argument when installing, overwrite config.yaml with the specified file -->
<CustomAction Id="CopyConfig" ExeCommand="xcopy /y &quot;[CONFIG]&quot; &quot;[INSTALLDIR]config.yaml*&quot;" Directory="INSTALLDIR" Impersonate="no" Execute="deferred" Return="check" />
<InstallExecuteSequence>
<Custom Action="CopyConfig" After="InstallFiles">CONFIG AND NOT Installed</Custom>
</InstallExecuteSequence>
</Product>
</Wix>
Binary file added packaging/msi/opentelemetry.ico
Binary file not shown.

0 comments on commit 6a1d522

Please sign in to comment.