diff --git a/garden-service/src/build-dir.ts b/garden-service/src/build-dir.ts index d968131809..c784726e73 100644 --- a/garden-service/src/build-dir.ts +++ b/garden-service/src/build-dir.ts @@ -15,20 +15,12 @@ import { sep, relative, } from "path" -import { - emptyDir, - ensureDir, -} from "fs-extra" +import { emptyDir, ensureDir } from "fs-extra" import { ConfigurationError } from "./exceptions" -import { - FileCopySpec, - Module, - getModuleKey, -} from "./types/module" +import { FileCopySpec, Module, getModuleKey } from "./types/module" import { zip } from "lodash" import * as execa from "execa" -import { platform } from "os" -import { toCygwinPath } from "./util/fs" +import { normalizeLocalRsyncPath } from "./util/fs" import { ModuleConfig } from "./config/module" import { LogEntry } from "./logger/log-entry" @@ -116,11 +108,9 @@ export class BuildDir { const destinationDir = parse(destinationPath).dir await ensureDir(destinationDir) - if (platform() === "win32") { - // this is so that the cygwin-based rsync client can deal with the paths - sourcePath = toCygwinPath(sourcePath) - destinationPath = toCygwinPath(destinationPath) - } + // this is so that the cygwin-based rsync client can deal with the paths + sourcePath = normalizeLocalRsyncPath(sourcePath) + destinationPath = normalizeLocalRsyncPath(destinationPath) // the correct way to copy all contents of a folder is using a trailing slash and not a wildcard sourcePath = stripWildcard(sourcePath) diff --git a/garden-service/src/plugins/kubernetes/container/build.ts b/garden-service/src/plugins/kubernetes/container/build.ts index 00b8b09c52..feda0efe6c 100644 --- a/garden-service/src/plugins/kubernetes/container/build.ts +++ b/garden-service/src/plugins/kubernetes/container/build.ts @@ -25,6 +25,7 @@ import { PluginError } from "../../../exceptions" import { runPod } from "../run" import { getRegistryHostname } from "../init" import { getManifestFromRegistry } from "./util" +import { normalizeLocalRsyncPath } from "../../../util/fs" const dockerDaemonDeploymentName = "garden-docker-daemon" const dockerDaemonContainerName = "docker-daemon" @@ -135,9 +136,10 @@ const remoteBuild: BuildHandler = async (params) => { // -> Run rsync const buildRoot = resolve(module.buildPath, "..") - // This trick is used to automatically create the correct target directory with rsync: + // The '/./' trick is used to automatically create the correct target directory with rsync: // https://stackoverflow.com/questions/1636889/rsync-how-can-i-configure-it-to-create-target-directory-on-server - const src = `${buildRoot}/./${module.name}/` + let src = normalizeLocalRsyncPath(`${buildRoot}/./${module.name}/`) + const destination = `rsync://localhost:${syncFwd.localPort}/volume/${ctx.workingCopyId}/` log.debug(`Syncing from ${src} to ${destination}`) diff --git a/garden-service/src/plugins/kubernetes/hot-reload.ts b/garden-service/src/plugins/kubernetes/hot-reload.ts index 03194d6ad4..4d423f626b 100644 --- a/garden-service/src/plugins/kubernetes/hot-reload.ts +++ b/garden-service/src/plugins/kubernetes/hot-reload.ts @@ -24,6 +24,7 @@ import { getAppNamespace } from "./namespace" import { KubernetesPluginContext } from "./config" import { HotReloadServiceParams, HotReloadServiceResult } from "../../types/plugin/service/hotReloadService" import { KubernetesResource } from "./types" +import { normalizeLocalRsyncPath } from "../../util/fs" export const RSYNC_PORT_NAME = "garden-rsync" @@ -199,9 +200,11 @@ export function removeTrailingSlashes(path: string) { return path.replace(/\/*$/, "") } -export function rsyncSourcePath(modulePath: string, sourcePath: string) { - return resolvePath(modulePath, sourcePath) +function rsyncSourcePath(modulePath: string, sourcePath: string) { + const path = resolvePath(modulePath, sourcePath) .replace(/\/*$/, "/") // ensure (exactly one) trailing slash + + return normalizeLocalRsyncPath(path) } /** @@ -210,7 +213,7 @@ export function rsyncSourcePath(modulePath: string, sourcePath: string) { * Converts /src/foo into src/foo/ * @param target */ -export function rsyncTargetPath(path: string) { +function rsyncTargetPath(path: string) { return path.replace(/^\/*/, "") .replace(/\/*$/, "/") } diff --git a/garden-service/src/util/fs.ts b/garden-service/src/util/fs.ts index b6493a0d5e..a9bb141976 100644 --- a/garden-service/src/util/fs.ts +++ b/garden-service/src/util/fs.ts @@ -15,6 +15,7 @@ import { some } from "lodash" import * as uuid from "uuid" import { join, basename, win32, posix, relative, parse } from "path" import { ValidationError } from "../exceptions" +import { platform } from "os" // NOTE: Importing from ignore/ignore doesn't work on Windows const ignore = require("ignore") @@ -187,6 +188,10 @@ export function toCygwinPath(path: string) { return path.endsWith(win32.sep) ? cygpath + posix.sep : cygpath } +export function normalizeLocalRsyncPath(path: string) { + return platform() === "win32" ? toCygwinPath(path) : path +} + /** * Checks if the given `path` matches any of the given glob `patterns`. */