Skip to content

Commit b4c29e0

Browse files
authored
Make it possible to disable auto-sync (#4923)
* hack at turning auto into a bool * Use MarshalJSON to DTRT * make generate-schemas * small cleanup * fix additional auto:{} references * Update docs on disabling auto-sync
1 parent 331da68 commit b4c29e0

File tree

13 files changed

+56
-36
lines changed

13 files changed

+56
-36
lines changed

docs/content/en/docs/pipeline-stages/filesync.md

+3-8
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,15 @@ Changes to other file types trigger an image rebuild.
9898

9999
##### Disable Auto Sync for Buildpacks
100100

101-
To disable auto sync, simply provide a manual sync rule. It does
102-
not matter if the sync rule does not match any actual files.
103-
For example:
101+
To disable auto sync, set `sync.auto = false`:
104102

105103
```
106104
artifacts:
107105
- image: xxx
108106
buildpacks:
109107
builder: gcr.io/buildpacks/builder:v1
110-
# disable buildpacks auto-sync
111108
sync:
112-
manual:
113-
- src: .
114-
dest: .
109+
auto: false # disable buildpacks auto-sync
115110
```
116111

117112
##### How it works
@@ -125,7 +120,7 @@ have to output the sync rules based on their exploration of the source and the b
125120
Those sync rules will then be used by Skaffold without the user having to configure them manually.
126121

127122
Another thing the Buildpacks have to do is support the `GOOGLE_DEVMODE` environment variable. Skaffold will
128-
set it to `1` when running `skaffold dev` with sync configured to `auto: {}`. The Buildpacks can then use that
123+
set it to `1` when running `skaffold dev` with sync configured to `auto: true`. The Buildpacks can then use that
129124
signal to change the way the application is built so that it reloads the changes or rebuilds the app on each change.
130125

131126
#### Jib

docs/content/en/schemas/v2beta9.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,6 @@
385385
"description": "describes a specific build dependency for an artifact.",
386386
"x-intellij-html-description": "describes a specific build dependency for an artifact."
387387
},
388-
"Auto": {
389-
"description": "cannot be customized.",
390-
"x-intellij-html-description": "cannot be customized."
391-
},
392388
"BazelArtifact": {
393389
"required": [
394390
"target"
@@ -2534,7 +2530,7 @@
25342530
"Sync": {
25352531
"properties": {
25362532
"auto": {
2537-
"$ref": "#/definitions/Auto",
2533+
"type": "boolean",
25382534
"description": "delegates discovery of sync rules to the build system. Only available for jib and buildpacks.",
25392535
"x-intellij-html-description": "delegates discovery of sync rules to the build system. Only available for jib and buildpacks."
25402536
},

integration/examples/jib-sync/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ build:
5858
context: .
5959
jib: {}
6060
sync:
61-
auto: {}
61+
auto: true
6262
```
6363
6464
This example is designed around the functionality available in [Spring Boot Developer Tools](https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-devtools) for developing against running applications.
@@ -76,7 +76,7 @@ build:
7676
jib:
7777
fromImage: gcr.io/distroless/java:debug
7878
sync:
79-
auto: {}
79+
auto: true
8080
```
8181

8282

@@ -121,7 +121,7 @@ build:
121121
args:
122122
- -Psync
123123
sync:
124-
auto: {}
124+
auto: true
125125
```
126126
127127
You can also take advantage of [skaffold profiles](https://skaffold.dev/docs/environment/profiles/) to control when to activate sync on your project.
@@ -141,7 +141,7 @@ profiles:
141141
# we want to activate sync on our skaffold artifact
142142
path: /build/artifacts/0/sync
143143
value:
144-
- auto: {}
144+
- auto: true
145145
- op: add
146146
# we activate the sync profile in our java builds
147147
path: /build/artifacts/0/jib/args

integration/examples/jib-sync/skaffold-gradle.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ build:
99
- -Psync
1010
fromImage: gcr.io/distroless/java:debug
1111
sync:
12-
auto: {}
12+
auto: true
1313

1414
portForward:
1515
- resourceType: pod

integration/examples/jib-sync/skaffold-maven.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ build:
1010
- -Psync
1111
fromImage: gcr.io/distroless/java:debug
1212
sync:
13-
auto: {}
13+
auto: true
1414

1515
portForward:
1616
- resourceType: pod

pkg/skaffold/build/buildpacks/build_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
2828
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
2929
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
30+
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
3031
"github.com/GoogleContainerTools/skaffold/testutil"
3132
)
3233

@@ -185,7 +186,7 @@ value = "VALUE2"
185186
},
186187
{
187188
description: "dev mode",
188-
artifact: withSync(&latest.Sync{Auto: &latest.Auto{}}, buildpacksArtifact("another/builder", "another/run")),
189+
artifact: withSync(&latest.Sync{Auto: util.BoolPtr(true)}, buildpacksArtifact("another/builder", "another/run")),
189190
tag: "img:tag",
190191
api: &testutil.FakeAPIClient{},
191192
mode: config.RunModes.Dev,

pkg/skaffold/build/buildpacks/env.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func env(a *latest.Artifact, mode config.RunMode, projectDescriptor project.Desc
4646
return nil, fmt.Errorf("unable to evaluate env variables: %w", err)
4747
}
4848

49-
if mode == config.RunModes.Dev && a.Sync != nil && a.Sync.Auto != nil {
49+
if mode == config.RunModes.Dev && a.Sync != nil && a.Sync.Auto != nil && *a.Sync.Auto {
5050
envVars = append(envVars, "GOOGLE_DEVMODE=1")
5151
}
5252

pkg/skaffold/schema/defaults/defaults.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
2828
kubectx "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context"
2929
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
30+
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
3031
)
3132

3233
const (
@@ -235,13 +236,13 @@ func setDefaultSync(a *latest.Artifact) {
235236
if len(a.Sync.Manual) == 0 && len(a.Sync.Infer) == 0 && a.Sync.Auto == nil {
236237
switch {
237238
case a.JibArtifact != nil || a.BuildpackArtifact != nil:
238-
a.Sync.Auto = &latest.Auto{}
239+
a.Sync.Auto = util.BoolPtr(true)
239240
default:
240241
a.Sync.Infer = []string{"**/*"}
241242
}
242243
}
243244
} else if a.BuildpackArtifact != nil {
244-
a.Sync = &latest.Sync{Auto: &latest.Auto{}}
245+
a.Sync = &latest.Sync{Auto: util.BoolPtr(true)}
245246
}
246247
}
247248

pkg/skaffold/schema/defaults/defaults_test.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
2727
kubectx "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context"
2828
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
29+
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
2930
"github.com/GoogleContainerTools/skaffold/testutil"
3031
)
3132

@@ -76,6 +77,13 @@ func TestSetDefaults(t *testing.T) {
7677
BuildpackArtifact: &latest.BuildpackArtifact{},
7778
},
7879
},
80+
{
81+
ImageName: "seventh",
82+
ArtifactType: latest.ArtifactType{
83+
BuildpackArtifact: &latest.BuildpackArtifact{},
84+
},
85+
Sync: &latest.Sync{Auto: util.BoolPtr(false)},
86+
},
7987
},
8088
},
8189
},
@@ -103,16 +111,22 @@ func TestSetDefaults(t *testing.T) {
103111
testutil.CheckDeepEqual(t, []string{"."}, cfg.Build.Artifacts[3].BuildpackArtifact.Dependencies.Paths)
104112
testutil.CheckDeepEqual(t, []string(nil), cfg.Build.Artifacts[3].BuildpackArtifact.Dependencies.Ignore)
105113
testutil.CheckDeepEqual(t, "project.toml", cfg.Build.Artifacts[3].BuildpackArtifact.ProjectDescriptor)
106-
testutil.CheckDeepEqual(t, &latest.Auto{}, cfg.Build.Artifacts[3].Sync.Auto)
114+
testutil.CheckDeepEqual(t, util.BoolPtr(true), cfg.Build.Artifacts[3].Sync.Auto)
107115

108116
testutil.CheckDeepEqual(t, "fifth", cfg.Build.Artifacts[4].ImageName)
109-
testutil.CheckDeepEqual(t, &latest.Auto{}, cfg.Build.Artifacts[4].Sync.Auto)
117+
testutil.CheckDeepEqual(t, util.BoolPtr(true), cfg.Build.Artifacts[4].Sync.Auto)
110118

111119
testutil.CheckDeepEqual(t, "sixth", cfg.Build.Artifacts[5].ImageName)
112120
testutil.CheckDeepEqual(t, []string{"."}, cfg.Build.Artifacts[5].BuildpackArtifact.Dependencies.Paths)
113121
testutil.CheckDeepEqual(t, []string(nil), cfg.Build.Artifacts[5].BuildpackArtifact.Dependencies.Ignore)
114122
testutil.CheckDeepEqual(t, "project.toml", cfg.Build.Artifacts[5].BuildpackArtifact.ProjectDescriptor)
115-
testutil.CheckDeepEqual(t, &latest.Auto{}, cfg.Build.Artifacts[5].Sync.Auto)
123+
testutil.CheckDeepEqual(t, util.BoolPtr(true), cfg.Build.Artifacts[5].Sync.Auto)
124+
125+
testutil.CheckDeepEqual(t, "seventh", cfg.Build.Artifacts[6].ImageName)
126+
testutil.CheckDeepEqual(t, []string{"."}, cfg.Build.Artifacts[6].BuildpackArtifact.Dependencies.Paths)
127+
testutil.CheckDeepEqual(t, []string(nil), cfg.Build.Artifacts[6].BuildpackArtifact.Dependencies.Ignore)
128+
testutil.CheckDeepEqual(t, "project.toml", cfg.Build.Artifacts[6].BuildpackArtifact.ProjectDescriptor)
129+
testutil.CheckDeepEqual(t, util.BoolPtr(false), cfg.Build.Artifacts[6].Sync.Auto)
116130
}
117131

118132
func TestSetDefaultsOnCluster(t *testing.T) {

pkg/skaffold/schema/latest/config.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ type Sync struct {
786786

787787
// Auto delegates discovery of sync rules to the build system.
788788
// Only available for jib and buildpacks.
789-
Auto *Auto `yaml:"auto,omitempty" yamltags:"oneOf=sync"`
789+
Auto *bool `yaml:"auto,omitempty" yamltags:"oneOf=sync"`
790790
}
791791

792792
// SyncRule specifies which local files to sync to remote folders.
@@ -806,9 +806,6 @@ type SyncRule struct {
806806
Strip string `yaml:"strip,omitempty"`
807807
}
808808

809-
// Auto cannot be customized.
810-
type Auto struct{}
811-
812809
// Profile is used to override any `build`, `test` or `deploy` configuration.
813810
type Profile struct {
814811
// Name is a unique profile name.

pkg/skaffold/schema/v2beta8/upgrade.go

100755100644
+12
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ import (
2424

2525
// Upgrade upgrades a configuration to the next version.
2626
// Config changes from v2beta8 to v2beta9
27+
// 1. No additions:
28+
// 2. No removals
29+
// 3. Updates:
30+
// - sync.auto becomes boolean
2731
func (c *SkaffoldConfig) Upgrade() (util.VersionedConfig, error) {
2832
var newConfig next.SkaffoldConfig
2933
pkgutil.CloneThroughJSON(c, &newConfig)
@@ -36,3 +40,11 @@ func (c *SkaffoldConfig) Upgrade() (util.VersionedConfig, error) {
3640
func upgradeOnePipeline(_, _ interface{}) error {
3741
return nil
3842
}
43+
44+
func (a *Auto) MarshalJSON() ([]byte, error) {
45+
// The presence of an Auto{} means auto-sync is enabled.
46+
if a != nil {
47+
return []byte(`true`), nil
48+
}
49+
return nil, nil
50+
}

pkg/skaffold/schema/v2beta8/upgrade_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ build:
4646
- image: gcr.io/k8s-skaffold/buildpacks
4747
buildpacks:
4848
builder: gcr.io/buildpacks/builder:v1
49+
sync:
50+
auto: {}
4951
googleCloudBuild:
5052
projectId: test-project
5153
test:
@@ -115,6 +117,8 @@ build:
115117
- image: gcr.io/k8s-skaffold/buildpacks
116118
buildpacks:
117119
builder: gcr.io/buildpacks/builder:v1
120+
sync:
121+
auto: true
118122
googleCloudBuild:
119123
projectId: test-project
120124
test:

pkg/skaffold/sync/sync_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ func TestNewSyncItem(t *testing.T) {
650650
},
651651
ImageName: "test",
652652
Sync: &latest.Sync{
653-
Auto: &latest.Auto{},
653+
Auto: util.BoolPtr(true),
654654
},
655655
Workspace: ".",
656656
},
@@ -690,7 +690,7 @@ func TestNewSyncItem(t *testing.T) {
690690
},
691691
ImageName: "test",
692692
Sync: &latest.Sync{
693-
Auto: &latest.Auto{},
693+
Auto: util.BoolPtr(true),
694694
},
695695
Workspace: ".",
696696
},
@@ -724,7 +724,7 @@ func TestNewSyncItem(t *testing.T) {
724724
ImageName: "test",
725725
Workspace: ".",
726726
Sync: &latest.Sync{
727-
Auto: &latest.Auto{},
727+
Auto: util.BoolPtr(true),
728728
},
729729
ArtifactType: latest.ArtifactType{
730730
JibArtifact: &latest.JibArtifact{},
@@ -1073,18 +1073,18 @@ func TestInit(t *testing.T) {
10731073
},
10741074
{
10751075
description: "sync on, auto on, non-jib",
1076-
artifact: &latest.Artifact{Sync: &latest.Sync{Auto: &latest.Auto{}}},
1076+
artifact: &latest.Artifact{Sync: &latest.Sync{Auto: util.BoolPtr(true)}},
10771077
shouldInit: false,
10781078
},
10791079
{
10801080
description: "sync on, auto on, jib",
1081-
artifact: &latest.Artifact{ArtifactType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{}}, Sync: &latest.Sync{Auto: &latest.Auto{}}},
1081+
artifact: &latest.Artifact{ArtifactType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{}}, Sync: &latest.Sync{Auto: util.BoolPtr(true)}},
10821082
shouldInit: true,
10831083
initErrors: false,
10841084
},
10851085
{
10861086
description: "sync on, auto on, jib, init fails",
1087-
artifact: &latest.Artifact{ArtifactType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{}}, Sync: &latest.Sync{Auto: &latest.Auto{}}},
1087+
artifact: &latest.Artifact{ArtifactType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{}}, Sync: &latest.Sync{Auto: util.BoolPtr(true)}},
10881088
shouldInit: true,
10891089
initErrors: true,
10901090
},

0 commit comments

Comments
 (0)