-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(k8s): make hot reloading respect excludes
Before this fix, hot reloading would sync the entire source directory, including files that are not version controlled. This would cause issues when e.g. `node_modules` were present in the target service. This change should improve performance and stability for hot reloading. BREAKING CHANGE: Hot reloading now uses the tracked file list for its sync, similarly to how the build sync does. This means that untracked files will no longer be synced by hot reloading.
- Loading branch information
Showing
8 changed files
with
162 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { exec } from "./util" | ||
import { LogEntry } from "../logger/log-entry" | ||
import { LogLevel } from "../logger/log-node" | ||
|
||
/** | ||
* Syncs `sourcePath` with `destinationPath` using `syncOpts`. Adds options to `syncOpts` as appropriate for the | ||
* `withDelete` and `files` parameters. | ||
* | ||
* @param destinationPath | ||
* May be a local path or a remote destination. | ||
* @param withDelete | ||
* If `true`, files/folders in `destinationPath` that are not in `sourcePath` will also be deleted. | ||
* @param files | ||
* If provided, only those paths will be synced. Should be relative paths from `sourcePath`. | ||
*/ | ||
export async function syncWithOptions({ | ||
log, | ||
syncOpts, | ||
sourcePath, | ||
destinationPath, | ||
withDelete, | ||
files, | ||
}: { | ||
log: LogEntry | ||
syncOpts: string[] | ||
sourcePath: string | ||
destinationPath: string | ||
withDelete: boolean | ||
files?: string[] | ||
}): Promise<void> { | ||
const opts = [...syncOpts] // We create a new array in case the caller wants to reuse the syncOpts array passed in. | ||
|
||
// rsync benefits from file lists being sorted. | ||
files && files.sort() | ||
|
||
let input: string | undefined | ||
|
||
if (withDelete) { | ||
opts.push("--prune-empty-dirs") | ||
|
||
if (files === undefined) { | ||
opts.push("--delete") | ||
} else { | ||
// Workaround for this issue: https://stackoverflow.com/questions/1813907 | ||
opts.push("--include-from=-", "--exclude=*", "--delete-excluded") | ||
|
||
// -> Make sure the file list is anchored (otherwise filenames are matched as patterns) | ||
files = files.map((f) => "/" + f) | ||
|
||
input = "/**/\n" + files.join("\n") | ||
} | ||
} else if (files !== undefined) { | ||
opts.push("--files-from=-") | ||
input = files.join("\n") | ||
} | ||
|
||
// Avoid rendering the full file list except when at the silly log level | ||
if (log.root.level === LogLevel.silly) { | ||
log.silly(`File list: ${JSON.stringify(files)}`) | ||
log.silly(`Rsync args: ${[...opts, sourcePath, destinationPath].join(" ")}`) | ||
} | ||
|
||
await exec("rsync", [...opts, sourcePath, destinationPath], { input }) | ||
} |
3 changes: 2 additions & 1 deletion
3
garden-service/test/data/test-projects/include-exclude/module-a/garden.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
kind: Module | ||
name: module-a | ||
type: test | ||
include: ["yes.txt"] | ||
include: ["yes.txt", "somedir/*"] | ||
exclude: ["somedir/nope.txt"] |
1 change: 1 addition & 0 deletions
1
garden-service/test/data/test-projects/include-exclude/module-a/somedir/nope.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Go away! |
1 change: 1 addition & 0 deletions
1
garden-service/test/data/test-projects/include-exclude/module-a/somedir/yes.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Oh hai! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters