Skip to content

Commit

Permalink
misc: finalize asset names for Windows (#108)
Browse files Browse the repository at this point in the history
Finalizes asset names so that all of the following are true:

* The published binary is named `alloy-windows-ARCH.exe`
* The installer is named `alloy-installer-windows-ARCH.exe`
* The default config file path (when the installer is used or in Docker)
  is `%PROGRAMFILES%\GrafanaLabs\Alloy\config.alloy`
* The default data storage path (when the installer is used or in
  Docker) is `%ProgramData%\GrafanaLabs\Alloy\data`
* The installed application is named "Alloy" and runs as a service
  called "Alloy" (both with a capitalized "A")
* Extra settings for the Windows service are stored in the Registry at
  `HKLM\Software\GrafanaLabs\Alloy`
  • Loading branch information
rfratto authored Apr 3, 2024
1 parent c9daa54 commit ac72ca8
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 24 deletions.
6 changes: 3 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ build/
data/
data-agent/
dist/
web/ui/node_modules/
web/ui/build/
internal/web/ui/node_modules/
internal/web/ui/build/
packaging/windows/LICENSE
packaging/windows/agent-windows-amd64.exe
cmd/grafana-agent/Dockerfile
cmd/grafana-agent/Dockerfile
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ data-agent
/dist.temp/
/packaging/windows/LICENSE
/packaging/windows/agent-windows-amd64.exe
web/ui/build
internal/web/ui/build

.DS_Store
buildx-v*
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ RUN ""C:\Program Files\git\bin\bash.exe" -c "go clean -cache -modcache""
# Use the smallest container possible for the final image
FROM mcr.microsoft.com/windows/nanoserver:1809

COPY --from=builder /src/alloy/build/alloy /bin/alloy
COPY --from=builder /src/alloy/example-config.alloy /etc/alloy/config.alloy
COPY --from=builder ["/src/alloy/build/alloy", "C:/Program Files/GrafanaLabs/Alloy/alloy.exe"]
COPY --from=builder ["/src/alloy/example-config.alloy", "C:/Program Files/GrafanaLabs/Alloy/config.alloy"]

ENTRYPOINT ["/bin/alloy"]
ENTRYPOINT ["C:/Program Files/GrafanaLabs/Alloy/alloy.exe"]
ENV ALLOY_DEPLOY_MODE=docker
CMD ["run", "/etc/alloy/config.alloy", "--storage.path=/etc/alloy/data"]
CMD ["run", "C:/Program Files/GrafanaLabs/Alloy/config.alloy", "--storage.path=C:/ProgramData/GrafanaLabs/Alloy/data"]
8 changes: 5 additions & 3 deletions docs/sources/get-started/install/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ docker run \
-v <CONFIG_FILE_PATH>:/etc/alloy/config.alloy \
-p 12345:12345 \
grafana/alloy:latest \
run --server.http.listen-addr=0.0.0.0:12345 /etc/alloy/config.alloy
run --server.http.listen-addr=0.0.0.0:12345 --storage.path=/var/lib/alloy/data \
/etc/alloy/config.alloy
```

Replace the following:
Expand All @@ -55,10 +56,11 @@ To run {{< param "PRODUCT_NAME" >}} as a Windows Docker container, run the follo

```shell
docker run \
-v <CONFIG_FILE_PATH>:C:\etc\alloy\config.alloy \
-v "<CONFIG_FILE_PATH>:C:\Program Files\GrafanaLabs\Alloy\config.alloy" \
-p 12345:12345 \
grafana/alloy:latest-windows \
run --server.http.listen-addr=0.0.0.0:12345 C:\etc\alloy\config.alloy
run --server.http.listen-addr=0.0.0.0:12345 "--storage.path=C:\ProgramData\GrafanaLabs\Alloy\data" \
"C:\Program Files\GrafanaLabs\Alloy\config.alloy"
```

Replace the following:
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/alloy-service/config_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func loadConfig() (*config, error) {
// able to either migrate from the old key to the new key or supporting
// both the old and the new key at the same time.

alloyKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `Software\Grafana\Alloy`, registry.READ)
alloyKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `Software\GrafanaLabs\Alloy`, registry.READ)
if err != nil {
return nil, fmt.Errorf("failed to open registry: %w", err)
}
Expand Down
37 changes: 29 additions & 8 deletions packaging/windows/install_script.nsis
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Unicode true
!include FileFunc.nsh
!include .\macros.nsis

!define APPNAME "Grafana Alloy"
!define APPNAME "Alloy"
!define HELPURL "https://grafana.com/docs/alloy/latest"
!define UPDATEURL "https://github.com/grafana/alloy/releases"
!define ABOUTURL "https://github.com/grafana/alloy"
Expand All @@ -23,8 +23,8 @@ RequestExecutionLevel admin

Name "${APPNAME} ${VERSION}" # Shown in title bar for installer/uninstaller
Icon "logo.ico"
InstallDir "$PROGRAMFILES64\${APPNAME}"
LicenseData ..\..\..\LICENSE
InstallDir "$PROGRAMFILES64\GrafanaLabs\${APPNAME}"
LicenseData ..\..\LICENSE
OutFile "${OUT}"

# Everything must be global Vars
Expand Down Expand Up @@ -70,8 +70,8 @@ Section "install"
Exists:
SetOutPath "$INSTDIR"

File "..\..\..\dist\alloy-windows-amd64.exe"
File "..\..\..\dist.temp\alloy-service-windows-amd64.exe"
File "..\..\dist\alloy-windows-amd64.exe"
File "..\..\dist.temp\alloy-service-windows-amd64.exe"
File "logo.ico"

# Create an uninstaller at the same pathFunctionEnd
Expand All @@ -94,6 +94,7 @@ Section "install"
WriteRegDWORD HKLM "${UNINSTALLKEY}" "NoRepair" 1

Call CreateConfig
Call CreateDataDirectory
Call InitializeRegistry

# Create the service.
Expand Down Expand Up @@ -126,10 +127,30 @@ Function CreateConfig
Return
FunctionEnd

Function CreateDataDirectory
# IfFileExists checks for directories by adding \*.* to the path; this handles
# empty directories as well as directories with files.
IfFileExists "$APPDATA\GrafanaLabs\${APPNAME}\data\*.*" Noop CreateDataDirectory
Noop:
Return
CreateDataDirectory:
CreateDirectory "$APPDATA\GrafanaLabs\${APPNAME}\data"

# Set permissions on the data directory
AccessControl::DisableFileInheritance "$APPDATA\GrafanaLabs\${APPNAME}\data"
AccessControl::SetFileOwner "$APPDATA\GrafanaLabs\${APPNAME}\data" "Administrators"
AccessControl::ClearOnFile "$APPDATA\GrafanaLabs\${APPNAME}\data" "Administrators" "FullAccess"
AccessControl::SetOnFile "$APPDATA\GrafanaLabs\${APPNAME}\data" "SYSTEM" "FullAccess"
AccessControl::GrantOnFile "$APPDATA\GrafanaLabs\${APPNAME}\data" "Everyone" "ListDirectory"
AccessControl::GrantOnFile "$APPDATA\GrafanaLabs\${APPNAME}\data" "Everyone" "ReadAttributes"
Return
FunctionEnd


# InitializeRegistry initializes the keys in the registry that the service
# runner uses. If the registry values already exist, they are not overwritten.
Function InitializeRegistry
!define REGKEY "HKLM\Software\Grafana\Alloy"
!define REGKEY "HKLM\Software\GrafanaLabs\Alloy"

# Define the default key, which points to the service.
nsExec::ExecToLog 'Reg.exe query "${REGKEY}" /reg:64 /ve'
Expand Down Expand Up @@ -162,7 +183,7 @@ Function InitializeRegistry
nsExec::ExecToLog 'Reg.exe query "${REGKEY}" /reg:64 /v Arguments'
Pop $0
${If} $0 == 1
nsExec::ExecToLog 'Reg.exe add "${REGKEY}" /reg:64 /v Arguments /t REG_MULTI_SZ /d "run"\0"$ConfigFlag"\0"--storage.path=$APPDATA\${APPNAME}\data"\0"$DisableReportingFlag$DisableProfilingFlag"'
nsExec::ExecToLog 'Reg.exe add "${REGKEY}" /reg:64 /v Arguments /t REG_MULTI_SZ /d "run"\0"$ConfigFlag"\0"--storage.path=$APPDATA\GrafanaLabs\${APPNAME}\data"\0"$DisableReportingFlag$DisableProfilingFlag"'
Pop $0 # Ignore return result
${EndIf}

Expand Down Expand Up @@ -219,7 +240,7 @@ Section "uninstall"
RMDir /r "$APPDATA\${APPNAME}" # Application data.

# Remove service and uninstaller information from the registry.
nsExec::ExecToLog 'Reg.exe delete "HKLM\SOFTWARE\Grafana\Alloy" /reg:64 /f'
nsExec::ExecToLog 'Reg.exe delete "HKLM\SOFTWARE\GrafanaLabs\Alloy" /reg:64 /f'
Pop $0
nsExec::ExecToLog 'Reg.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" /reg:64 /f'
Pop $0
Expand Down
8 changes: 4 additions & 4 deletions tools/make/packaging.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
PARENT_MAKEFILE := $(firstword $(MAKEFILE_LIST))

.PHONY: dist clean-dist
dist: dist-alloy-binaries dist-alloy-packages dist-alloy-installer
dist: dist-alloy-binaries dist-alloy-packages dist-alloy-installer-windows

clean-dist:
rm -rf ./dist/* ./dist.temp/*
Expand Down Expand Up @@ -184,12 +184,12 @@ endif
# Windows installer
#

.PHONY: dist-alloy-installer
dist-alloy-installer: dist/alloy-windows-amd64.exe dist.temp/alloy-service-windows-amd64.exe
.PHONY: dist-alloy-installer-windows
dist-alloy-installer-windows: dist/alloy-windows-amd64.exe dist.temp/alloy-service-windows-amd64.exe
ifeq ($(USE_CONTAINER),1)
$(RERUN_IN_CONTAINER)
else
# quotes around mkdir are mandatory. ref: https://github.com/grafana/agent/pull/5664#discussion_r1378796371
"mkdir" -p dist
makensis -V4 -DVERSION=$(VERSION) -DOUT="../../../dist/alloy-installer.exe" ./alloy/windows/install_script.nsis
makensis -V4 -DVERSION=$(VERSION) -DOUT="../../dist/alloy-installer-windows-amd64.exe" ./packaging/windows/install_script.nsis
endif

0 comments on commit ac72ca8

Please sign in to comment.