Keep the database files, logs and binaries out of the build context (closes #120)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
The daemon's database is db.sqlite with its -wal and -shm files, which the .db patterns in .dockerignore and .gitignore did not match, so a database left in the clone shipped in the image's source archive. .dockerignore now also excludes the logs and the .exe, .dll, .so and .dylib files .gitignore already ignores. A test opens a database and checks that .dockerignore has an any-depth pattern for each of its files. Model: opus-5-5
This commit was merged in pull request #145.
This commit is contained in:
+12
-2
@@ -73,7 +73,8 @@
|
|||||||
|
|
||||||
# This repository's host-built artifacts: `make build` writes bin/, `go
|
# This repository's host-built artifacts: `make build` writes bin/, `go
|
||||||
# build` in the root the binaries, `make run` log.txt, `make asupdate` its
|
# build` in the root the binaries, `make run` log.txt, `make asupdate` its
|
||||||
# .tmp file; test binaries, coverage profiles and source archives.
|
# .tmp file; logs, test binaries, coverage profiles, source archives, and
|
||||||
|
# the binaries and libraries a build for another platform writes.
|
||||||
/bin
|
/bin
|
||||||
/routewatch
|
/routewatch
|
||||||
/asinfo-gen
|
/asinfo-gen
|
||||||
@@ -82,15 +83,24 @@
|
|||||||
/out
|
/out
|
||||||
/pkg/asinfo/asdata.json
|
/pkg/asinfo/asdata.json
|
||||||
**/*.tar.zst
|
**/*.tar.zst
|
||||||
|
**/*.log
|
||||||
**/*.test
|
**/*.test
|
||||||
**/*.out
|
**/*.out
|
||||||
**/*.tmp
|
**/*.tmp
|
||||||
|
**/*.exe
|
||||||
|
**/*.dll
|
||||||
|
**/*.so
|
||||||
|
**/*.dylib
|
||||||
|
|
||||||
# Local databases. The image carries a source archive of the whole build
|
# Local databases. The image carries a source archive of the whole build
|
||||||
# context, so these would otherwise ship inside it.
|
# context, so these would otherwise ship inside it. The daemon's database
|
||||||
|
# is db.sqlite, with its -wal and -shm files while it runs.
|
||||||
**/*.db
|
**/*.db
|
||||||
**/*.db-journal
|
**/*.db-journal
|
||||||
**/*.db-wal
|
**/*.db-wal
|
||||||
|
**/*.sqlite
|
||||||
|
**/*.sqlite-wal
|
||||||
|
**/*.sqlite-shm
|
||||||
|
|
||||||
# A local Go workspace points at directories outside the build context.
|
# A local Go workspace points at directories outside the build context.
|
||||||
/go.work
|
/go.work
|
||||||
|
|||||||
+5
-1
@@ -67,10 +67,14 @@ node_modules/
|
|||||||
go.work
|
go.work
|
||||||
go.work.sum
|
go.work.sum
|
||||||
|
|
||||||
# Local databases, temporary files and debug output.
|
# Local databases, temporary files and debug output. The daemon's
|
||||||
|
# database is db.sqlite, with its -wal and -shm files while it runs.
|
||||||
*.db
|
*.db
|
||||||
*.db-journal
|
*.db-journal
|
||||||
*.db-wal
|
*.db-wal
|
||||||
|
*.sqlite
|
||||||
|
*.sqlite-wal
|
||||||
|
*.sqlite-shm
|
||||||
*.tmp
|
*.tmp
|
||||||
log.txt
|
log.txt
|
||||||
out
|
out
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.eeqj.de/sneak/routewatch/internal/config"
|
||||||
|
"git.eeqj.de/sneak/routewatch/internal/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestDockerignoreExcludesDatabaseFiles checks that .dockerignore keeps the
|
||||||
|
// database file, and the WAL and shared-memory files SQLite writes next to it,
|
||||||
|
// out of the build context wherever they sit in the clone. The image ships the
|
||||||
|
// whole build context as a source archive.
|
||||||
|
func TestDockerignoreExcludesDatabaseFiles(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
db, err := New(&config.Config{StateDir: t.TempDir()}, logger.New())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create database: %v", err)
|
||||||
|
}
|
||||||
|
defer func() { _ = db.Close() }()
|
||||||
|
|
||||||
|
data, err := os.ReadFile("../../.dockerignore")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to read .dockerignore: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Docker reads `**/` as any number of directories and the rest of the
|
||||||
|
// pattern as filepath.Match does, so `**/` followed by a pattern that
|
||||||
|
// matches a file's name excludes that file at any depth.
|
||||||
|
var anyDepth []string
|
||||||
|
|
||||||
|
for line := range strings.Lines(string(data)) {
|
||||||
|
pattern, ok := strings.CutPrefix(strings.TrimSpace(line), "**/")
|
||||||
|
if ok {
|
||||||
|
anyDepth = append(anyDepth, pattern)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
name := filepath.Base(db.path)
|
||||||
|
|
||||||
|
for _, file := range []string{name, name + "-wal", name + "-shm"} {
|
||||||
|
excluded := false
|
||||||
|
|
||||||
|
for _, pattern := range anyDepth {
|
||||||
|
matched, err := filepath.Match(pattern, file)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("bad .dockerignore pattern **/%s: %v", pattern, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
excluded = excluded || matched
|
||||||
|
}
|
||||||
|
|
||||||
|
if !excluded {
|
||||||
|
t.Errorf(".dockerignore has no **/ pattern that excludes %s", file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user