Skip to content

Commit 8bc0776

Browse files
satotakebep
authored andcommitted
Add route-based ignore configuration
In some case, it would be useful to configure ignored routes.
1 parent ebba5f3 commit 8bc0776

File tree

5 files changed

+67
-3
lines changed

5 files changed

+67
-3
lines changed

lib/config.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,19 @@ func (cfg *Config) shouldIgnoreLocal(key string) bool {
140140
}
141141

142142
func (cfg *Config) shouldIgnoreRemote(key string) bool {
143-
if cfg.Ignore == "" {
144-
return false
145-
}
146143

147144
sub := key[len(cfg.BucketPath):]
148145
sub = strings.TrimPrefix(sub, "/")
149146

147+
for _, r := range cfg.conf.Routes {
148+
if r.Ignore && r.routerRE.MatchString(sub) {
149+
return true
150+
}
151+
}
152+
153+
if cfg.Ignore == "" {
154+
return false
155+
}
156+
150157
return cfg.IgnoreRE.MatchString(sub)
151158
}

lib/deployer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ func (d *Deployer) walk(ctx context.Context, basePath string, files chan<- *osFi
289289
return err
290290
}
291291

292+
if f.route != nil && f.route.Ignore {
293+
return nil
294+
}
295+
292296
select {
293297
case <-ctx.Done():
294298
return ctx.Err()

lib/deployer_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,44 @@ func TestDeployWitIgnorePattern(t *testing.T) {
136136
c.Assert(prevTag, qt.Equals, mainCss.ETag())
137137
}
138138

139+
func TestDeployWitRoutesIgnore(t *testing.T) {
140+
c := qt.New(t)
141+
root := "my/path"
142+
143+
store, m := newTestStore(0, root)
144+
source := testSourcePath()
145+
configFile := filepath.Join(source, ".hidden/.s3deploy.ignore.yml")
146+
147+
cfg := &Config{
148+
BucketName: "example.com",
149+
RegionName: "eu-west-1",
150+
ConfigFile: configFile,
151+
BucketPath: root,
152+
MaxDelete: 300,
153+
Silent: false,
154+
SourcePath: source,
155+
baseStore: store,
156+
}
157+
158+
// same as TestDeployWitIgnorePattern
159+
160+
prevCss := m["my/path/main.css"]
161+
prevTag := prevCss.ETag()
162+
163+
stats, err := Deploy(cfg)
164+
c.Assert(err, qt.IsNil)
165+
c.Assert(stats.Summary(), qt.Equals, "Deleted 0 of 0, uploaded 2, skipped 1 (67% changed)")
166+
assertKeys(t, m,
167+
"my/path/.s3deploy.yml",
168+
"my/path/index.html",
169+
"my/path/ab.txt",
170+
"my/path/deleteme.txt", // ignored: stale
171+
"my/path/main.css", // ignored: not updated
172+
)
173+
mainCss := m["my/path/main.css"]
174+
c.Assert(prevTag, qt.Equals, mainCss.ETag())
175+
}
176+
139177
func TestDeploySourceNotFound(t *testing.T) {
140178
c := qt.New(t)
141179
store, _ := newTestStore(0, "")

lib/files.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ type route struct {
239239
Route string `yaml:"route"`
240240
Headers map[string]string `yaml:"headers"`
241241
Gzip bool `yaml:"gzip"`
242+
Ignore bool `yaml:"ignore"`
242243

243244
routerRE *regexp.Regexp // compiled version of Route
244245
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
routes:
2+
- route: "^main\\.css|deleteme\\.txt$"
3+
ignore: true
4+
- route: "^.+\\.(js|css|svg|ttf)$"
5+
# cache static assets for 20 years
6+
headers:
7+
Cache-Control: "max-age=630720000, no-transform, public"
8+
gzip: true
9+
- route: "^.+\\.(png|jpg)$"
10+
headers:
11+
Cache-Control: "max-age=630720000, no-transform, public"
12+
gzip: true
13+
- route: "^.+\\.(html|xml|json)$"
14+
gzip: true

0 commit comments

Comments
 (0)