From 8f6a1e3f07afc9296aae3e0b0e8f711382a95979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Fri, 3 May 2024 07:30:31 +0200 Subject: [PATCH] Implement a Windows application manifest (#1445) --- .gitignore | 2 +- Makefile | 9 ++++++-- exporter.go | 7 +++++-- winres/winres.json | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 winres/winres.json diff --git a/.gitignore b/.gitignore index b225252a..2c199092 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ output/ .idea *.syso installer/*.msi -installer/*.wixpdb \ No newline at end of file +installer/*.wixpdb diff --git a/Makefile b/Makefile index 3e429802..2a16cd1e 100644 --- a/Makefile +++ b/Makefile @@ -12,10 +12,15 @@ ALL_OS:= 1809 ltsc2022 BASE_IMAGE=mcr.microsoft.com/windows/nanoserver .PHONY: build -build: windows_exporter.exe +build: generate windows_exporter.exe + windows_exporter.exe: pkg/**/*.go promu build -v +.PHONY: generate +generate: + go generate ./... + test: go test -v ./... @@ -36,7 +41,7 @@ promtool: windows_exporter.exe fmt: gofmt -l -w -s . -crossbuild: +crossbuild: generate # The prometheus/golang-builder image for promu crossbuild doesn't exist # on Windows, so for now, we'll just build twice GOARCH=amd64 promu build --prefix=output/amd64 diff --git a/exporter.go b/exporter.go index f93a3b75..5ff8c8c2 100644 --- a/exporter.go +++ b/exporter.go @@ -1,8 +1,13 @@ //go:build windows +//go:generate go run github.com/tc-hib/go-winres@v0.3.3 make --product-version=git-tag --file-version=git-tag --arch=amd64,arm64 + package main import ( + // Its important that we do these first so that we can register with the Windows service control ASAP to avoid timeouts + "github.com/prometheus-community/windows_exporter/pkg/initiate" + "encoding/json" "fmt" "net/http" @@ -13,8 +18,6 @@ import ( "sort" "strings" - // Its important that we do these first so that we can register with the windows service control ASAP to avoid timeouts - "github.com/prometheus-community/windows_exporter/pkg/initiate" winlog "github.com/prometheus-community/windows_exporter/pkg/log" "github.com/prometheus-community/windows_exporter/pkg/types" "github.com/prometheus-community/windows_exporter/pkg/utils" diff --git a/winres/winres.json b/winres/winres.json new file mode 100644 index 00000000..0aa40a99 --- /dev/null +++ b/winres/winres.json @@ -0,0 +1,52 @@ +{ + "RT_GROUP_ICON": { + "APP": {} + }, + "RT_MANIFEST": { + "#1": { + "0409": { + "description": "A Prometheus exporter for Windows machines.", + "minimum-os": "win7", + "execution-level": "as invoker", + "ui-access": false, + "auto-elevate": false, + "dpi-awareness": "system", + "disable-theming": false, + "disable-window-filtering": false, + "high-resolution-scrolling-aware": false, + "ultra-high-resolution-scrolling-aware": false, + "long-path-aware": false, + "printer-driver-isolation": false, + "gdi-scaling": false, + "segment-heap": false, + "use-common-controls-v6": false + } + } + }, + "RT_VERSION": { + "#1": { + "0000": { + "fixed": { + "file_version": "0.0.0.0", + "product_version": "0.0.0.0" + }, + "info": { + "0409": { + "Comments": "", + "CompanyName": "Prometheus Community", + "FileDescription": "A Prometheus exporter for Windows machines.", + "FileVersion": "", + "InternalName": "", + "LegalCopyright": "", + "LegalTrademarks": "", + "OriginalFilename": "", + "PrivateBuild": "", + "ProductName": "", + "ProductVersion": "", + "SpecialBuild": "" + } + } + } + } + } +} \ No newline at end of file