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 <[email protected]>
  • Loading branch information
dgageot committed Jan 17, 2020
1 parent 80f82f4 commit 301eaf8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 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 @@ -1904,8 +1911,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
7 changes: 7 additions & 0 deletions pkg/skaffold/schema/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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 && a.BuildpackArtifact == nil {
defaultToKanikoArtifact(a)
Expand Down Expand Up @@ -213,6 +214,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 @@ -560,6 +560,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 @@ -568,6 +570,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 301eaf8

Please sign in to comment.