build.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env bun
  2. import { $ } from "bun"
  3. const rootDir = new URL("../../..", import.meta.url).pathname
  4. process.chdir(rootDir)
  5. const reg = process.env.REGISTRY ?? "ghcr.io/anomalyco"
  6. const tag = process.env.TAG ?? "24.04"
  7. const push = process.argv.includes("--push") || process.env.PUSH === "1"
  8. const root = new URL("package.json", new URL(rootDir)).pathname
  9. const pkg = await Bun.file(root).json()
  10. const manager = pkg.packageManager ?? ""
  11. const bun = manager.startsWith("bun@") ? manager.slice(4) : ""
  12. if (!bun) throw new Error("packageManager must be bun@<version>")
  13. const images = ["base", "bun-node", "rust", "tauri-linux", "publish"]
  14. for (const name of images) {
  15. const image = `${reg}/build/${name}:${tag}`
  16. const file = `packages/containers/${name}/Dockerfile`
  17. if (name === "base") {
  18. console.log(`docker build -f ${file} -t ${image} .`)
  19. await $`docker build -f ${file} -t ${image} .`
  20. }
  21. if (name === "bun-node") {
  22. console.log(`docker build -f ${file} -t ${image} --build-arg REGISTRY=${reg} --build-arg BUN_VERSION=${bun} .`)
  23. await $`docker build -f ${file} -t ${image} --build-arg REGISTRY=${reg} --build-arg BUN_VERSION=${bun} .`
  24. }
  25. if (name !== "base" && name !== "bun-node") {
  26. console.log(`docker build -f ${file} -t ${image} --build-arg REGISTRY=${reg} .`)
  27. await $`docker build -f ${file} -t ${image} --build-arg REGISTRY=${reg} .`
  28. }
  29. if (push) {
  30. await $`docker push ${image}`
  31. }
  32. }