-- Copyright Epic Games, Inc. All Rights Reserved. import("core.base.option") -------------------------------------------------------------------------------- local function _get_version() local version_file = path.join(os.projectdir(), "VERSION.txt") local version = io.readfile(version_file) if version then version = version:trim() end if not version or version == "" then raise("Failed to read version from VERSION.txt") end return version end -------------------------------------------------------------------------------- function main() local registry = option.get("registry") local tag = option.get("tag") local push = option.get("push") local no_wine = option.get("no-wine") local win_binary = option.get("win-binary") if not tag then tag = _get_version() end local image_name = no_wine and "zenserver-compute-linux" or "zenserver-compute" if registry then image_name = registry .. "/" .. image_name end local full_tag = image_name .. ":" .. tag -- Verify the zenserver binary exists local binary_path = path.join(os.projectdir(), "build/linux/x86_64/release/zenserver") if not os.isfile(binary_path) then raise("zenserver binary not found at %s\nBuild it first with: xmake config -y -m release -a x64 && xmake build -y zenserver", binary_path) end -- Stage Windows binary if provided local win_staging_dir = nil if win_binary then if not os.isfile(win_binary) then raise("Windows binary not found at %s", win_binary) end win_staging_dir = path.join(os.projectdir(), "build/win-binary-staging") os.mkdir(win_staging_dir) os.cp(win_binary, path.join(win_staging_dir, "zenserver.exe")) print("-- Including Windows binary: %s", win_binary) end -- Build the Docker image local dockerfile = path.join(os.projectdir(), "docker/Dockerfile") print("-- Building Docker image: %s", full_tag) local args = {"build", "-t", full_tag, "-f", dockerfile} if no_wine then table.insert(args, "--build-arg") table.insert(args, "INSTALL_WINE=false") end if win_staging_dir then table.insert(args, "--build-arg") table.insert(args, "WIN_BINARY_DIR=build/win-binary-staging") end table.insert(args, os.projectdir()) local ret = os.execv("docker", args) if ret > 0 then raise("Docker build failed") end -- Clean up staging directory if win_staging_dir then os.rmdir(win_staging_dir) end print("-- Built image: %s", full_tag) if push then print("-- Pushing image: %s", full_tag) ret = os.execv("docker", {"push", full_tag}) if ret > 0 then raise("Docker push failed") end print("-- Pushed image: %s", full_tag) end end