build.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env bun
  2. import { $ } from "bun"
  3. import path from "path"
  4. import { fileURLToPath } from "url"
  5. const rootDir = fileURLToPath(new URL("../../..", import.meta.url))
  6. process.chdir(rootDir)
  7. const reg = process.env.REGISTRY ?? "ghcr.io/kilo-org" // kilocode_change
  8. const tag = process.env.TAG ?? "24.04"
  9. const push = process.argv.includes("--push") || process.env.PUSH === "1"
  10. const root = path.join(rootDir, "package.json")
  11. const pkg = await Bun.file(root).json()
  12. const manager = pkg.packageManager ?? ""
  13. const bun = manager.startsWith("bun@") ? manager.slice(4) : ""
  14. if (!bun) throw new Error("packageManager must be bun@<version>")
  15. const images = ["base", "bun-node", "rust", "tauri-linux", "publish"]
  16. const setup = async () => {
  17. if (!push) return
  18. const list = await $`docker buildx ls`.text()
  19. // kilocode_change start
  20. if (list.includes("kilo")) {
  21. await $`docker buildx use kilo`
  22. return
  23. }
  24. await $`docker buildx create --name kilo --use`
  25. // kilocode_change end
  26. }
  27. await setup()
  28. const platform = "linux/amd64,linux/arm64"
  29. for (const name of images) {
  30. const image = `${reg}/build/${name}:${tag}`
  31. const file = `packages/containers/${name}/Dockerfile`
  32. if (name === "base") {
  33. if (push) {
  34. console.log(`docker buildx build --platform ${platform} -f ${file} -t ${image} --push .`)
  35. await $`docker buildx build --platform ${platform} -f ${file} -t ${image} --push .`
  36. }
  37. if (!push) {
  38. console.log(`docker build -f ${file} -t ${image} .`)
  39. await $`docker build -f ${file} -t ${image} .`
  40. }
  41. }
  42. if (name === "bun-node") {
  43. if (push) {
  44. console.log(
  45. `docker buildx build --platform ${platform} -f ${file} -t ${image} --build-arg REGISTRY=${reg} --build-arg BUN_VERSION=${bun} --push .`,
  46. )
  47. await $`docker buildx build --platform ${platform} -f ${file} -t ${image} --build-arg REGISTRY=${reg} --build-arg BUN_VERSION=${bun} --push .`
  48. }
  49. if (!push) {
  50. console.log(`docker build -f ${file} -t ${image} --build-arg REGISTRY=${reg} --build-arg BUN_VERSION=${bun} .`)
  51. await $`docker build -f ${file} -t ${image} --build-arg REGISTRY=${reg} --build-arg BUN_VERSION=${bun} .`
  52. }
  53. }
  54. if (name !== "base" && name !== "bun-node") {
  55. if (push) {
  56. console.log(
  57. `docker buildx build --platform ${platform} -f ${file} -t ${image} --build-arg REGISTRY=${reg} --push .`,
  58. )
  59. await $`docker buildx build --platform ${platform} -f ${file} -t ${image} --build-arg REGISTRY=${reg} --push .`
  60. }
  61. if (!push) {
  62. console.log(`docker build -f ${file} -t ${image} --build-arg REGISTRY=${reg} .`)
  63. await $`docker build -f ${file} -t ${image} --build-arg REGISTRY=${reg} .`
  64. }
  65. }
  66. if (push) {
  67. console.log(`pushed ${image}`)
  68. }
  69. }