Skip to content

Commit 13b7c05

Browse files
Adopt single msi-builder in circle and release script (open-telemetry#210)
1 parent b9a34b7 commit 13b7c05

5 files changed

Lines changed: 102 additions & 92 deletions

File tree

.circleci/config.yml

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ workflows:
237237
filters:
238238
tags:
239239
only: /^v[0-9]+\.[0-9]+\.[0-9]+.*/
240+
- windows-msi-validation:
241+
requires:
242+
- windows-msi
243+
filters:
244+
tags:
245+
only: /^v[0-9]+\.[0-9]+\.[0-9]+.*/
240246

241247
jobs:
242248
setup-environment:
@@ -404,6 +410,7 @@ jobs:
404410
installer-script-test:
405411
machine:
406412
image: ubuntu-1604:202007-01
413+
docker_layer_caching: true
407414
parallelism: 2
408415
steps:
409416
- checkout
@@ -433,30 +440,35 @@ jobs:
433440
- save_pytest_results
434441

435442
windows-msi:
436-
executor:
437-
name: win/default
438-
shell: powershell.exe
443+
machine:
444+
image: ubuntu-1604:202007-01
445+
docker_layer_caching: true
439446
steps:
440447
- attach_to_workspace
441448
- run:
442-
command: mkdir -p dist
443-
- run:
444-
name: Install Wix Toolset
445-
command: .\internal\buildscripts\packaging\msi\make.ps1 Install-Tools
449+
name: Build msi-builder image
450+
command: docker build -t msi-builder internal/buildscripts/packaging/msi/msi-builder
446451
- run:
447452
name: Build MSI
448453
command: |
449-
$Version = if ($env:CIRCLE_TAG -match '^v(\d+\.\d+\.\d+)') { $Matches[1] } else { "0.0.1.$env:CIRCLE_BUILD_NUM" }
450-
.\internal\buildscripts\packaging\msi\make.ps1 New-MSI -Version $Version
451-
Remove-Item -Force -Recurse .\dist -Exclude *.msi
454+
mkdir dist
455+
export VERSION_TAG="${CIRCLE_TAG/v/}"
456+
docker run --rm -v $(pwd):/project -u 0 msi-builder "${VERSION_TAG:-0.0.1.$CIRCLE_BUILD_NUM}"
457+
- persist_to_workspace:
458+
root: ~/
459+
paths: project/dist/*.msi
460+
- store_artifacts:
461+
path: dist
462+
463+
windows-msi-validation:
464+
executor:
465+
name: win/default
466+
shell: powershell.exe
467+
steps:
468+
- attach_to_workspace
452469
- run:
453470
name: Installation test
454471
command: |
455472
$msi_path = Resolve-Path .\dist\splunk-otel-collector*.msi
456473
$env:VERIFY_ACCESS_TOKEN = "false"
457474
.\internal\buildscripts\packaging\installer\install.ps1 -access_token "testing123" -msi_path "$msi_path"
458-
- persist_to_workspace:
459-
root: ~/
460-
paths: project/dist/*.msi
461-
- store_artifacts:
462-
path: dist

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ bin/
22
dist/
33

44
# GoLand IDEA
5-
/.idea/
5+
.idea
66
*.iml
77

88
# VS Code
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM felfert/wix:latest
2+
3+
COPY ./build.sh /work/build.sh
4+
5+
ENV OUTPUT_DIR=project/dist
6+
7+
# `wix` user cannot write to anything outside /work, so run w/ `-u 0` if necessary (circle configuration)
8+
ENTRYPOINT ["bash", "-c", "su wix -c \"/work/build.sh $0 $@ --output /work/build/stage \" && cp /work/build/stage/*.msi $OUTPUT_DIR/"]

internal/buildscripts/packaging/msi/build.sh renamed to internal/buildscripts/packaging/msi/msi-builder/build.sh

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,35 @@
1616

1717
set -euo pipefail
1818

19-
SCRIPT_DIR="$( cd "$( dirname ${BASH_SOURCE[0]} )" && pwd )"
20-
REPO_DIR="$( cd $SCRIPT_DIR/../../../../ && pwd )"
21-
22-
IMAGE_NAME="felfert/wix:latest"
23-
WXS_PATH="./internal/buildscripts/packaging/msi/splunk-otel-collector.wxs"
24-
OTELCOL="./bin/otelcol_windows_amd64.exe"
25-
CONFIG="./cmd/otelcol/config/collector/agent_config.yaml"
26-
FLUENTD_CONFIG="./internal/buildscripts/packaging/fpm/etc/otel/collector/fluentd/fluent.conf"
27-
FLUENTD_CONFD="./internal/buildscripts/packaging/msi/fluentd/conf.d"
28-
OUTPUT_DIR="./dist"
19+
WXS_PATH="/project/internal/buildscripts/packaging/msi/splunk-otel-collector.wxs"
20+
OTELCOL="/project/bin/otelcol_windows_amd64.exe"
21+
CONFIG="/project/cmd/otelcol/config/collector/agent_config.yaml"
22+
FLUENTD_CONFIG="/project/internal/buildscripts/packaging/fpm/etc/otel/collector/fluentd/fluent.conf"
23+
FLUENTD_CONFD="/project/internal/buildscripts/packaging/msi/fluentd/conf.d"
24+
SPLUNK_ICON="/project/internal/buildscripts/packaging/msi/splunk.ico"
25+
OUTPUT_DIR="/project/dist"
2926

3027
usage() {
3128
cat <<EOH >&2
3229
usage: ${BASH_SOURCE[0]} [OPTIONS] VERSION
3330
3431
Description:
35-
Build the MSI with the '$IMAGE_NAME' docker image.
32+
Build the Splunk OpenTelemetry MSI from the project available at /project.
3633
By default, the MSI is saved as '${OUTPUT_DIR}/splunk-otel-collector-VERSION-amd64.msi'.
3734
38-
Required Arguments:
39-
VERSION: The version for the MSI. The version should be in the form "N.N.N" or "N.N.N.N".
40-
4135
OPTIONS:
42-
--otelcol PATH: Relative path from the repo base directory to the otelcol exe.
43-
Defaults to '$OTELCOL'.
44-
--config PATH: Relative path from the repo base directory to the agent config.
45-
Defaults to '$CONFIG'.
46-
--fluentd PATH: Relative path from the repo base directory to the fluentd config.
47-
Defaults to '$FLUENTD_CONFIG'.
48-
--eventlog PATH: Relative path from the repo base directory to the eventlog config.
49-
Defaults to '$EVENTLOG_CONFIG'.
50-
--output DIR: Directory to save the MSI.
51-
Defaults to '$OUTPUT_DIR'.
36+
--otelcol PATH: Absolute path to the otelcol exe.
37+
Defaults to '$OTELCOL'.
38+
--config PATH: Absolute path to the agent config.
39+
Defaults to '$CONFIG'.
40+
--fluentd PATH: Absolute path to the fluentd config.
41+
Defaults to '$FLUENTD_CONFIG'.
42+
--fluentd-confd PATH: Absolute path to the conf.d.
43+
Defaults to '$FLUENTD_CONFD'.
44+
--splunk-icon PATH: Absolute path to the splunk.ico.
45+
Defaults to '$SPLUNK_ICON'.
46+
--output DIR: Directory to save the MSI.
47+
Defaults to '$OUTPUT_DIR'.
5248
5349
EOH
5450
}
@@ -59,6 +55,7 @@ parse_args_and_build() {
5955
local fluentd_config="$FLUENTD_CONFIG"
6056
local fluentd_confd="$FLUENTD_CONFD"
6157
local output="$OUTPUT_DIR"
58+
local splunk_icon="$SPLUNK_ICON"
6259
local version=
6360

6461
while [ -n "${1-}" ]; do
@@ -79,6 +76,10 @@ parse_args_and_build() {
7976
fluentd_confd="$2"
8077
shift 1
8178
;;
79+
--splunk-icon)
80+
splunk_icon="$2"
81+
shift 1
82+
;;
8283
--output)
8384
output="$2"
8485
shift 1
@@ -107,8 +108,8 @@ parse_args_and_build() {
107108
exit 1
108109
fi
109110

110-
docker_run="docker run --rm -v ${REPO_DIR}:/work -w /work $IMAGE_NAME"
111-
build_dir="${output}/build"
111+
set -x
112+
build_dir="/work/build"
112113
files_dir="${build_dir}/msi"
113114
msi_name="splunk-otel-collector-${version}-amd64.msi"
114115

@@ -121,10 +122,27 @@ parse_args_and_build() {
121122
cp "$fluentd_config" "${files_dir}/fluentd/td-agent.conf"
122123
cp "${fluentd_confd}"/*.conf "${files_dir}/fluentd/conf.d/"
123124

124-
$docker_run heat dir "$files_dir" -srd -sreg -gg -template fragment -cg ConfigFiles -dr INSTALLDIR -out "${build_dir}/configfiles.wsx"
125-
$docker_run candle -arch x64 -out "${build_dir}/configfiles.wixobj" "${build_dir}/configfiles.wsx"
126-
$docker_run candle -arch x64 -out "${build_dir}/splunk-otel-collector.wixobj" -dVersion="$version" -dOtelcol="$otelcol" "$WXS_PATH"
127-
$docker_run light -ext WixUtilExtension.dll -sval -out "${output}/${msi_name}" -b "${files_dir}" "${build_dir}/splunk-otel-collector.wixobj" "${build_dir}/configfiles.wixobj"
125+
# kludge to satisfy relative path in splunk-otel-collector.wxs
126+
mkdir -p /work/internal/buildscripts/packaging/msi
127+
cp "${splunk_icon}" "/work/internal/buildscripts/packaging/msi/splunk.ico"
128+
129+
cd /work
130+
configFilesWsx="${build_dir}/configfiles.wsx"
131+
heat dir "$files_dir" -srd -sreg -gg -template fragment -cg ConfigFiles -dr INSTALLDIR -out "${configFilesWsx//\//\\}"
132+
133+
configFilesWixObj="${build_dir}/configfiles.wixobj"
134+
candle -arch x64 -out "${configFilesWixObj//\//\\}" "${configFilesWsx//\//\\}"
135+
136+
collectorWixObj="${build_dir}/splunk-otel-collector.wixobj"
137+
candle -arch x64 -out "${collectorWixObj//\//\\}" -dVersion="$version" -dOtelcol="$otelcol" "${WXS_PATH//\//\\}"
138+
139+
msi="${build_dir}/${msi_name}"
140+
light -ext WixUtilExtension.dll -sval -out "${msi//\//\\}" -b "${files_dir//\//\\}" "${collectorWixObj//\//\\}" "${configFilesWixObj//\//\\}"
141+
142+
mkdir -p $output
143+
cp "${msi}" "${output}/${msi_name}"
144+
{ set +x; } 2>/dev/null
145+
128146
echo "MSI saved to ${output}/${msi_name}"
129147
}
130148

internal/buildscripts/packaging/release/helpers/util.py

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -438,59 +438,31 @@ def build_msi(exe_path, args):
438438
sys.exit(1)
439439
os.remove(msi_path)
440440

441-
client = docker.from_env()
441+
os.makedirs(args.assets_dir, exist_ok=True)
442442

443-
container_options = {
444-
"remove": True,
445-
"volumes": {
446-
REPO_DIR: {"bind": "/work", "mode": "rw"},
447-
},
448-
"working_dir": "/work",
449-
}
443+
client = docker.from_env()
444+
msi_builder_path = os.path.join(REPO_DIR, "internal", "buildscripts", "packaging", "msi", "msi-builder")
445+
msi_builder_image, _ = client.images.build(path=msi_builder_path)
450446

451447
with tempfile.TemporaryDirectory(dir=str(REPO_DIR)) as build_dir:
452-
base_dir = os.path.basename(build_dir)
453-
config_dir = os.path.join(build_dir, "config")
454-
fluentd_dir = os.path.join(config_dir, "fluentd")
455-
os.makedirs(fluentd_dir, exist_ok=True)
456-
shutil.copy(exe_path, os.path.join(build_dir, "otelcol.exe"))
457-
shutil.copy(os.path.join(str(REPO_DIR), MSI_CONFIG), os.path.join(config_dir, "config.yaml"))
458-
shutil.copy(os.path.join(str(REPO_DIR), FLUENTD_CONFIG), os.path.join(fluentd_dir, "td-agent.conf"))
459-
shutil.copytree(os.path.join(str(REPO_DIR), FLUENTD_CONFD), os.path.join(fluentd_dir, "conf.d"))
460-
cont_config_dir = os.path.join(base_dir, "config")
461-
cmd = (
462-
f"heat dir {cont_config_dir} -srd -sreg -gg -template fragment "
463-
f"-cg ConfigFiles -dr INSTALLDIR -out {os.path.join(base_dir, 'configfiles.wsx')}"
464-
)
465-
output = client.containers.run(WIX_IMAGE, command=cmd, **container_options)
466-
print(output.decode("utf-8"))
467-
assert os.path.isfile(os.path.join(build_dir, "configfiles.wsx")), "configfiles.wsx not found!"
468-
cmd = (
469-
f"candle -arch x64 -out {os.path.join(base_dir, 'configfiles.wixobj')} "
470-
f"{os.path.join(base_dir, 'configfiles.wsx')}"
471-
)
472-
output = client.containers.run(WIX_IMAGE, command=cmd, **container_options)
473-
print(output.decode("utf-8"))
474-
assert os.path.isfile(os.path.join(build_dir, "configfiles.wixobj")), "configfiles.wixobj not found!"
475-
cmd = (
476-
f"candle -arch x64 -out {os.path.join(base_dir, 'splunk-otel-collector.wixobj')} "
477-
f'-dVersion="{msi_version}" -dOtelcol="{os.path.join(base_dir, "otelcol.exe")}" {WXS_PATH}'
478-
)
479-
output = client.containers.run(WIX_IMAGE, command=cmd, **container_options)
480-
print(output.decode("utf-8"))
481-
assert os.path.isfile(
482-
os.path.join(build_dir, "splunk-otel-collector.wixobj")
483-
), "splunk-otel-collector.wixobj not found!"
484-
cmd = (
485-
f"light -ext WixUtilExtension.dll -sval -spdb -out {os.path.join(base_dir, msi_name)} "
486-
f"-b {cont_config_dir} {os.path.join(base_dir, 'splunk-otel-collector.wixobj')} "
487-
f"{os.path.join(base_dir, 'configfiles.wixobj')}"
488-
)
489-
output = client.containers.run(WIX_IMAGE, command=cmd, **container_options)
448+
container_options = {
449+
"remove": True,
450+
"volumes": {
451+
REPO_DIR: {"bind": "/project", "mode": "ro"},
452+
build_dir: {"bind": "/work/stage", "mode": "rw"},
453+
},
454+
"user": 0,
455+
"working_dir": "/work",
456+
"environment": {'OUTPUT_DIR': "/work/stage"},
457+
"command": f"{msi_version}",
458+
}
459+
output = client.containers.run(msi_builder_image, **container_options)
490460
print(output.decode("utf-8"))
491461
assert os.path.isfile(os.path.join(build_dir, msi_name)), f"{msi_name} not found!"
492462
os.makedirs(args.assets_dir, exist_ok=True)
493463
os.rename(os.path.join(build_dir, msi_name), msi_path)
464+
assert os.path.isfile(msi_path), f"{msi_name} not found in {args.assets_dir}!"
465+
print(f"Successfully built {msi_path}.")
494466

495467
return msi_path
496468

0 commit comments

Comments
 (0)