Skip to content

Commit

Permalink
Empty, non-nil sync = sync all the files and infer destination
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot committed Jan 10, 2020
1 parent 391dfa7 commit 68043c3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 26 deletions.
40 changes: 24 additions & 16 deletions docs/content/en/schemas/v2alpha2.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@
},
"sync": {
"$ref": "#/definitions/Sync",
"description": "*beta* local files synced to pods instead of triggering an image build when modified.",
"x-intellij-html-description": "<em>beta</em> local files synced to pods instead of triggering an image build when modified."
"description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
"x-intellij-html-description": "<em>beta</em> local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
"default": "infer: [\"**/*\"]"
}
},
"preferredOrder": [
Expand Down Expand Up @@ -100,8 +101,9 @@
},
"sync": {
"$ref": "#/definitions/Sync",
"description": "*beta* local files synced to pods instead of triggering an image build when modified.",
"x-intellij-html-description": "<em>beta</em> local files synced to pods instead of triggering an image build when modified."
"description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
"x-intellij-html-description": "<em>beta</em> local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
"default": "infer: [\"**/*\"]"
}
},
"preferredOrder": [
Expand Down Expand Up @@ -135,8 +137,9 @@
},
"sync": {
"$ref": "#/definitions/Sync",
"description": "*beta* local files synced to pods instead of triggering an image build when modified.",
"x-intellij-html-description": "<em>beta</em> local files synced to pods instead of triggering an image build when modified."
"description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
"x-intellij-html-description": "<em>beta</em> local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
"default": "infer: [\"**/*\"]"
}
},
"preferredOrder": [
Expand Down Expand Up @@ -170,8 +173,9 @@
},
"sync": {
"$ref": "#/definitions/Sync",
"description": "*beta* local files synced to pods instead of triggering an image build when modified.",
"x-intellij-html-description": "<em>beta</em> local files synced to pods instead of triggering an image build when modified."
"description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
"x-intellij-html-description": "<em>beta</em> local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
"default": "infer: [\"**/*\"]"
}
},
"preferredOrder": [
Expand Down Expand Up @@ -205,8 +209,9 @@
},
"sync": {
"$ref": "#/definitions/Sync",
"description": "*beta* local files synced to pods instead of triggering an image build when modified.",
"x-intellij-html-description": "<em>beta</em> local files synced to pods instead of triggering an image build when modified."
"description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
"x-intellij-html-description": "<em>beta</em> local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
"default": "infer: [\"**/*\"]"
}
},
"preferredOrder": [
Expand Down Expand Up @@ -240,8 +245,9 @@
},
"sync": {
"$ref": "#/definitions/Sync",
"description": "*beta* local files synced to pods instead of triggering an image build when modified.",
"x-intellij-html-description": "<em>beta</em> local files synced to pods instead of triggering an image build when modified."
"description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
"x-intellij-html-description": "<em>beta</em> local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
"default": "infer: [\"**/*\"]"
}
},
"preferredOrder": [
Expand Down Expand Up @@ -275,8 +281,9 @@
},
"sync": {
"$ref": "#/definitions/Sync",
"description": "*beta* local files synced to pods instead of triggering an image build when modified.",
"x-intellij-html-description": "<em>beta</em> local files synced to pods instead of triggering an image build when modified."
"description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
"x-intellij-html-description": "<em>beta</em> local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
"default": "infer: [\"**/*\"]"
}
},
"preferredOrder": [
Expand Down Expand Up @@ -1964,8 +1971,9 @@
"infer"
],
"additionalProperties": false,
"description": "*beta* specifies what files to sync into the container. This is a list of sync rules indicating the intent to sync for source files.",
"x-intellij-html-description": "<em>beta</em> specifies what files to sync into the container. This is a list of sync rules indicating the intent to sync for source files."
"description": "*beta* specifies what files to sync into the container. This is a list of sync rules indicating the intent to sync for source files. If no files are listed, sync all the files and infer the destination.",
"x-intellij-html-description": "<em>beta</em> specifies what files to sync into the container. This is a list of sync rules indicating the intent to sync for source files. If no files are listed, sync all the files and infer the destination.",
"default": "infer: [\"**/*\"]"
},
"SyncRule": {
"required": [
Expand Down
12 changes: 2 additions & 10 deletions integration/examples/hot-reload/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@ build:
artifacts:
- image: gcr.io/k8s-skaffold/node-example
context: node
sync:
manual:
- src: 'src/**/*.js'
dest: .
strip: src/
sync: {}
- image: gcr.io/k8s-skaffold/python-reload
context: python
sync:
manual:
- src: 'src/**/*.py'
dest: .
strip: src/
sync: {}
7 changes: 7 additions & 0 deletions pkg/skaffold/schema/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func Set(c *latest.SkaffoldConfig) error {

for _, a := range c.Build.Artifacts {
setDefaultWorkspace(a)
setAutoSync(a)

if c.Build.Cluster != nil && a.CustomArtifact == nil {
defaultToKanikoArtifact(a)
Expand Down Expand Up @@ -200,6 +201,12 @@ func setDefaultWorkspace(a *latest.Artifact) {
a.Workspace = valueOrDefault(a.Workspace, ".")
}

func setAutoSync(a *latest.Artifact) {
if a.Sync != nil && len(a.Sync.Manual) == 0 && len(a.Sync.Infer) == 0 {
a.Sync.Infer = []string{"**/*"}
}
}

func withClusterConfig(c *latest.SkaffoldConfig, opts ...func(*latest.ClusterDetails) error) error {
clusterDetails := c.Build.BuildType.Cluster
if clusterDetails == nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/skaffold/schema/defaults/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestSetDefaults(t *testing.T) {
ArtifactType: latest.ArtifactType{
BuildpackArtifact: &latest.BuildpackArtifact{},
},
Sync: &latest.Sync{},
},
},
},
Expand All @@ -81,6 +82,7 @@ func TestSetDefaults(t *testing.T) {
testutil.CheckDeepEqual(t, "fourth", cfg.Build.Artifacts[3].ImageName)
testutil.CheckDeepEqual(t, []string{"."}, cfg.Build.Artifacts[3].BuildpackArtifact.Dependencies.Paths)
testutil.CheckDeepEqual(t, []string(nil), cfg.Build.Artifacts[3].BuildpackArtifact.Dependencies.Ignore)
testutil.CheckDeepEqual(t, []string{"**/*"}, cfg.Build.Artifacts[3].Sync.Infer)
}

func TestSetDefaultsOnCluster(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,8 @@ type Artifact struct {

// Sync *beta* lists local files synced to pods instead
// of triggering an image build when modified.
// If no files are listed, sync all the files and infer the destination.
// Defaults to `infer: ["**/*"]`
Sync *Sync `yaml:"sync,omitempty"`

// ArtifactType describes how to build an artifact.
Expand All @@ -562,6 +564,8 @@ type Artifact struct {

// Sync *beta* specifies what files to sync into the container.
// This is a list of sync rules indicating the intent to sync for source files.
// If no files are listed, sync all the files and infer the destination.
// Defaults to `infer: ["**/*"]`
type Sync struct {
// Manual lists manual sync rules indicating the source and destination.
Manual []*SyncRule `yaml:"manual,omitempty" yamltags:"oneOf=sync"`
Expand Down

0 comments on commit 68043c3

Please sign in to comment.