mirror of https://github.com/grafana/grafana
Refactor starlark to remove references to the build_image (#74624)
* Refactor starlark to remove references to the build_imagepull/74753/head
parent
4f5728233c
commit
915f198ecb
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,187 @@ |
||||
""" |
||||
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 -tags requires_buildifer -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", |
||||
], |
||||
} |
@ -0,0 +1,49 @@ |
||||
""" |
||||
Individual steps that use 'grafana-build' to replace existing individual steps. |
||||
These aren't used in releases. |
||||
""" |
||||
|
||||
# rgm_package_step will create a tar.gz for use in e2e tests or other PR testing related activities.. |
||||
def rgm_package_step(distros = "linux/amd64,linux/arm64", file = "packages.txt"): |
||||
return { |
||||
"name": "rgm-package", |
||||
"image": "grafana/grafana-build:main", |
||||
"depends_on": ["yarn-install"], |
||||
"commands": [ |
||||
"/src/grafana-build package --distro={} ".format(distros) + |
||||
"--yarn-cache=$$YARN_CACHE_FOLDER " + |
||||
"--build-id=$$DRONE_BUILD_NUMBER " + |
||||
"--grafana-dir=$$PWD > {}".format(file), |
||||
], |
||||
"volumes": [{"name": "docker", "path": "/var/run/docker.sock"}], |
||||
} |
||||
|
||||
# rgm_build_backend will create compile the grafana backend for various platforms. It's preferred to use |
||||
# 'rgm_package_step' if you creating a "usable" artifact. This should really only be used to verify that the code is |
||||
# compilable. |
||||
def rgm_build_backend_step(distros = "linux/amd64,linux/arm64"): |
||||
return { |
||||
"name": "rgm-package", |
||||
"image": "grafana/grafana-build:main", |
||||
"commands": [ |
||||
"/src/grafana-build build --distro={} --grafana-dir=$$PWD".format(distros), |
||||
], |
||||
"volumes": [{"name": "docker", "path": "/var/run/docker.sock"}], |
||||
} |
||||
|
||||
def rgm_build_docker_step(packages, ubuntu, alpine, depends_on = ["rgm-package"], file = "docker.txt", tag_format = "{{ .version }}-{{ .arch }}", ubuntu_tag_format = "{{ .version }}-ubuntu-{{ .arch }}"): |
||||
return { |
||||
"name": "rgm-build-docker", |
||||
"image": "grafana/grafana-build:main", |
||||
"commands": [ |
||||
"/src/grafana-build docker " + |
||||
"--package=$(cat {} | grep tar.gz | grep -v docker | grep -v sha256) ".format(packages) + |
||||
"--ubuntu-base={} ".format(ubuntu) + |
||||
"--alpine-base={} ".format(alpine) + |
||||
"--tag-format='{}' ".format(tag_format) + |
||||
"--ubuntu-tag-format='{}' > {}".format(ubuntu_tag_format, file), |
||||
"find ./dist -name '*docker*.tar.gz' -type f | xargs -n1 docker load -i", |
||||
], |
||||
"volumes": [{"name": "docker", "path": "/var/run/docker.sock"}], |
||||
"depends_on": depends_on, |
||||
} |
@ -0,0 +1,9 @@ |
||||
""" |
||||
global variables |
||||
""" |
||||
|
||||
grabpl_version = "v3.0.41" |
||||
golang_version = "1.21.1" |
||||
|
||||
# nodejs_version should match what's in ".nvmrc", but without the v prefix. |
||||
nodejs_version = "18.12.0" |
@ -1,16 +0,0 @@ |
||||
""" |
||||
This module returns the pipeline used for version branches. |
||||
""" |
||||
|
||||
load( |
||||
"scripts/drone/events/release.star", |
||||
"oss_pipelines", |
||||
) |
||||
|
||||
ver_mode = "release-branch" |
||||
trigger = {"ref": ["refs/heads/v[0-9]*"]} |
||||
|
||||
def version_branch_pipelines(): |
||||
return ( |
||||
oss_pipelines(ver_mode = ver_mode, trigger = trigger) |
||||
) |
Loading…
Reference in new issue