CI: use linux to build msi installers (#95215)

* Build the MSI installers using Linux and wine
This commit is contained in:
Kevin Minehart
2024-10-23 14:26:52 -05:00
committed by GitHub
parent c84b6b783c
commit 66c728d26b
11 changed files with 361 additions and 638 deletions

View File

@ -39,10 +39,6 @@ load(
"scripts/drone/pipelines/verify_storybook.star",
"verify_storybook",
)
load(
"scripts/drone/pipelines/windows.star",
"windows",
)
load(
"scripts/drone/utils/utils.star",
"failure_template",
@ -68,6 +64,8 @@ trigger = {
}
def main_pipelines():
# This is how we should define any new pipelines. At some point we should update existing ones.
# Let's make an effort to reduce the amount of string constants in "depends_on" lists.
pipelines = [
docs_pipelines(ver_mode, trigger_docs_main()),
test_frontend(trigger, ver_mode),
@ -77,7 +75,6 @@ def main_pipelines():
verify_storybook(trigger, ver_mode),
build_e2e(trigger, ver_mode),
integration_tests(trigger, prefix = ver_mode, ver_mode = ver_mode),
windows(trigger, ver_mode = ver_mode),
enterprise_downstream_pipeline(),
notify_pipeline(
name = "main-notify",
@ -88,7 +85,6 @@ def main_pipelines():
"main-test-backend",
"main-build-e2e-publish",
"main-integration-tests",
"main-windows",
],
template = failure_template,
secret = "slack_webhook",

View File

@ -1,66 +0,0 @@
"""
This module contains steps and pipelines relating to creating CI Docker images.
"""
load(
"scripts/drone/utils/utils.star",
"pipeline",
)
load(
"scripts/drone/utils/windows_images.star",
"windows_images",
)
load(
"scripts/drone/vault.star",
"from_secret",
)
def publish_ci_windows_test_image_pipeline():
trigger = {
"event": ["promote"],
"target": ["ci-windows-test-image"],
}
pl = pipeline(
name = "publish-ci-windows-test-image",
trigger = trigger,
platform = "windows",
steps = [
{
"name": "clone",
"image": windows_images["wix"],
"environment": {
"GITHUB_TOKEN": from_secret("github_token"),
},
"commands": [
'git clone "https://$$env:GITHUB_TOKEN@github.com/grafana/grafana-ci-sandbox.git" .',
"git checkout -f $$env:DRONE_COMMIT",
],
},
{
"name": "build-and-publish",
"image": windows_images["windows_server_core"],
"environment": {
"DOCKER_USERNAME": from_secret("docker_username"),
"DOCKER_PASSWORD": from_secret("docker_password"),
},
"commands": [
"cd scripts\\build\\ci-windows-test",
"docker login -u $$env:DOCKER_USERNAME -p $$env:DOCKER_PASSWORD",
"docker build -t grafana/grafana-ci-windows-test:$$env:TAG .",
"docker push grafana/grafana-ci-windows-test:$$env:TAG",
],
"volumes": [
{
"name": "docker",
"path": "//./pipe/docker_engine/",
},
],
},
],
)
pl["clone"] = {
"disable": True,
}
return [pl]

View File

@ -1,85 +0,0 @@
"""
This module returns the pipeline used for building Grafana on Windows.
"""
load(
"scripts/drone/steps/lib_windows.star",
"clone_step_windows",
"get_windows_steps",
"test_backend_step_windows",
"wire_install_step_windows",
)
load(
"scripts/drone/utils/utils.star",
"pipeline",
)
load(
"scripts/drone/utils/windows_images.star",
"windows_images",
)
def windows_test_backend(trigger, edition, ver_mode):
""" Generates a pipeline that runs backend tests on Windows
Args:
trigger: a Drone trigger for the pipeline
edition: controls whether enterprise code is included or not
ver_mode: controls whether a pre-release or actual release pipeline is generated.
Returns:
A single pipeline running backend tests for Windows
"""
environment = {"EDITION": edition}
steps = [
clone_step_windows(),
]
steps.extend([{
"name": "windows-init",
"image": windows_images["go"],
"depends_on": ["clone"],
"commands": [],
}])
steps.extend([
wire_install_step_windows(edition),
test_backend_step_windows(),
])
pl = pipeline(
name = "{}-test-backend-windows".format(ver_mode),
trigger = trigger,
steps = steps,
depends_on = [],
platform = "windows",
environment = environment,
)
pl["clone"] = {
"disable": True,
}
return pl
def windows(trigger, ver_mode):
"""Generates the pipeline used for building Grafana on Windows.
Args:
trigger: a Drone trigger for the pipeline.
ver_mode: controls whether a pre-release or actual release pipeline is generated.
Also indirectly controls which version of enterprise code is used.
Returns:
Drone pipeline.
"""
environment = {"EDITION": "oss"}
return pipeline(
name = "main-windows",
trigger = dict(trigger, repo = ["grafana/grafana"]),
steps = get_windows_steps(ver_mode),
depends_on = [
"main-test-frontend",
"main-test-backend",
"main-build-e2e-publish",
"main-integration-tests",
],
platform = "windows",
environment = environment,
)

View File

@ -20,10 +20,6 @@ load(
"scripts/drone/pipelines/whats_new_checker.star",
"whats_new_checker_pipeline",
)
load(
"scripts/drone/steps/lib_windows.star",
"get_windows_steps",
)
load(
"scripts/drone/utils/images.star",
"images",
@ -49,6 +45,10 @@ load(
"rgm_github_token",
"rgm_storybook_destination",
)
load(
"scripts/drone/windows.star",
"windows_pipeline_release",
)
docs_paths = {
"exclude": [
@ -228,18 +228,6 @@ def rgm_tag():
steps = rgm_run("rgm-build", "drone_build_tag_grafana.sh"),
)
def rgm_tag_windows():
return pipeline(
name = "rgm-tag-prerelease-windows",
trigger = tag_trigger,
steps = get_windows_steps(
ver_mode = "release",
bucket = "grafana-prerelease",
),
depends_on = ["rgm-tag-prerelease"],
platform = "windows",
)
def rgm_version_branch():
# Runs a package / build proces (with all distros) when a commit lands on a version branch
return pipeline(
@ -299,17 +287,23 @@ def rgm_nightly_pipeline():
]
def rgm_tag_pipeline():
build = rgm_tag()
# the Windows step requires an uploaded .zip file to base its compilation on
windows = windows_pipeline_release(trigger = tag_trigger, depends_on = [
build["name"],
])
return [
build,
whats_new_checker_pipeline(tag_trigger),
rgm_tag(),
rgm_tag_windows(),
windows,
verify_release_pipeline(
trigger = tag_trigger,
name = "rgm-tag-verify-prerelease-assets",
bucket = "grafana-prerelease",
depends_on = [
"rgm-tag-prerelease",
"rgm-tag-prerelease-windows",
windows["name"],
build["name"],
],
),
]

View File

@ -1,187 +0,0 @@
"""
This module is a library of Drone steps that exclusively run on windows machines.
"""
load(
"scripts/drone/utils/windows_images.star",
"windows_images",
)
load(
"scripts/drone/variables.star",
"grabpl_version",
)
load(
"scripts/drone/vault.star",
"from_secret",
"gcp_grafanauploads_base64",
"prerelease_bucket",
)
def identify_runner_step_windows():
return {
"name": "identify-runner",
"image": windows_images["1809"],
"commands": [
"echo $env:DRONE_RUNNER_NAME",
],
}
def get_windows_steps(ver_mode, bucket = "%PRERELEASE_BUCKET%"):
"""Generate the list of Windows steps.
Args:
ver_mode: used to differentiate steps for different version modes.
bucket: used to override prerelease bucket.
Returns:
List of Drone steps.
"""
steps = [
identify_runner_step_windows(),
]
init_cmds = [
'$$ProgressPreference = "SilentlyContinue"',
"Invoke-WebRequest https://grafana-downloads.storage.googleapis.com/grafana-build-pipeline/{}/windows/grabpl.exe -OutFile grabpl.exe".format(
grabpl_version,
),
]
steps.extend(
[
{
"name": "windows-init",
"image": windows_images["wix"],
"commands": init_cmds,
},
],
)
if ver_mode in (
"release",
"release-branch",
):
gcp_bucket = "{}/artifacts/downloads".format(bucket)
if ver_mode == "release":
ver_part = "${DRONE_TAG}"
dir = "release"
else:
dir = "main"
gcp_bucket = "grafana-downloads"
build_no = "DRONE_BUILD_NUMBER"
ver_part = "--build-id $$env:{}".format(build_no)
installer_commands = [
"$$gcpKey = $$env:GCP_KEY",
"[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($$gcpKey)) > gcpkey.json",
# gcloud fails to read the file unless converted with dos2unix
"dos2unix gcpkey.json",
"gcloud auth activate-service-account --key-file=gcpkey.json",
"rm gcpkey.json",
"cp C:\\App\\nssm-2.24.zip .",
]
if ver_mode in ("release",):
version = "${DRONE_TAG:1}"
installer_commands.extend(
[
".\\grabpl.exe windows-installer --target {} --edition oss {}".format(
"gs://{}/{}/oss/{}/grafana-{}.windows-amd64.zip".format(gcp_bucket, ver_part, ver_mode, version),
ver_part,
),
'$$fname = ((Get-Childitem grafana*.msi -name) -split "`n")[0]',
],
)
if ver_mode == "main":
installer_commands.extend(
[
"gsutil cp $$fname gs://{}/oss/{}/".format(gcp_bucket, dir),
'gsutil cp "$$fname.sha256" gs://{}/oss/{}/'.format(
gcp_bucket,
dir,
),
],
)
else:
installer_commands.extend(
[
"gsutil cp $$fname gs://{}/{}/oss/{}/".format(
gcp_bucket,
ver_part,
dir,
),
'gsutil cp "$$fname.sha256" gs://{}/{}/oss/{}/'.format(
gcp_bucket,
ver_part,
dir,
),
],
)
steps.append(
{
"name": "build-windows-installer",
"image": windows_images["wix"],
"depends_on": [
"windows-init",
],
"environment": {
"GCP_KEY": from_secret(gcp_grafanauploads_base64),
"PRERELEASE_BUCKET": from_secret(prerelease_bucket),
"GITHUB_TOKEN": from_secret("github_token"),
},
"commands": installer_commands,
},
)
return steps
def download_grabpl_step_windows():
return {
"name": "grabpl",
"image": windows_images["wix"],
"commands": [
'$$ProgressPreference = "SilentlyContinue"',
"Invoke-WebRequest https://grafana-downloads.storage.googleapis.com/grafana-build-pipeline/{}/windows/grabpl.exe -OutFile grabpl.exe".format(
grabpl_version,
),
],
}
def test_backend_step_windows():
# TODO: This is mostly a duplicate of "test_backend_step" in lib.star; but this file can't import that one,
# otherwise it creates an import cycle.
return {
"name": "test-backend",
"image": windows_images["go"],
"depends_on": [
"wire-install",
],
"commands": [
"go test -short -covermode=atomic -timeout=5m ./pkg/...",
],
}
def clone_step_windows():
return {
"name": "clone",
"image": windows_images["wix"],
"environment": {
"GITHUB_TOKEN": from_secret("github_token"),
},
"commands": [
'git clone "https://$$env:GITHUB_TOKEN@github.com/$$env:DRONE_REPO.git" .',
"git checkout -f $$env:DRONE_COMMIT",
],
}
def wire_install_step_windows(edition):
return {
"name": "wire-install",
"image": windows_images["go"],
"commands": [
"go install github.com/google/wire/cmd/wire@v0.5.0",
"wire gen -tags {} ./pkg/server".format(edition),
],
"depends_on": [
"windows-init",
],
}

View File

@ -36,4 +36,5 @@ images = {
"dockerize": "jwilder/dockerize:0.6.1",
"shellcheck": "koalaman/shellcheck:stable",
"rocky": "rockylinux:9",
"wine": "scottyhardy/docker-wine:stable-9.0",
}

View File

@ -1,17 +0,0 @@
"""
This module contains all the windows docker images that are used to build test and publish Grafana.
All the windows images needed to be in a different file than the other images, since they cannot be scanned
by trivy. Related issue: https://github.com/aquasecurity/trivy/issues/1392
"""
load(
"scripts/drone/variables.star",
"golang_version",
)
windows_images = {
"1809": "mcr.microsoft.com/windows:1809",
"wix": "grafana/ci-wix:0.1.1",
"windows_server_core": "docker:windowsservercore-1809",
"go": "golang:{}-windowsservercore-1809".format(golang_version),
}

View File

@ -2,7 +2,7 @@
global variables
"""
grabpl_version = "v3.0.56"
grabpl_version = "v3.1.1"
golang_version = "1.23.1"
# nodejs_version should match what's in ".nvmrc", but without the v prefix.

149
scripts/drone/windows.star Normal file
View File

@ -0,0 +1,149 @@
"""
This module is a library of Drone steps that exclusively run on windows machines.
"""
load(
"scripts/drone/steps/lib.star",
"download_grabpl_step",
)
load(
"scripts/drone/utils/images.star",
"images",
)
load(
"scripts/drone/utils/utils.star",
"pipeline",
)
load(
"scripts/drone/vault.star",
"from_secret",
"rgm_gcp_key_base64",
)
def download_nssm_step():
return {
"name": "downlad-nssm",
"image": images["curl"],
"commands": [
# We don't need to extract nssm-2.24 because the wix / build process extracts it. It just needs to be in
# PWD and be named `nssm-2.24`.
"curl -L0 https://nssm.cc/release/nssm-2.24.zip -o nssm-2.24.zip",
],
}
def download_wix_step():
return {
"name": "download-wix3",
"image": images["curl"],
"commands": [
"mkdir wix3 && cd wix3",
"curl -L0 https://github.com/wixtoolset/wix3/releases/download/wix3141rtm/wix314-binaries.zip -o wix3.zip",
"unzip wix3.zip",
],
}
def download_zip_step(target = ""):
path = "{}/grafana-$${{DRONE_TAG:1}}.windows-amd64.zip".format(target)
return {
"name": "download-zip",
"image": images["cloudsdk"],
"commands": [
"printenv GCP_KEY | base64 -d > /tmp/key.json",
"gcloud auth activate-service-account --key-file=/tmp/key.json",
"bash -c 'gcloud storage cp {} grafana.zip'".format(path),
],
"environment": {
"GCP_KEY": from_secret(rgm_gcp_key_base64),
},
}
def windows_msi_pipeline(target = "", name = "", trigger = {}, depends_on = [], environment = {}):
"""windows_msi_pipeline is a pipeline which creates an MSI from a .zip file.
Args:
target: GCS path (with gs:// scheme) to the oflder containing the zip file
name: Name of the pipeline, should be unique.
trigger: The conditions which trigger the pipeline
depends_on: dependencies (strings)
environment: map of environment variables
Returns:
Drone step.
"""
nssm = download_nssm_step()
wix = download_wix_step()
grabpl = download_grabpl_step()
zip = download_zip_step(target = target)
build = build_msi_step(
depends_on = [
nssm["name"],
wix["name"],
grabpl["name"],
zip["name"],
],
)
upload = upload_msi_step(
depends_on = [
build["name"],
],
target = target,
)
return pipeline(
name = name,
steps = [
nssm,
wix,
zip,
grabpl,
build,
upload,
],
trigger = trigger,
depends_on = depends_on,
environment = environment,
)
def windows_pipeline_release(name = "prerelease-windows-msi", depends_on = [], trigger = {}, environment = {}):
target = "gs://grafana-prerelease/artifacts/downloads/$${DRONE_TAG}/oss/release"
return windows_msi_pipeline(name = name, target = target, depends_on = depends_on, trigger = trigger, environment = environment)
def windows_pipeline_main(depends_on = [], trigger = {}, environment = {}):
target = "gs://grafana-downloads/oss/main"
return windows_msi_pipeline(name = "main-windows-msi", target = target, depends_on = depends_on, trigger = trigger, environment = environment)
def upload_msi_step(depends_on = [], target = ""):
return {
"name": "upload-msi-installer",
"image": images["cloudsdk"],
"commands": [
"printenv GCP_KEY | base64 -d > /tmp/key.json",
"gcloud auth activate-service-account --key-file=/tmp/key.json",
"bash -c 'gcloud storage cp *.msi {}'".format(target),
"bash -c 'gcloud storage cp *.msi.sha256 {}'".format(target),
],
"depends_on": depends_on,
"environment": {
"GCP_KEY": from_secret(rgm_gcp_key_base64),
},
}
def build_msi_step(depends_on = []):
return {
"name": "build-msi",
"image": images["wine"],
"entrypoint": ["/bin/bash"],
"commands": [
"export WINEPATH=$(winepath ./wix3)",
"./bin/grabpl windows-installer --target grafana.zip --edition oss",
],
"depends_on": depends_on,
}
def windows_manual_pipeline():
return windows_pipeline_release(
name = "windows-pipeline-manual",
trigger = {
"event": ["promote"],
"target": "build-msi",
},
)