Skip to content

Commit

Permalink
fix(sync-mode): use the same source path schemas for all action types (
Browse files Browse the repository at this point in the history
…#5363)

* refactor(container): extract named function for sync source path schema

* fix(sync-mode): use the same source path schemas for all action types

* docs(reference): re-generated docs

* test(windows): always test sync mode config validation on Windows

* docs: update source path description
  • Loading branch information
vvagaytsev committed Nov 14, 2023
1 parent da3f68f commit 71b3781
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 46 deletions.
18 changes: 17 additions & 1 deletion .circleci/continue-config.yml
Expand Up @@ -1084,9 +1084,25 @@ jobs:
command: |
.\dist\windows-amd64\garden.exe deploy --root .\examples\demo-project\ --logger-type basic --log-level silly --env remote --force-build --var userId=$env:CIRCLE_BUILD_NUM-win
- run:
name: Cleanup
name: Cleanup demo-project
command: (kubectl delete namespace --wait=false demo-project-testing-$env:CIRCLE_BUILD_NUM-win) -or $true
when: always
- run:
name: Validate vote-helm project # to validate the sync mode paths on Windows with action-based configs
command: |
.\dist\windows-amd64\garden.exe validate --root .\e2e\projects\vote-helm\ --logger-type basic --log-level silly --env testing --var userId=$env:CIRCLE_BUILD_NUM-win
- run:
name: Cleanup vote-helm project
command: (kubectl delete namespace --wait=false vote-helm-testing-$env:CIRCLE_BUILD_NUM-win) -or $true
when: always
- run:
name: Validate vote-helm-modules project # to validate the sync mode paths on Windows with module-based configs
command: |
.\dist\windows-amd64\garden.exe validate --root .\e2e\projects\vote-helm-modules\ --logger-type basic --log-level silly --env testing --var userId=$env:CIRCLE_BUILD_NUM-win
- run:
name: Cleanup vote-helm-modules project
command: (kubectl delete namespace --wait=false vote-helm-modules-testing-$env:CIRCLE_BUILD_NUM-win) -or $true
when: always
- fail_fast

workflows:
Expand Down
32 changes: 23 additions & 9 deletions core/src/plugins/container/config.ts
Expand Up @@ -31,6 +31,7 @@ import type { RunAction, RunActionConfig } from "../../actions/run.js"
import { memoize } from "lodash-es"
import type Joi from "@hapi/joi"
import type { OctalPermissionMask } from "../kubernetes/types.js"
import { templateStringLiteral } from "../../docs/common.js"

export const defaultDockerfileName = "Dockerfile"

Expand Down Expand Up @@ -237,6 +238,27 @@ export const syncDefaultGroupSchema = memoize(() =>
.description("Set the default group on files and directories at the target. " + ownerDocs)
)

const exampleActionRef = templateStringLiteral("actions.build.my-container-image.sourcePath")
const backSlash = "`\\`"
const forwardSlash = "`/`"

export const syncSourcePathSchema = memoize(() =>
joi
.string()
.default(".")
.description(
deline`
Path to a local directory to be synchronized with the target.
This should generally be a templated path to another action's source path (e.g. ${exampleActionRef}), or a relative path.
If a path is hard-coded, we recommend sticking with relative paths here, and using forward slashes (${forwardSlash}) as a delimiter, as Windows-style paths with back slashes (${backSlash}) and absolute paths will work on some platforms, but they are not portable and will not work for users on other platforms.
Defaults to the Deploy action's config's directory if no value is provided.
`
)
.example("src")
)
export const syncTargetPathSchema = memoize(() =>
joi
.posixPath()
Expand All @@ -254,15 +276,7 @@ export const syncTargetPathSchema = memoize(() =>
const containerSyncSchema = createSchema({
name: "container-sync",
keys: () => ({
source: joi
.string()
.default(".")
.description(
deline`
POSIX-style or Windows path of the directory to sync to the target. Defaults to the config's directory if no value is provided.
`
)
.example("src"),
source: syncSourcePathSchema(),
target: syncTargetPathSchema(),
exclude: syncExcludeSchema(),
mode: syncModeSchema(),
Expand Down
15 changes: 2 additions & 13 deletions core/src/plugins/kubernetes/sync.ts
Expand Up @@ -24,6 +24,7 @@ import {
syncDefaultOwnerSchema,
syncExcludeSchema,
syncModeSchema,
syncSourcePathSchema,
syncTargetPathSchema,
} from "../container/moduleConfig.js"
import { dedent, gardenAnnotationKey } from "../../util/string.js"
Expand Down Expand Up @@ -58,7 +59,6 @@ import type { PluginContext } from "../../plugin-context.js"
import type { SyncConfig, SyncSession } from "../../mutagen.js"
import { mutagenAgentPath, Mutagen, haltedStatuses, mutagenStatusDescriptions } from "../../mutagen.js"
import { k8sSyncUtilImageName } from "./constants.js"
import { templateStringLiteral } from "../../docs/common.js"
import { relative, resolve } from "path"
import type { Resolved } from "../../actions/types.js"
import { isAbsolute } from "path"
Expand Down Expand Up @@ -136,25 +136,14 @@ export interface KubernetesDeployDevModeSyncSpec extends DevModeSyncOptions {
containerName?: string
}

const exampleActionRef = templateStringLiteral("actions.build.my-container-image.sourcePath")

export const kubernetesDeploySyncPathSchema = () =>
joi
.object()
.keys({
target: targetResourceSpecSchema().description(
"The Kubernetes resource to sync to. If specified, this is used instead of `spec.defaultTarget`."
),
sourcePath: joi
.posixPath()
.default(".")
.description(
dedent`
The local path to sync from, either absolute or relative to the source directory where the Deploy action is defined.
This should generally be a templated path to another action's source path (e.g. ${exampleActionRef}), or a relative path. If a path is hard-coded, you must make sure the path exists, and that it is reliably the correct path for every user.
`
),
sourcePath: syncSourcePathSchema(),
containerPath: syncTargetPathSchema(),

exclude: syncExcludeSchema(),
Expand Down
5 changes: 4 additions & 1 deletion docs/reference/action-types/Deploy/container.md
Expand Up @@ -556,7 +556,10 @@ Specify one or more source files or directories to automatically sync with the r

[spec](#spec) > [sync](#specsync) > [paths](#specsyncpaths) > source

POSIX-style or Windows path of the directory to sync to the target. Defaults to the config's directory if no value is provided.
Path to a local directory to be synchronized with the target.
This should generally be a templated path to another action's source path (e.g. `${actions.build.my-container-image.sourcePath}`), or a relative path.
If a path is hard-coded, we recommend sticking with relative paths here, and using forward slashes (`/`) as a delimiter, as Windows-style paths with back slashes (`\`) and absolute paths will work on some platforms, but they are not portable and will not work for users on other platforms.
Defaults to the Deploy action's config's directory if no value is provided.

| Type | Default | Required |
| -------- | ------- | -------- |
Expand Down
22 changes: 17 additions & 5 deletions docs/reference/action-types/Deploy/helm.md
Expand Up @@ -647,13 +647,25 @@ The name of a container in the target. Specify this if the target contains more

[spec](#spec) > [sync](#specsync) > [paths](#specsyncpaths) > sourcePath

The local path to sync from, either absolute or relative to the source directory where the Deploy action is defined.
Path to a local directory to be synchronized with the target.
This should generally be a templated path to another action's source path (e.g. `${actions.build.my-container-image.sourcePath}`), or a relative path.
If a path is hard-coded, we recommend sticking with relative paths here, and using forward slashes (`/`) as a delimiter, as Windows-style paths with back slashes (`\`) and absolute paths will work on some platforms, but they are not portable and will not work for users on other platforms.
Defaults to the Deploy action's config's directory if no value is provided.

This should generally be a templated path to another action's source path (e.g. `${actions.build.my-container-image.sourcePath}`), or a relative path. If a path is hard-coded, you must make sure the path exists, and that it is reliably the correct path for every user.
| Type | Default | Required |
| -------- | ------- | -------- |
| `string` | `"."` | No |

Example:

| Type | Default | Required |
| ----------- | ------- | -------- |
| `posixPath` | `"."` | No |
```yaml
spec:
...
sync:
...
paths:
- sourcePath: "src"
```

### `spec.sync.paths[].containerPath`

Expand Down
22 changes: 17 additions & 5 deletions docs/reference/action-types/Deploy/kubernetes.md
Expand Up @@ -684,13 +684,25 @@ The name of a container in the target. Specify this if the target contains more

[spec](#spec) > [sync](#specsync) > [paths](#specsyncpaths) > sourcePath

The local path to sync from, either absolute or relative to the source directory where the Deploy action is defined.
Path to a local directory to be synchronized with the target.
This should generally be a templated path to another action's source path (e.g. `${actions.build.my-container-image.sourcePath}`), or a relative path.
If a path is hard-coded, we recommend sticking with relative paths here, and using forward slashes (`/`) as a delimiter, as Windows-style paths with back slashes (`\`) and absolute paths will work on some platforms, but they are not portable and will not work for users on other platforms.
Defaults to the Deploy action's config's directory if no value is provided.

This should generally be a templated path to another action's source path (e.g. `${actions.build.my-container-image.sourcePath}`), or a relative path. If a path is hard-coded, you must make sure the path exists, and that it is reliably the correct path for every user.
| Type | Default | Required |
| -------- | ------- | -------- |
| `string` | `"."` | No |

Example:

| Type | Default | Required |
| ----------- | ------- | -------- |
| `posixPath` | `"."` | No |
```yaml
spec:
...
sync:
...
paths:
- sourcePath: "src"
```

### `spec.sync.paths[].containerPath`

Expand Down
14 changes: 11 additions & 3 deletions docs/reference/module-types/container.md
Expand Up @@ -312,8 +312,13 @@ services:

# Specify one or more source files or directories to automatically sync with the running container.
paths:
- # POSIX-style or Windows path of the directory to sync to the target. Defaults to the config's directory if
# no value is provided.
- # Path to a local directory to be synchronized with the target.
# This should generally be a templated path to another action's source path (e.g.
# `${actions.build.my-container-image.sourcePath}`), or a relative path.
# If a path is hard-coded, we recommend sticking with relative paths here, and using forward slashes (`/`)
# as a delimiter, as Windows-style paths with back slashes (`\`) and absolute paths will work on some
# platforms, but they are not portable and will not work for users on other platforms.
# Defaults to the Deploy action's config's directory if no value is provided.
source: .

# POSIX-style absolute path to sync to inside the container. The root path (i.e. "/") is not allowed.
Expand Down Expand Up @@ -1409,7 +1414,10 @@ Specify one or more source files or directories to automatically sync with the r

[services](#services) > [sync](#servicessync) > [paths](#servicessyncpaths) > source

POSIX-style or Windows path of the directory to sync to the target. Defaults to the config's directory if no value is provided.
Path to a local directory to be synchronized with the target.
This should generally be a templated path to another action's source path (e.g. `${actions.build.my-container-image.sourcePath}`), or a relative path.
If a path is hard-coded, we recommend sticking with relative paths here, and using forward slashes (`/`) as a delimiter, as Windows-style paths with back slashes (`\`) and absolute paths will work on some platforms, but they are not portable and will not work for users on other platforms.
Defaults to the Deploy action's config's directory if no value is provided.

| Type | Default | Required |
| -------- | ------- | -------- |
Expand Down
14 changes: 11 additions & 3 deletions docs/reference/module-types/helm.md
Expand Up @@ -243,8 +243,13 @@ sync:

# Specify one or more source files or directories to automatically sync with the running container.
paths:
- # POSIX-style or Windows path of the directory to sync to the target. Defaults to the config's directory if no
# value is provided.
- # Path to a local directory to be synchronized with the target.
# This should generally be a templated path to another action's source path (e.g.
# `${actions.build.my-container-image.sourcePath}`), or a relative path.
# If a path is hard-coded, we recommend sticking with relative paths here, and using forward slashes (`/`) as a
# delimiter, as Windows-style paths with back slashes (`\`) and absolute paths will work on some platforms, but
# they are not portable and will not work for users on other platforms.
# Defaults to the Deploy action's config's directory if no value is provided.
source: .

# POSIX-style absolute path to sync to inside the container. The root path (i.e. "/") is not allowed.
Expand Down Expand Up @@ -1099,7 +1104,10 @@ Specify one or more source files or directories to automatically sync with the r

[sync](#sync) > [paths](#syncpaths) > source

POSIX-style or Windows path of the directory to sync to the target. Defaults to the config's directory if no value is provided.
Path to a local directory to be synchronized with the target.
This should generally be a templated path to another action's source path (e.g. `${actions.build.my-container-image.sourcePath}`), or a relative path.
If a path is hard-coded, we recommend sticking with relative paths here, and using forward slashes (`/`) as a delimiter, as Windows-style paths with back slashes (`\`) and absolute paths will work on some platforms, but they are not portable and will not work for users on other platforms.
Defaults to the Deploy action's config's directory if no value is provided.

| Type | Default | Required |
| -------- | ------- | -------- |
Expand Down
14 changes: 11 additions & 3 deletions docs/reference/module-types/jib-container.md
Expand Up @@ -380,8 +380,13 @@ services:

# Specify one or more source files or directories to automatically sync with the running container.
paths:
- # POSIX-style or Windows path of the directory to sync to the target. Defaults to the config's directory if
# no value is provided.
- # Path to a local directory to be synchronized with the target.
# This should generally be a templated path to another action's source path (e.g.
# `${actions.build.my-container-image.sourcePath}`), or a relative path.
# If a path is hard-coded, we recommend sticking with relative paths here, and using forward slashes (`/`)
# as a delimiter, as Windows-style paths with back slashes (`\`) and absolute paths will work on some
# platforms, but they are not portable and will not work for users on other platforms.
# Defaults to the Deploy action's config's directory if no value is provided.
source: .

# POSIX-style absolute path to sync to inside the container. The root path (i.e. "/") is not allowed.
Expand Down Expand Up @@ -1624,7 +1629,10 @@ Specify one or more source files or directories to automatically sync with the r

[services](#services) > [sync](#servicessync) > [paths](#servicessyncpaths) > source

POSIX-style or Windows path of the directory to sync to the target. Defaults to the config's directory if no value is provided.
Path to a local directory to be synchronized with the target.
This should generally be a templated path to another action's source path (e.g. `${actions.build.my-container-image.sourcePath}`), or a relative path.
If a path is hard-coded, we recommend sticking with relative paths here, and using forward slashes (`/`) as a delimiter, as Windows-style paths with back slashes (`\`) and absolute paths will work on some platforms, but they are not portable and will not work for users on other platforms.
Defaults to the Deploy action's config's directory if no value is provided.

| Type | Default | Required |
| -------- | ------- | -------- |
Expand Down
14 changes: 11 additions & 3 deletions docs/reference/module-types/kubernetes.md
Expand Up @@ -269,8 +269,13 @@ sync:

# Specify one or more source files or directories to automatically sync with the running container.
paths:
- # POSIX-style or Windows path of the directory to sync to the target. Defaults to the config's directory if no
# value is provided.
- # Path to a local directory to be synchronized with the target.
# This should generally be a templated path to another action's source path (e.g.
# `${actions.build.my-container-image.sourcePath}`), or a relative path.
# If a path is hard-coded, we recommend sticking with relative paths here, and using forward slashes (`/`) as a
# delimiter, as Windows-style paths with back slashes (`\`) and absolute paths will work on some platforms, but
# they are not portable and will not work for users on other platforms.
# Defaults to the Deploy action's config's directory if no value is provided.
source: .

# POSIX-style absolute path to sync to inside the container. The root path (i.e. "/") is not allowed.
Expand Down Expand Up @@ -1150,7 +1155,10 @@ Specify one or more source files or directories to automatically sync with the r

[sync](#sync) > [paths](#syncpaths) > source

POSIX-style or Windows path of the directory to sync to the target. Defaults to the config's directory if no value is provided.
Path to a local directory to be synchronized with the target.
This should generally be a templated path to another action's source path (e.g. `${actions.build.my-container-image.sourcePath}`), or a relative path.
If a path is hard-coded, we recommend sticking with relative paths here, and using forward slashes (`/`) as a delimiter, as Windows-style paths with back slashes (`\`) and absolute paths will work on some platforms, but they are not portable and will not work for users on other platforms.
Defaults to the Deploy action's config's directory if no value is provided.

| Type | Default | Required |
| -------- | ------- | -------- |
Expand Down

0 comments on commit 71b3781

Please sign in to comment.