Skip to content

Commit

Permalink
fix: hot-reloading and remote builds didn't work on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Jul 12, 2019
1 parent 7efea23 commit 4013335
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
22 changes: 6 additions & 16 deletions garden-service/src/build-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions garden-service/src/plugins/kubernetes/container/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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}`)
Expand Down
9 changes: 6 additions & 3 deletions garden-service/src/plugins/kubernetes/hot-reload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
}

/**
Expand All @@ -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(/\/*$/, "/")
}
Expand Down
5 changes: 5 additions & 0 deletions garden-service/src/util/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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`.
*/
Expand Down

0 comments on commit 4013335

Please sign in to comment.