Skip to content

Commit 26a131e

Browse files
committed
generate powershell buildscript template
1 parent d614fbf commit 26a131e

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ gen-google-otel-contrib:
6363
regen-google-otel-contrib:
6464
@$(GEN_GOOGLE_OTEL_CONTRIB) -force
6565

66-
GEN_OTELOPSCOL=$(RUN_DISTROGEN) -registry ./registries/operations-collector-registry.yaml -spec ./specs/otelopscol.yaml
66+
GEN_OTELOPSCOL=$(RUN_DISTROGEN) -registry ./registries/operations-collector-registry.yaml -spec ./specs/otelopscol.yaml -custom_templates ./templates/otelopscol
6767
.PHONY: gen-otelopscol
6868
gen-otelopscol:
6969
@$(GEN_OTELOPSCOL)

otelopscol/build.ps1

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#################################################################################
16+
# The build tooling from this repo is designed to be run on Linux. Eventually
17+
# we will be able to do cross-platform builds for the Ops Agent, but for now
18+
# we are still running in a Windows container. This script exists as a stop-gap
19+
# until proper cross-platform builds are possible.
20+
#################################################################################
21+
# This script builds the otelopscol binary with a particular name and path to
22+
# match the expectations of our build tooling. It will do the same thing as
23+
# our Makefiles in this repo do, mainly to ensure there is one source of truth
24+
# in this repo for exactly what version of Go is used to build the binary.
25+
#################################################################################
26+
27+
param (
28+
[string]$jmxHash = "",
29+
[string]$outDir = "."
30+
)
31+
32+
# Set up tools directory.
33+
$toolsDir="" + (Get-Location) + "\.tools" # Powershell moment
34+
New-Item -ItemType Directory -Force -Path $toolsDir | Out-Null
35+
36+
# Download Go.
37+
$goZipPath="./go.windows-amd64.zip"
38+
$goDownloadURL="https://go.dev/dl/go1.23.2.windows-amd64.zip"
39+
Invoke-WebRequest $goDownloadURL -OutFile $goZipPath
40+
Expand-Archive -Path $goZipPath -DestinationPath $toolsDir
41+
Remove-Item $goZipPath
42+
$goBinDir="$toolsDir\go\bin"
43+
$goBin="$goBinDir\go"
44+
45+
# Download OCB.
46+
$installOcbCommand="`$env:GOBIN='$toolsDir'; `$env:CGO_ENABLED=0; $goBin install -trimpath -ldflags='-s -w' go.opentelemetry.io/collector/cmd/[email protected]"
47+
powershell.exe -Command $installOcbCommand
48+
$ocbBin="$toolsDir\builder.exe"
49+
50+
# Generate the collector source.
51+
$ocbGenerateCommand="`$env:PATH='${goBinDir};${PATH}'; `$env:CGO_ENABLED=0; $ocbBin --skip-compilation --verbose --config manifest.yaml"
52+
powershell.exe -Command $ocbGenerateCommand
53+
54+
# Build the collector.
55+
$ldFlags="-s -w"
56+
if ($jmxHash -ne "") {
57+
$ldFlags+=" github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jmxreceiver.MetricsGathererHash=$jmxHash"
58+
}
59+
$collectorBinPath="${outDir}/bin/google-cloud-metrics-agent_windows_amd64.exe"
60+
$buildCollectorCommand="`$env:GOWORK='off'; cd _build; $goBin build -p 32 -buildvcs=false -o='${collectorBinPath}' --ldflags='$ldFlags' ."
61+
powershell.exe -Command $buildCollectorCommand

templates/otelopscol/build.ps1.go.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ $goBinDir="$toolsDir\go\bin"
4343
$goBin="$goBinDir\go"
4444

4545
# Download OCB.
46-
$installOcbCommand="`$env:GOBIN='$toolsDir'; `$env:CGO_ENABLED=0; $goBin install -trimpath -ldflags='-s -w' go.opentelemetry.io/collector/cmd/builder@{{ .OpenTelemetryVersion }}"
46+
$installOcbCommand="`$env:GOBIN='$toolsDir'; `$env:CGO_ENABLED=0; $goBin install -trimpath -ldflags='-s -w' go.opentelemetry.io/collector/cmd/builder@v{{ .OpenTelemetryVersion }}"
4747
powershell.exe -Command $installOcbCommand
4848
$ocbBin="$toolsDir\builder.exe"
4949

0 commit comments

Comments
 (0)