4// returns the host to use for docker push + registry API calls 5// on LAN: push to dockLanHost (faster, direct); off LAN: push to dockreg_host (external) 6// k8s image tags always use dockLanHost (nodes are always on LAN) 7// registry stores by path so the image is accessible via either hostname 8type GetDockerPushHostProps = { 12 builderClusterName?: string 15const getLanAwareHost = async ({dockreg_host, dockLanHost, cluster_name, builderClusterName}: GetDockerPushHostProps = {}) => { 17 dockreg_host ||= ctx.dockreg_host 18 dockLanHost ||= ctx.dockLanHost 19 cluster_name ||= ctx.cluster_name 20 // a kaniko pod in another cluster can never reach this cluster's LAN VIP (lanHostIpsH are 21 // published in public dns but only route on-site), so dev-machine LAN detection doesn't apply 22 if (builderClusterName && builderClusterName !== cluster_name) return dockreg_host 24 if (!dockLanHost) return dockreg_host 25 const inLan = await isOnSameLan({cluster_name: cluster_name!, nodeIpsExtHost: nodePortsCfg?.nodeIpsExtHost, clusterVip: nodePortsCfg?.lanHostIpsH?.clusterVip}) 26 return inLan ? dockLanHost : dockreg_host 29export const getDockerPushHost = getLanAwareHost 31// rewrites dockLanHost -> dockreg_host in dockerfile content for local builds 32// kaniko/k8s can use LAN hostnames, but local docker needs external 33export const rewriteDfHostForLocalBuild = async (dockerfileContent: string) => { 35 const {dockreg_host, dockLanHost, cluster_name} = ctx 36 if (!dockLanHost || !dockreg_host) return dockerfileContent 38 const inLan = await isOnSameLan({cluster_name: cluster_name!, nodeIpsExtHost: nodePortsCfg?.nodeIpsExtHost, clusterVip: nodePortsCfg?.lanHostIpsH?.clusterVip}) 39 if (inLan) return dockerfileContent 40 return dockerfileContent.replaceAll(dockLanHost, dockreg_host)