2021-10-21 11:09:15 +00:00
|
|
|
#!/usr/bin/env python3
|
2022-06-15 11:17:45 +00:00
|
|
|
|
2023-12-18 08:07:22 +00:00
|
|
|
import argparse
|
2023-08-09 16:56:19 +00:00
|
|
|
from pathlib import Path
|
2023-09-01 20:35:31 +00:00
|
|
|
from typing import Tuple
|
2021-10-21 11:09:15 +00:00
|
|
|
import subprocess
|
|
|
|
import logging
|
|
|
|
import sys
|
|
|
|
import time
|
2022-06-15 11:17:45 +00:00
|
|
|
|
2023-02-22 16:01:32 +00:00
|
|
|
from ci_config import CI_CONFIG, BuildConfig
|
2023-12-20 15:37:37 +00:00
|
|
|
from cache_utils import CargoCache
|
2023-12-18 08:07:22 +00:00
|
|
|
|
2022-06-15 11:17:45 +00:00
|
|
|
from env_helper import (
|
2023-11-07 14:56:00 +00:00
|
|
|
GITHUB_JOB_API_URL,
|
2022-06-15 11:17:45 +00:00
|
|
|
REPO_COPY,
|
|
|
|
S3_BUILDS_BUCKET,
|
2022-08-11 13:01:32 +00:00
|
|
|
S3_DOWNLOAD,
|
2022-06-15 11:17:45 +00:00
|
|
|
TEMP_PATH,
|
|
|
|
)
|
2023-08-09 19:12:01 +00:00
|
|
|
from git_helper import Git, git_runner
|
2021-11-26 14:00:09 +00:00
|
|
|
from pr_info import PRInfo
|
2023-09-01 20:35:31 +00:00
|
|
|
from report import BuildResult, FAILURE, StatusType, SUCCESS
|
2023-02-22 16:01:32 +00:00
|
|
|
from s3_helper import S3Helper
|
|
|
|
from tee_popen import TeePopen
|
2023-12-18 08:07:22 +00:00
|
|
|
import docker_images_helper
|
2022-01-12 12:17:21 +00:00
|
|
|
from version_helper import (
|
|
|
|
ClickHouseVersion,
|
|
|
|
get_version_from_repo,
|
|
|
|
update_version_local,
|
|
|
|
)
|
2023-07-30 07:18:06 +00:00
|
|
|
from clickhouse_helper import (
|
|
|
|
ClickHouseHelper,
|
2023-08-29 18:09:15 +00:00
|
|
|
CiLogsCredentials,
|
2023-07-30 07:18:06 +00:00
|
|
|
prepare_tests_results_for_clickhouse,
|
2023-08-09 13:11:17 +00:00
|
|
|
get_instance_type,
|
2023-09-08 23:44:14 +00:00
|
|
|
get_instance_id,
|
2023-07-30 07:18:06 +00:00
|
|
|
)
|
|
|
|
from stopwatch import Stopwatch
|
2021-10-21 11:09:15 +00:00
|
|
|
|
2022-02-08 18:12:04 +00:00
|
|
|
IMAGE_NAME = "clickhouse/binary-builder"
|
2022-06-15 11:17:45 +00:00
|
|
|
BUILD_LOG_NAME = "build_log.log"
|
2022-02-08 18:12:04 +00:00
|
|
|
|
2021-10-21 11:09:15 +00:00
|
|
|
|
2022-01-12 12:17:21 +00:00
|
|
|
def _can_export_binaries(build_config: BuildConfig) -> bool:
|
2023-08-02 16:27:14 +00:00
|
|
|
if build_config.package_type != "deb":
|
2021-10-21 11:09:15 +00:00
|
|
|
return False
|
2023-08-02 16:27:14 +00:00
|
|
|
if build_config.sanitizer != "":
|
2021-10-21 11:09:15 +00:00
|
|
|
return True
|
2023-08-02 16:27:14 +00:00
|
|
|
if build_config.debug_build:
|
2021-10-21 11:09:15 +00:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2022-01-11 11:23:09 +00:00
|
|
|
def get_packager_cmd(
|
2022-01-12 12:17:21 +00:00
|
|
|
build_config: BuildConfig,
|
2023-09-27 14:27:37 +00:00
|
|
|
packager_path: Path,
|
2023-08-09 16:56:19 +00:00
|
|
|
output_path: Path,
|
2023-08-10 17:12:09 +00:00
|
|
|
cargo_cache_dir: Path,
|
2022-01-12 12:17:21 +00:00
|
|
|
build_version: str,
|
|
|
|
image_version: str,
|
2022-03-30 14:29:13 +00:00
|
|
|
official: bool,
|
2022-01-12 12:17:21 +00:00
|
|
|
) -> str:
|
2023-08-02 16:27:14 +00:00
|
|
|
package_type = build_config.package_type
|
|
|
|
comp = build_config.compiler
|
2022-08-27 21:08:01 +00:00
|
|
|
cmake_flags = "-DENABLE_CLICKHOUSE_SELF_EXTRACTING=1"
|
2022-01-11 11:23:09 +00:00
|
|
|
cmd = (
|
2023-08-09 19:12:01 +00:00
|
|
|
f"cd {packager_path} && CMAKE_FLAGS='{cmake_flags}' ./packager "
|
|
|
|
f"--output-dir={output_path} --package-type={package_type} --compiler={comp}"
|
2022-01-11 11:23:09 +00:00
|
|
|
)
|
|
|
|
|
2023-08-02 16:27:14 +00:00
|
|
|
if build_config.debug_build:
|
2023-07-03 15:28:48 +00:00
|
|
|
cmd += " --debug-build"
|
2023-08-02 16:27:14 +00:00
|
|
|
if build_config.sanitizer:
|
|
|
|
cmd += f" --sanitizer={build_config.sanitizer}"
|
|
|
|
if build_config.tidy:
|
2022-01-11 11:23:09 +00:00
|
|
|
cmd += " --clang-tidy"
|
|
|
|
|
2023-03-24 16:24:21 +00:00
|
|
|
cmd += " --cache=sccache"
|
|
|
|
cmd += " --s3-rw-access"
|
|
|
|
cmd += f" --s3-bucket={S3_BUILDS_BUCKET}"
|
2023-08-10 17:12:09 +00:00
|
|
|
cmd += f" --cargo-cache-dir={cargo_cache_dir}"
|
2022-01-11 11:23:09 +00:00
|
|
|
|
2023-08-02 16:27:14 +00:00
|
|
|
if build_config.additional_pkgs:
|
2022-03-14 21:07:58 +00:00
|
|
|
cmd += " --additional-pkgs"
|
2022-01-11 11:23:09 +00:00
|
|
|
|
2022-04-08 17:43:19 +00:00
|
|
|
cmd += f" --docker-image-version={image_version}"
|
2023-08-09 14:00:10 +00:00
|
|
|
cmd += " --with-profiler"
|
2022-04-08 17:43:19 +00:00
|
|
|
cmd += f" --version={build_version}"
|
2021-10-21 11:09:15 +00:00
|
|
|
|
|
|
|
if _can_export_binaries(build_config):
|
2022-01-11 11:23:09 +00:00
|
|
|
cmd += " --with-binaries=tests"
|
2021-10-21 11:09:15 +00:00
|
|
|
|
2022-03-30 14:29:13 +00:00
|
|
|
if official:
|
|
|
|
cmd += " --official"
|
|
|
|
|
2021-10-21 11:09:15 +00:00
|
|
|
return cmd
|
|
|
|
|
2022-01-11 11:23:09 +00:00
|
|
|
|
2022-01-12 12:17:21 +00:00
|
|
|
def build_clickhouse(
|
2023-09-05 10:59:31 +00:00
|
|
|
packager_cmd: str, logs_path: Path, build_output_path: Path
|
2023-09-01 20:35:31 +00:00
|
|
|
) -> Tuple[Path, StatusType]:
|
2023-08-09 16:56:19 +00:00
|
|
|
build_log_path = logs_path / BUILD_LOG_NAME
|
2022-01-12 12:17:21 +00:00
|
|
|
success = False
|
2021-12-03 08:33:16 +00:00
|
|
|
with TeePopen(packager_cmd, build_log_path) as process:
|
|
|
|
retcode = process.wait()
|
2023-08-09 16:56:19 +00:00
|
|
|
if build_output_path.exists():
|
2023-09-27 14:27:37 +00:00
|
|
|
results_exists = any(build_output_path.iterdir())
|
2021-12-14 10:40:03 +00:00
|
|
|
else:
|
2023-09-27 14:27:37 +00:00
|
|
|
results_exists = False
|
2021-12-14 10:40:03 +00:00
|
|
|
|
2021-10-21 11:09:15 +00:00
|
|
|
if retcode == 0:
|
2023-09-27 14:27:37 +00:00
|
|
|
if results_exists:
|
2022-01-12 12:17:21 +00:00
|
|
|
success = True
|
2021-12-14 10:40:03 +00:00
|
|
|
logging.info("Built successfully")
|
|
|
|
else:
|
2022-01-11 11:23:09 +00:00
|
|
|
logging.info(
|
|
|
|
"Success exit code, but no build artifacts => build failed"
|
|
|
|
)
|
2021-10-21 11:09:15 +00:00
|
|
|
else:
|
|
|
|
logging.info("Build failed")
|
2023-09-01 20:35:31 +00:00
|
|
|
return build_log_path, SUCCESS if success else FAILURE
|
2021-10-21 11:09:15 +00:00
|
|
|
|
2021-12-01 14:23:51 +00:00
|
|
|
|
2022-06-15 11:17:45 +00:00
|
|
|
def check_for_success_run(
|
|
|
|
s3_helper: S3Helper,
|
|
|
|
s3_prefix: str,
|
|
|
|
build_name: str,
|
2023-09-01 20:35:31 +00:00
|
|
|
version: ClickHouseVersion,
|
2022-11-15 13:03:16 +00:00
|
|
|
) -> None:
|
2023-09-01 20:35:31 +00:00
|
|
|
# TODO: Remove after S3 artifacts
|
2023-11-20 10:57:46 +00:00
|
|
|
logging.info("Checking for artifacts %s in bucket %s", s3_prefix, S3_BUILDS_BUCKET)
|
2021-12-01 14:23:51 +00:00
|
|
|
try:
|
2023-02-22 16:01:32 +00:00
|
|
|
# Performance artifacts are now part of regular build, so we're safe
|
2022-06-15 11:17:45 +00:00
|
|
|
build_results = s3_helper.list_prefix(s3_prefix)
|
2021-12-01 14:23:51 +00:00
|
|
|
except Exception as ex:
|
2023-11-20 10:57:46 +00:00
|
|
|
logging.info("Got exception while listing %s: %s\nRerun", s3_prefix, ex)
|
2022-06-15 11:17:45 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
if build_results is None or len(build_results) == 0:
|
2023-11-20 10:57:46 +00:00
|
|
|
logging.info("Nothing found in %s, rerun", s3_prefix)
|
2022-06-15 11:17:45 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
logging.info("Some build results found:\n%s", build_results)
|
|
|
|
build_urls = []
|
|
|
|
log_url = ""
|
|
|
|
for url in build_results:
|
|
|
|
url_escaped = url.replace("+", "%2B").replace(" ", "%20")
|
|
|
|
if BUILD_LOG_NAME in url:
|
2022-08-11 13:01:32 +00:00
|
|
|
log_url = f"{S3_DOWNLOAD}/{S3_BUILDS_BUCKET}/{url_escaped}"
|
2022-06-15 11:17:45 +00:00
|
|
|
else:
|
2022-08-11 13:01:32 +00:00
|
|
|
build_urls.append(f"{S3_DOWNLOAD}/{S3_BUILDS_BUCKET}/{url_escaped}")
|
2022-06-15 11:17:45 +00:00
|
|
|
if not log_url:
|
|
|
|
# log is uploaded the last, so if there's no log we need to rerun the build
|
|
|
|
return
|
|
|
|
|
|
|
|
success = len(build_urls) > 0
|
2023-09-01 20:35:31 +00:00
|
|
|
build_result = BuildResult(
|
2022-06-15 11:17:45 +00:00
|
|
|
build_name,
|
|
|
|
log_url,
|
|
|
|
build_urls,
|
2023-09-01 20:35:31 +00:00
|
|
|
version.describe,
|
|
|
|
SUCCESS if success else FAILURE,
|
2022-06-15 11:17:45 +00:00
|
|
|
0,
|
2023-11-07 14:56:00 +00:00
|
|
|
GITHUB_JOB_API_URL(),
|
2022-06-15 11:17:45 +00:00
|
|
|
)
|
2023-11-08 17:18:05 +00:00
|
|
|
result_json_path = build_result.write_json(Path(TEMP_PATH))
|
|
|
|
logging.info(
|
|
|
|
"Build result file %s is written, content:\n %s",
|
|
|
|
result_json_path,
|
|
|
|
result_json_path.read_text(encoding="utf-8"),
|
|
|
|
)
|
2022-06-15 11:17:45 +00:00
|
|
|
# Fail build job if not successeded
|
|
|
|
if not success:
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
sys.exit(0)
|
2021-12-01 14:23:51 +00:00
|
|
|
|
2022-01-11 11:23:09 +00:00
|
|
|
|
2022-05-19 20:37:54 +00:00
|
|
|
def get_release_or_pr(pr_info: PRInfo, version: ClickHouseVersion) -> Tuple[str, str]:
|
2023-03-23 15:56:20 +00:00
|
|
|
"Return prefixes for S3 artifacts paths"
|
2022-05-19 20:37:54 +00:00
|
|
|
# FIXME performance
|
|
|
|
# performance builds are havily relies on a fixed path for artifacts, that's why
|
|
|
|
# we need to preserve 0 for anything but PR number
|
|
|
|
# It should be fixed in performance-comparison image eventually
|
2023-03-23 15:56:20 +00:00
|
|
|
# For performance tests we always set PRs prefix
|
|
|
|
performance_pr = "PRs/0"
|
2022-01-12 12:17:21 +00:00
|
|
|
if "release" in pr_info.labels or "release-lts" in pr_info.labels:
|
|
|
|
# for release pull requests we use branch names prefixes, not pr numbers
|
2022-05-19 20:37:54 +00:00
|
|
|
return pr_info.head_ref, performance_pr
|
2023-03-23 15:56:20 +00:00
|
|
|
if pr_info.number == 0:
|
2022-05-19 20:37:54 +00:00
|
|
|
# for pushes to master - major version
|
|
|
|
return f"{version.major}.{version.minor}", performance_pr
|
2022-01-12 12:17:21 +00:00
|
|
|
# PR number for anything else
|
2023-03-23 15:56:20 +00:00
|
|
|
pr_number = f"PRs/{pr_info.number}"
|
2022-05-19 20:37:54 +00:00
|
|
|
return pr_number, pr_number
|
2022-01-12 12:17:21 +00:00
|
|
|
|
|
|
|
|
2022-01-12 12:17:54 +00:00
|
|
|
def upload_master_static_binaries(
|
|
|
|
pr_info: PRInfo,
|
|
|
|
build_config: BuildConfig,
|
|
|
|
s3_helper: S3Helper,
|
2023-08-09 16:56:19 +00:00
|
|
|
build_output_path: Path,
|
2022-11-15 13:03:16 +00:00
|
|
|
) -> None:
|
2022-01-12 12:17:54 +00:00
|
|
|
"""Upload binary artifacts to a static S3 links"""
|
2023-08-02 16:27:14 +00:00
|
|
|
static_binary_name = build_config.static_binary_name
|
2022-01-12 12:17:54 +00:00
|
|
|
if pr_info.number != 0:
|
|
|
|
return
|
2022-01-13 12:55:51 +00:00
|
|
|
elif not static_binary_name:
|
2022-01-12 13:57:11 +00:00
|
|
|
return
|
2022-01-12 13:30:32 +00:00
|
|
|
elif pr_info.base_ref != "master":
|
2022-01-12 12:17:54 +00:00
|
|
|
return
|
|
|
|
|
2023-11-11 06:27:10 +00:00
|
|
|
# Full binary with debug info:
|
|
|
|
s3_path_full = "/".join((pr_info.base_ref, static_binary_name, "clickhouse-full"))
|
|
|
|
binary_full = build_output_path / "clickhouse"
|
|
|
|
url_full = s3_helper.upload_build_file_to_s3(binary_full, s3_path_full)
|
|
|
|
print(f"::notice ::Binary static URL (with debug info): {url_full}")
|
|
|
|
|
|
|
|
# Stripped binary without debug info:
|
|
|
|
s3_path_compact = "/".join((pr_info.base_ref, static_binary_name, "clickhouse"))
|
|
|
|
binary_compact = build_output_path / "clickhouse-stripped"
|
|
|
|
url_compact = s3_helper.upload_build_file_to_s3(binary_compact, s3_path_compact)
|
|
|
|
print(f"::notice ::Binary static URL (compact): {url_compact}")
|
2022-01-12 12:17:54 +00:00
|
|
|
|
|
|
|
|
2023-12-18 08:07:22 +00:00
|
|
|
def parse_args() -> argparse.Namespace:
|
|
|
|
parser = argparse.ArgumentParser("Clickhouse builder script")
|
|
|
|
parser.add_argument(
|
|
|
|
"build_name",
|
|
|
|
help="build name",
|
|
|
|
)
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
2022-01-12 12:17:21 +00:00
|
|
|
def main():
|
2021-10-21 11:09:15 +00:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
2023-12-18 08:07:22 +00:00
|
|
|
args = parse_args()
|
|
|
|
|
2023-07-30 07:18:06 +00:00
|
|
|
stopwatch = Stopwatch()
|
2023-12-18 08:07:22 +00:00
|
|
|
build_name = args.build_name
|
2021-10-21 11:09:15 +00:00
|
|
|
|
2023-08-02 16:27:14 +00:00
|
|
|
build_config = CI_CONFIG.build_config[build_name]
|
2021-10-21 11:09:15 +00:00
|
|
|
|
2023-08-09 16:56:19 +00:00
|
|
|
temp_path = Path(TEMP_PATH)
|
2023-09-27 14:27:37 +00:00
|
|
|
temp_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
repo_path = Path(REPO_COPY)
|
2021-10-21 11:09:15 +00:00
|
|
|
|
2021-11-26 14:00:09 +00:00
|
|
|
pr_info = PRInfo()
|
2021-10-21 11:09:15 +00:00
|
|
|
|
2023-09-27 14:27:37 +00:00
|
|
|
logging.info("Repo copy path %s", repo_path)
|
2021-10-21 11:09:15 +00:00
|
|
|
|
2022-08-11 13:01:32 +00:00
|
|
|
s3_helper = S3Helper()
|
2021-12-01 14:23:51 +00:00
|
|
|
|
2022-04-12 16:39:02 +00:00
|
|
|
version = get_version_from_repo(git=Git(True))
|
2022-05-19 20:37:54 +00:00
|
|
|
release_or_pr, performance_pr = get_release_or_pr(pr_info, version)
|
2021-12-01 14:23:51 +00:00
|
|
|
|
|
|
|
s3_path_prefix = "/".join((release_or_pr, pr_info.sha, build_name))
|
2022-05-19 20:37:54 +00:00
|
|
|
# FIXME performance
|
|
|
|
s3_performance_path = "/".join(
|
2023-01-09 00:58:42 +00:00
|
|
|
(performance_pr, pr_info.sha, build_name, "performance.tar.zst")
|
2022-05-19 20:37:54 +00:00
|
|
|
)
|
2021-12-01 14:23:51 +00:00
|
|
|
|
2023-12-18 08:07:22 +00:00
|
|
|
# FIXME: to be removed in favor of "skip by job digest"
|
2021-12-01 14:23:51 +00:00
|
|
|
# If this is rerun, then we try to find already created artifacts and just
|
2022-06-15 11:17:45 +00:00
|
|
|
# put them as github actions artifact (result)
|
2023-11-20 10:57:46 +00:00
|
|
|
# The s3_path_prefix has additional "/" in the end to prevent finding
|
|
|
|
# e.g. `binary_darwin_aarch64/clickhouse` for `binary_darwin`
|
|
|
|
check_for_success_run(s3_helper, f"{s3_path_prefix}/", build_name, version)
|
2021-10-21 11:09:15 +00:00
|
|
|
|
2022-01-28 13:39:23 +00:00
|
|
|
logging.info("Got version from repo %s", version.string)
|
2021-11-25 11:19:26 +00:00
|
|
|
|
2022-03-30 14:29:13 +00:00
|
|
|
official_flag = pr_info.number == 0
|
2022-05-13 17:22:23 +00:00
|
|
|
|
2022-01-11 11:23:09 +00:00
|
|
|
version_type = "testing"
|
|
|
|
if "release" in pr_info.labels or "release-lts" in pr_info.labels:
|
|
|
|
version_type = "stable"
|
2022-03-30 14:29:13 +00:00
|
|
|
official_flag = True
|
2021-11-25 11:19:26 +00:00
|
|
|
|
2022-03-30 22:12:35 +00:00
|
|
|
update_version_local(version, version_type)
|
2021-11-25 11:19:26 +00:00
|
|
|
|
|
|
|
logging.info("Updated local files with version")
|
2021-10-21 11:09:15 +00:00
|
|
|
|
2021-10-27 07:03:23 +00:00
|
|
|
logging.info("Build short name %s", build_name)
|
2021-10-21 11:09:15 +00:00
|
|
|
|
2023-08-09 16:56:19 +00:00
|
|
|
build_output_path = temp_path / build_name
|
2023-09-27 14:27:37 +00:00
|
|
|
build_output_path.mkdir(parents=True, exist_ok=True)
|
2023-08-10 17:12:09 +00:00
|
|
|
cargo_cache = CargoCache(
|
|
|
|
temp_path / "cargo_cache" / "registry", temp_path, s3_helper
|
|
|
|
)
|
|
|
|
cargo_cache.download()
|
2021-10-21 11:09:15 +00:00
|
|
|
|
2023-12-18 08:07:22 +00:00
|
|
|
docker_image = docker_images_helper.pull_image(
|
|
|
|
docker_images_helper.get_docker_image(IMAGE_NAME)
|
|
|
|
)
|
|
|
|
|
2022-01-11 11:23:09 +00:00
|
|
|
packager_cmd = get_packager_cmd(
|
|
|
|
build_config,
|
2023-09-27 14:27:37 +00:00
|
|
|
repo_path / "docker" / "packager",
|
2022-01-11 11:23:09 +00:00
|
|
|
build_output_path,
|
2023-08-10 17:12:09 +00:00
|
|
|
cargo_cache.directory,
|
2022-01-28 13:39:23 +00:00
|
|
|
version.string,
|
2023-12-18 08:07:22 +00:00
|
|
|
docker_image.version,
|
2022-04-06 08:15:36 +00:00
|
|
|
official_flag,
|
2022-01-11 11:23:09 +00:00
|
|
|
)
|
2022-03-30 14:29:13 +00:00
|
|
|
|
2021-10-21 11:09:15 +00:00
|
|
|
logging.info("Going to run packager with %s", packager_cmd)
|
|
|
|
|
2023-08-09 19:12:01 +00:00
|
|
|
logs_path = temp_path / "build_log"
|
2023-09-27 14:27:37 +00:00
|
|
|
logs_path.mkdir(parents=True, exist_ok=True)
|
2021-10-21 11:09:15 +00:00
|
|
|
|
2021-10-21 14:41:07 +00:00
|
|
|
start = time.time()
|
2023-09-01 20:35:31 +00:00
|
|
|
log_path, build_status = build_clickhouse(
|
|
|
|
packager_cmd, logs_path, build_output_path
|
|
|
|
)
|
2021-10-21 14:41:07 +00:00
|
|
|
elapsed = int(time.time() - start)
|
2022-01-11 11:23:09 +00:00
|
|
|
subprocess.check_call(
|
|
|
|
f"sudo chown -R ubuntu:ubuntu {build_output_path}", shell=True
|
|
|
|
)
|
2023-09-01 20:35:31 +00:00
|
|
|
logging.info("Build finished as %s, log path %s", build_status, log_path)
|
|
|
|
if build_status == SUCCESS:
|
2023-08-10 17:12:09 +00:00
|
|
|
cargo_cache.upload()
|
2023-09-01 20:35:31 +00:00
|
|
|
else:
|
2023-06-08 09:51:57 +00:00
|
|
|
# We check if docker works, because if it's down, it's infrastructure
|
|
|
|
try:
|
|
|
|
subprocess.check_call("docker info", shell=True)
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
logging.error(
|
|
|
|
"The dockerd looks down, won't upload anything and generate report"
|
|
|
|
)
|
|
|
|
sys.exit(1)
|
2021-10-21 11:09:15 +00:00
|
|
|
|
2022-05-19 20:37:54 +00:00
|
|
|
# FIXME performance
|
2022-05-19 20:44:10 +00:00
|
|
|
performance_urls = []
|
2023-08-09 16:56:19 +00:00
|
|
|
performance_path = build_output_path / "performance.tar.zst"
|
|
|
|
if performance_path.exists():
|
2022-05-19 20:44:10 +00:00
|
|
|
performance_urls.append(
|
2022-05-19 20:37:54 +00:00
|
|
|
s3_helper.upload_build_file_to_s3(performance_path, s3_performance_path)
|
|
|
|
)
|
|
|
|
logging.info(
|
2023-01-09 00:58:42 +00:00
|
|
|
"Uploaded performance.tar.zst to %s, now delete to avoid duplication",
|
2022-05-19 20:44:10 +00:00
|
|
|
performance_urls[0],
|
2022-05-19 20:37:54 +00:00
|
|
|
)
|
2023-09-27 14:27:37 +00:00
|
|
|
performance_path.unlink()
|
2022-05-19 20:37:54 +00:00
|
|
|
|
2022-05-19 20:44:10 +00:00
|
|
|
build_urls = (
|
2023-08-29 14:35:53 +00:00
|
|
|
s3_helper.upload_build_directory_to_s3(
|
2022-05-19 20:44:10 +00:00
|
|
|
build_output_path,
|
|
|
|
s3_path_prefix,
|
|
|
|
keep_dirs_in_s3_path=False,
|
|
|
|
upload_symlinks=False,
|
|
|
|
)
|
|
|
|
+ performance_urls
|
2022-01-11 11:23:09 +00:00
|
|
|
)
|
2021-10-21 12:37:19 +00:00
|
|
|
logging.info("Got build URLs %s", build_urls)
|
2021-10-21 12:46:25 +00:00
|
|
|
|
2022-01-11 11:23:09 +00:00
|
|
|
print("::notice ::Build URLs: {}".format("\n".join(build_urls)))
|
2021-10-21 12:46:25 +00:00
|
|
|
|
2023-08-09 16:56:19 +00:00
|
|
|
if log_path.exists():
|
2022-06-15 11:17:45 +00:00
|
|
|
log_url = s3_helper.upload_build_file_to_s3(
|
2023-08-09 16:56:19 +00:00
|
|
|
log_path, s3_path_prefix + "/" + log_path.name
|
2022-06-15 11:17:45 +00:00
|
|
|
)
|
|
|
|
logging.info("Log url %s", log_url)
|
|
|
|
else:
|
|
|
|
logging.info("Build log doesn't exist")
|
|
|
|
|
2022-04-08 17:43:19 +00:00
|
|
|
print(f"::notice ::Log URL: {log_url}")
|
2021-10-21 11:09:15 +00:00
|
|
|
|
2023-09-01 20:35:31 +00:00
|
|
|
build_result = BuildResult(
|
|
|
|
build_name,
|
|
|
|
log_url,
|
|
|
|
build_urls,
|
|
|
|
version.describe,
|
|
|
|
build_status,
|
|
|
|
elapsed,
|
2023-11-07 14:56:00 +00:00
|
|
|
GITHUB_JOB_API_URL(),
|
2023-09-01 20:35:31 +00:00
|
|
|
)
|
|
|
|
result_json_path = build_result.write_json(temp_path)
|
|
|
|
logging.info(
|
|
|
|
"Build result file %s is written, content:\n %s",
|
|
|
|
result_json_path,
|
|
|
|
result_json_path.read_text(encoding="utf-8"),
|
2022-01-11 11:23:09 +00:00
|
|
|
)
|
2022-01-12 12:17:54 +00:00
|
|
|
|
|
|
|
upload_master_static_binaries(pr_info, build_config, s3_helper, build_output_path)
|
2023-07-30 07:18:06 +00:00
|
|
|
|
2023-08-09 13:11:17 +00:00
|
|
|
# Upload profile data
|
2023-08-09 19:12:01 +00:00
|
|
|
ch_helper = ClickHouseHelper()
|
2023-08-09 13:11:17 +00:00
|
|
|
|
2023-08-29 18:09:15 +00:00
|
|
|
ci_logs_credentials = CiLogsCredentials(Path("/dev/null"))
|
|
|
|
if ci_logs_credentials.host:
|
2023-08-09 19:12:01 +00:00
|
|
|
instance_type = get_instance_type()
|
2023-09-08 23:44:14 +00:00
|
|
|
instance_id = get_instance_id()
|
2023-08-09 19:12:01 +00:00
|
|
|
query = f"""INSERT INTO build_time_trace
|
|
|
|
(
|
|
|
|
pull_request_number,
|
|
|
|
commit_sha,
|
|
|
|
check_start_time,
|
|
|
|
check_name,
|
|
|
|
instance_type,
|
2023-09-08 23:44:14 +00:00
|
|
|
instance_id,
|
2023-08-09 19:12:01 +00:00
|
|
|
file,
|
|
|
|
library,
|
|
|
|
time,
|
|
|
|
pid,
|
|
|
|
tid,
|
|
|
|
ph,
|
|
|
|
ts,
|
|
|
|
dur,
|
|
|
|
cat,
|
|
|
|
name,
|
|
|
|
detail,
|
|
|
|
count,
|
|
|
|
avgMs,
|
|
|
|
args_name
|
|
|
|
)
|
2023-09-08 23:44:14 +00:00
|
|
|
SELECT {pr_info.number}, '{pr_info.sha}', '{stopwatch.start_time_str}', '{build_name}', '{instance_type}', '{instance_id}', *
|
2023-08-09 19:12:01 +00:00
|
|
|
FROM input('
|
|
|
|
file String,
|
|
|
|
library String,
|
|
|
|
time DateTime64(6),
|
|
|
|
pid UInt32,
|
|
|
|
tid UInt32,
|
|
|
|
ph String,
|
|
|
|
ts UInt64,
|
|
|
|
dur UInt64,
|
|
|
|
cat String,
|
|
|
|
name String,
|
|
|
|
detail String,
|
|
|
|
count UInt64,
|
|
|
|
avgMs UInt64,
|
|
|
|
args_name String')
|
|
|
|
FORMAT JSONCompactEachRow"""
|
|
|
|
|
|
|
|
auth = {
|
|
|
|
"X-ClickHouse-User": "ci",
|
2023-08-29 18:09:15 +00:00
|
|
|
"X-ClickHouse-Key": ci_logs_credentials.password,
|
2023-08-09 19:12:01 +00:00
|
|
|
}
|
2023-08-29 18:09:15 +00:00
|
|
|
url = f"https://{ci_logs_credentials.host}/"
|
2023-08-09 19:12:01 +00:00
|
|
|
profiles_dir = temp_path / "profiles_source"
|
2023-09-27 14:27:37 +00:00
|
|
|
profiles_dir.mkdir(parents=True, exist_ok=True)
|
2023-11-20 13:22:02 +00:00
|
|
|
logging.info(
|
|
|
|
"Processing profile JSON files from %s", repo_path / "build_docker"
|
|
|
|
)
|
2023-08-09 19:12:01 +00:00
|
|
|
git_runner(
|
|
|
|
"./utils/prepare-time-trace/prepare-time-trace.sh "
|
|
|
|
f"build_docker {profiles_dir.absolute()}"
|
2023-08-09 13:11:17 +00:00
|
|
|
)
|
2023-08-09 19:12:01 +00:00
|
|
|
profile_data_file = temp_path / "profile.json"
|
|
|
|
with open(profile_data_file, "wb") as profile_fd:
|
2023-11-12 03:01:59 +00:00
|
|
|
for profile_source in profiles_dir.iterdir():
|
2023-11-12 07:07:14 +00:00
|
|
|
if profile_source.name != "binary_sizes.txt":
|
2023-11-12 03:52:49 +00:00
|
|
|
with open(profiles_dir / profile_source, "rb") as ps_fd:
|
|
|
|
profile_fd.write(ps_fd.read())
|
2023-08-09 13:11:17 +00:00
|
|
|
|
2023-08-09 19:12:01 +00:00
|
|
|
logging.info(
|
|
|
|
"::notice ::Log Uploading profile data, path: %s, size: %s, query: %s",
|
|
|
|
profile_data_file,
|
|
|
|
profile_data_file.stat().st_size,
|
|
|
|
query,
|
|
|
|
)
|
|
|
|
ch_helper.insert_file(url, auth, query, profile_data_file)
|
2023-08-09 13:11:17 +00:00
|
|
|
|
2023-11-12 03:01:59 +00:00
|
|
|
query = f"""INSERT INTO binary_sizes
|
|
|
|
(
|
|
|
|
pull_request_number,
|
|
|
|
commit_sha,
|
|
|
|
check_start_time,
|
|
|
|
check_name,
|
|
|
|
instance_type,
|
|
|
|
instance_id,
|
|
|
|
file,
|
|
|
|
size
|
|
|
|
)
|
|
|
|
SELECT {pr_info.number}, '{pr_info.sha}', '{stopwatch.start_time_str}', '{build_name}', '{instance_type}', '{instance_id}', file, size
|
|
|
|
FROM input('size UInt64, file String')
|
|
|
|
SETTINGS format_regexp = '^\\s*(\\d+) (.+)$'
|
2023-11-13 04:06:37 +00:00
|
|
|
FORMAT Regexp"""
|
|
|
|
|
2023-11-13 02:14:29 +00:00
|
|
|
binary_sizes_file = profiles_dir / "binary_sizes.txt"
|
2023-11-12 03:01:59 +00:00
|
|
|
|
|
|
|
logging.info(
|
|
|
|
"::notice ::Log Uploading binary sizes data, path: %s, size: %s, query: %s",
|
|
|
|
binary_sizes_file,
|
|
|
|
binary_sizes_file.stat().st_size,
|
|
|
|
query,
|
|
|
|
)
|
|
|
|
ch_helper.insert_file(url, auth, query, binary_sizes_file)
|
|
|
|
|
2023-08-09 13:11:17 +00:00
|
|
|
# Upload statistics to CI database
|
2023-07-30 07:18:06 +00:00
|
|
|
prepared_events = prepare_tests_results_for_clickhouse(
|
|
|
|
pr_info,
|
|
|
|
[],
|
2023-09-01 20:35:31 +00:00
|
|
|
build_status,
|
2023-07-30 07:18:06 +00:00
|
|
|
stopwatch.duration_seconds,
|
|
|
|
stopwatch.start_time_str,
|
|
|
|
log_url,
|
|
|
|
f"Build ({build_name})",
|
|
|
|
)
|
|
|
|
ch_helper.insert_events_into(db="default", table="checks", events=prepared_events)
|
|
|
|
|
|
|
|
# Fail the build job if it didn't succeed
|
2023-09-01 20:35:31 +00:00
|
|
|
if build_status != SUCCESS:
|
2021-11-25 10:01:29 +00:00
|
|
|
sys.exit(1)
|
2022-01-12 12:17:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|