linux.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. import os
  10. from pathlib import Path
  11. from ci import tarball_uploader
  12. from materialize import mzbuild, spawn, ui
  13. from materialize.mz_version import MzCliVersion
  14. from materialize.rustc_flags import Sanitizer
  15. from . import deploy_util
  16. from .deploy_util import APT_BUCKET, MZ_CLI_VERSION
  17. def main() -> None:
  18. bazel = ui.env_is_truthy("CI_BAZEL_BUILD")
  19. bazel_remote_cache = os.getenv("CI_BAZEL_REMOTE_CACHE")
  20. bazel_lto = ui.env_is_truthy("CI_BAZEL_LTO")
  21. repo = mzbuild.Repository(
  22. Path("."),
  23. coverage=False,
  24. sanitizer=Sanitizer.none,
  25. bazel=bazel,
  26. bazel_remote_cache=bazel_remote_cache,
  27. bazel_lto=bazel_lto,
  28. )
  29. target = f"{repo.rd.arch}-unknown-linux-gnu"
  30. print("--- Checking version")
  31. assert (
  32. MzCliVersion.parse_without_prefix(
  33. repo.rd.cargo_workspace.crates["mz"].version_string
  34. )
  35. == MZ_CLI_VERSION
  36. )
  37. print("--- Building mz")
  38. deps = repo.resolve_dependencies([repo.images["mz"]])
  39. deps.ensure()
  40. # Extract the mz binary from the Docker image.
  41. mz = repo.rd.cargo_target_dir() / "release" / "mz"
  42. mz.parent.mkdir(parents=True, exist_ok=True)
  43. with open(mz, "wb") as f:
  44. spawn.runv(
  45. [
  46. "docker",
  47. "run",
  48. "--rm",
  49. "--entrypoint",
  50. "cat",
  51. deps["mz"].spec(),
  52. "/usr/local/bin/mz",
  53. ],
  54. stdout=f,
  55. )
  56. mzbuild.chmod_x(mz)
  57. print(f"--- Uploading {target} binary tarball")
  58. uploader = tarball_uploader.TarballUploader(
  59. package_name="mz",
  60. version=deploy_util.MZ_CLI_VERSION,
  61. )
  62. uploader.deploy_tarball(target, mz)
  63. print("--- Publishing Debian package")
  64. filename = f"mz_{MZ_CLI_VERSION.str_without_prefix()}_{repo.rd.arch.go_str()}.deb"
  65. print(f"Publishing {filename}")
  66. spawn.runv(
  67. [
  68. *repo.rd.build("deb", rustflags=[]),
  69. "--no-build",
  70. "--no-strip",
  71. "--deb-version",
  72. MZ_CLI_VERSION.str_without_prefix(),
  73. '--deb-revision=""',
  74. "-p",
  75. "mz",
  76. "-o",
  77. filename,
  78. ],
  79. cwd=repo.root,
  80. )
  81. # Import our GPG signing key from the environment.
  82. spawn.runv(["gpg", "--import"], stdin=os.environ["GPG_KEY"].encode("ascii"))
  83. # Run deb-s3 to update the repository. No need to upload the file again.
  84. spawn.runv(
  85. [
  86. "deb-s3",
  87. "upload",
  88. "-p",
  89. "--sign",
  90. "-b",
  91. APT_BUCKET,
  92. "-c",
  93. "generic",
  94. filename,
  95. ]
  96. )
  97. if __name__ == "__main__":
  98. main()