Skip to content

Commit 60975fd

Browse files
committed
WIP
1 parent fe718d4 commit 60975fd

File tree

10 files changed

+331
-1
lines changed

10 files changed

+331
-1
lines changed

Diff for: Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: bin/mz-debug

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright Materialize, Inc. and contributors. All rights reserved.
4+
#
5+
# Use of this software is governed by the Business Source License
6+
# included in the LICENSE file at the root of this repository.
7+
#
8+
# As of the Change Date specified in that file, in accordance with
9+
# the Business Source License, use of this software will be governed
10+
# by the Apache License, Version 2.0.
11+
#
12+
# mz-debug -- build and run the Materialize debug tool.
13+
14+
set -euo pipefail
15+
16+
cd "$(dirname "$0")/.."
17+
18+
exec cargo run --bin mz-debug -- "$@"

Diff for: ci/deploy_mz_debug/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Deploy Materialize Language Server Protocol (LSP) Server.
2+
3+
The CI process will build and deploy the LSP server to the binaries S3 bucket.
4+
You can try the process by running the following commands:
5+
6+
```bash
7+
# Set a tag version.
8+
export BUILDKITE_TAG=mz-debug-vx.y.z
9+
10+
# macOS
11+
bin/pyactivate -m ci.deploy_mz_debug.macos
12+
13+
# Linux
14+
bin/pyactivate -m ci.deploy_mz_debug.linux
15+
```

Diff for: ci/deploy_mz_debug/__init__.py

Whitespace-only changes.

Diff for: ci/deploy_mz_debug/deploy_util.py

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Copyright Materialize, Inc. and contributors. All rights reserved.
2+
#
3+
# Use of this software is governed by the Business Source License
4+
# included in the LICENSE file at the root of this repository.
5+
#
6+
# As of the Change Date specified in that file, in accordance with
7+
# the Business Source License, use of this software will be governed
8+
# by the Apache License, Version 2.0.
9+
10+
import os
11+
import tarfile
12+
import tempfile
13+
import time
14+
from pathlib import Path
15+
16+
import boto3
17+
import humanize
18+
19+
from materialize import git
20+
from materialize.mz_version import MzDebugVersion
21+
22+
BINARIES_BUCKET = "materialize-binaries"
23+
TAG = os.environ["BUILDKITE_TAG"]
24+
MZ_DEBUG_VERSION = MzDebugVersion.parse(TAG)
25+
26+
27+
def _tardir(name: str) -> tarfile.TarInfo:
28+
"""Takes a dir path and creates a TarInfo. It sets the
29+
modification time, mode, and type of the dir."""
30+
31+
d = tarfile.TarInfo(name)
32+
d.mtime = int(time.time())
33+
d.mode = 0o40755
34+
d.type = tarfile.DIRTYPE
35+
return d
36+
37+
38+
def _sanitize_tarinfo(tarinfo: tarfile.TarInfo) -> tarfile.TarInfo:
39+
tarinfo.uid = tarinfo.gid = 0
40+
tarinfo.uname = tarinfo.gname = "root"
41+
return tarinfo
42+
43+
44+
def upload_tarball(tarball: Path, platform: str, version: str) -> None:
45+
"""Uploads the tarball (.tar) to the S3 binaries bucket."""
46+
s3_object = f"mz-debug-{version}-{platform}.tar.gz"
47+
boto3.client("s3").upload_file(
48+
Filename=str(tarball),
49+
Bucket=BINARIES_BUCKET,
50+
Key=s3_object,
51+
)
52+
if "aarch64" in platform:
53+
upload_redirect(
54+
f"mz-debug-{version}-{platform.replace('aarch64', 'arm64')}.tar.gz",
55+
f"/{s3_object}",
56+
)
57+
58+
59+
def upload_redirect(key: str, to: str) -> None:
60+
with tempfile.NamedTemporaryFile() as empty:
61+
boto3.client("s3").upload_fileobj(
62+
Fileobj=empty,
63+
Bucket=BINARIES_BUCKET,
64+
Key=key,
65+
ExtraArgs={"WebsiteRedirectLocation": to},
66+
)
67+
68+
69+
def upload_latest_redirect(platform: str, version: str) -> None:
70+
"""Uploads an S3 object containing the latest version number of the package,
71+
not the package itself. This is useful for determining the
72+
latest available version number of the package.
73+
As an example, mz (CLI) uses this information to check if there is a new update available.
74+
"""
75+
upload_redirect(
76+
f"mz-debug-latest-{platform}.tar.gz",
77+
f"/mz-debug-{version}-{platform}.tar.gz",
78+
)
79+
if "aarch64" in platform:
80+
upload_latest_redirect(platform.replace("aarch64", "arm64"), version)
81+
82+
83+
def deploy_tarball(platform: str, lsp: Path) -> None:
84+
tar_path = Path(f"mz-debug-{platform}.tar.gz")
85+
with tarfile.open(str(tar_path), "x:gz") as f:
86+
f.addfile(_tardir("mz/bin"))
87+
f.add(
88+
str(lsp),
89+
arcname="mz/bin/mz-debug",
90+
filter=_sanitize_tarinfo,
91+
)
92+
93+
size = humanize.naturalsize(os.lstat(tar_path).st_size)
94+
print(f"Tarball size: {size}")
95+
96+
upload_tarball(tar_path, platform, f"v{MZ_DEBUG_VERSION.str_without_prefix()}")
97+
if is_latest_version():
98+
upload_latest_redirect(
99+
platform, f"v{MZ_DEBUG_VERSION.str_without_prefix()}"
100+
)
101+
102+
103+
def is_latest_version() -> bool:
104+
latest_version = max(
105+
t
106+
for t in git.get_version_tags(version_type=MzDebugVersion)
107+
if t.prerelease is None
108+
)
109+
return MZ_DEBUG_VERSION == latest_version

Diff for: ci/deploy_mz_debug/linux.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright Materialize, Inc. and contributors. All rights reserved.
2+
#
3+
# Use of this software is governed by the Business Source License
4+
# included in the LICENSE file at the root of this repository.
5+
#
6+
# As of the Change Date specified in that file, in accordance with
7+
# the Business Source License, use of this software will be governed
8+
# by the Apache License, Version 2.0.
9+
10+
import os
11+
from pathlib import Path
12+
13+
from ci.deploy.deploy_util import rust_version
14+
from materialize import mzbuild, spawn, ui
15+
from materialize.mz_version import MzDebugVersion
16+
from materialize.rustc_flags import Sanitizer
17+
18+
from . import deploy_util
19+
from .deploy_util import MZ_DEBUG_VERSION
20+
21+
22+
def main() -> None:
23+
bazel = ui.env_is_truthy("CI_BAZEL_BUILD")
24+
bazel_remote_cache = os.getenv("CI_BAZEL_REMOTE_CACHE")
25+
26+
repo = mzbuild.Repository(
27+
Path("."),
28+
coverage=False,
29+
sanitizer=Sanitizer.none,
30+
bazel=bazel,
31+
bazel_remote_cache=bazel_remote_cache,
32+
)
33+
target = f"{repo.rd.arch}-unknown-linux-gnu"
34+
35+
print("--- Checking version")
36+
assert (
37+
MzDebugVersion.parse_without_prefix(
38+
repo.rd.cargo_workspace.crates["mz-debug"].version_string
39+
)
40+
== MZ_DEBUG_VERSION
41+
)
42+
43+
print("--- Building mz-debug")
44+
# The bin/ci-builder uses target-xcompile as the volume and
45+
# is where the binary release will be available.
46+
path = Path("target-xcompile") / "release" / "mz-debug"
47+
spawn.runv(
48+
["cargo", "build", "--bin", "mz-debug", "--release"],
49+
env=dict(os.environ, RUSTUP_TOOLCHAIN=rust_version()),
50+
)
51+
mzbuild.chmod_x(path)
52+
53+
print(f"--- Uploading {target} binary tarball")
54+
deploy_util.deploy_tarball(target, path)
55+
56+
57+
if __name__ == "__main__":
58+
main()

Diff for: ci/deploy_mz_debug/macos.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright Materialize, Inc. and contributors. All rights reserved.
2+
#
3+
# Use of this software is governed by the Business Source License
4+
# included in the LICENSE file at the root of this repository.
5+
#
6+
# As of the Change Date specified in that file, in accordance with
7+
# the Business Source License, use of this software will be governed
8+
# by the Apache License, Version 2.0.
9+
10+
import os
11+
from pathlib import Path
12+
13+
from materialize import spawn
14+
from materialize.xcompile import Arch
15+
16+
from ..deploy.deploy_util import rust_version
17+
from . import deploy_util
18+
19+
20+
def main() -> None:
21+
target = f"{Arch.host()}-apple-darwin"
22+
23+
print("--- Building mz-debug")
24+
spawn.runv(
25+
["cargo", "build", "--bin", "mz-debug", "--release"],
26+
env=dict(os.environ, RUSTUP_TOOLCHAIN=rust_version()),
27+
)
28+
29+
print(f"--- Uploading {target} binary tarball")
30+
deploy_util.deploy_tarball(target, Path("target") / "release" / "mz-debug")
31+
32+
33+
if __name__ == "__main__":
34+
main()

Diff for: ci/deploy_mz_debug/pipeline.template.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright Materialize, Inc. and contributors. All rights reserved.
2+
#
3+
# Use of this software is governed by the Business Source License
4+
# included in the LICENSE file at the root of this repository.
5+
#
6+
# As of the Change Date specified in that file, in accordance with
7+
# the Business Source License, use of this software will be governed
8+
# by the Apache License, Version 2.0.
9+
10+
# Deploys are fast, do them quickly
11+
priority: 30
12+
13+
steps:
14+
- command: bin/ci-builder run stable bin/pyactivate -m ci.deploy_mz-debug.version
15+
timeout_in_minutes: 30
16+
concurrency: 1
17+
concurrency_group: deploy-mz-debug/version
18+
retry:
19+
manual:
20+
permit_on_passed: true
21+
22+
- id: linux-x86_64
23+
command: bin/ci-builder run stable bin/pyactivate -m ci.deploy_mz-debug.linux
24+
timeout_in_minutes: 30
25+
agents:
26+
queue: linux-x86_64-small
27+
concurrency: 1
28+
concurrency_group: deploy-mz-debug/linux/x86_64
29+
retry:
30+
manual:
31+
permit_on_passed: true
32+
33+
- id: linux-aarch64
34+
command: bin/ci-builder run stable bin/pyactivate -m ci.deploy_mz-debug.linux
35+
timeout_in_minutes: 30
36+
agents:
37+
queue: linux-aarch64-small
38+
concurrency: 1
39+
concurrency_group: deploy-mz-debug/linux/aarch64
40+
retry:
41+
manual:
42+
permit_on_passed: true
43+
44+
- command: bin/pyactivate -m ci.deploy_mz-debug.macos
45+
agents:
46+
queue: mac-x86_64
47+
timeout_in_minutes: 30
48+
concurrency: 1
49+
concurrency_group: deploy-mz-debug/macos/x86_64
50+
retry:
51+
manual:
52+
permit_on_passed: true
53+
54+
- command: bin/pyactivate -m ci.deploy_mz-debug.macos
55+
agents:
56+
queue: mac-aarch64
57+
timeout_in_minutes: 30
58+
concurrency: 1
59+
concurrency_group: deploy-mz-debug/macos/aarch64
60+
retry:
61+
manual:
62+
permit_on_passed: true

Diff for: ci/deploy_mz_debug/version.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright Materialize, Inc. and contributors. All rights reserved.
2+
#
3+
# Use of this software is governed by the Business Source License
4+
# included in the LICENSE file at the root of this repository.
5+
#
6+
# As of the Change Date specified in that file, in accordance with
7+
# the Business Source License, use of this software will be governed
8+
# by the Apache License, Version 2.0.
9+
10+
import boto3
11+
12+
from .deploy_util import BINARIES_BUCKET, MZ_DEBUG_VERSION
13+
14+
15+
def main() -> None:
16+
print("--- Uploading version file")
17+
boto3.client("s3").put_object(
18+
Body=f"{MZ_DEBUG_VERSION.str_without_prefix()}",
19+
Bucket=BINARIES_BUCKET,
20+
Key="mz-debug-latest.version",
21+
ContentType="text/plain",
22+
)
23+
24+
25+
if __name__ == "__main__":
26+
main()

Diff for: misc/python/materialize/mz_version.py

+8
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,11 @@ class MzLspServerVersion(TypedVersionBase):
131131
@classmethod
132132
def get_prefix(cls) -> str:
133133
return "mz-lsp-server-v"
134+
135+
136+
class MzDebugVersion(TypedVersionBase):
137+
"""Version of Materialize Debug Tool"""
138+
139+
@classmethod
140+
def get_prefix(cls) -> str:
141+
return "mz-debug-v"

0 commit comments

Comments
 (0)