Skip to content

Commit b8f4eea

Browse files
committed
Dockerfile: Add sidecar support
1 parent 9b73243 commit b8f4eea

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
1010
--mount=type=cache,target=/go/pkg \
1111
go build -ldflags "-s -w -X 'main.Version=${LITEFS_VERSION}' -X 'main.Commit=${LITEFS_COMMIT}' -extldflags '-static'" -tags osusergo,netgo,sqlite_omit_load_extension -o /usr/local/bin/litefs ./cmd/litefs
1212

13+
FROM alpine
14+
15+
RUN apk add --no-cache fuse3
1316

14-
FROM scratch
1517
COPY --from=builder /usr/local/bin/litefs /usr/local/bin/litefs
18+
1619
ENTRYPOINT ["/usr/local/bin/litefs"]
17-
CMD []
20+
CMD ["mount", "-no-unmount"]

cmd/litefs/mount_linux.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ import (
3131

3232
// MountCommand represents a command to mount the file system.
3333
type MountCommand struct {
34-
cmd *exec.Cmd // subcommand
35-
execCh chan error // subcommand error channel
34+
cmd *exec.Cmd // subcommand
35+
execCh chan error // subcommand error channel
36+
noUnmount bool
3637

3738
Config Config
3839

@@ -73,6 +74,7 @@ func (c *MountCommand) ParseFlags(ctx context.Context, args []string) (err error
7374
fs := flag.NewFlagSet("litefs-mount", flag.ContinueOnError)
7475
configPath := fs.String("config", "", "config file path")
7576
noExpandEnv := fs.Bool("no-expand-env", false, "do not expand env vars in config")
77+
noUnmount := fs.Bool("no-unmount", false, "do not unmount before mounting")
7678
fuseDebug := fs.Bool("fuse.debug", false, "enable FUSE debug logging")
7779
debug := fs.Bool("debug", false, "enable DEBUG level logging")
7880
tracing := fs.Bool("tracing", false, "enable trace logging to stdout")
@@ -110,6 +112,8 @@ Arguments:
110112
c.Config.Exec = ExecConfigSlice{{Cmd: strings.Join(args1, " ")}}
111113
}
112114

115+
c.noUnmount = *noUnmount
116+
113117
// Override "debug" field if specified on the CLI.
114118
if *fuseDebug {
115119
c.Config.FUSE.Debug = true
@@ -489,7 +493,7 @@ func (c *MountCommand) initFileSystem(ctx context.Context) error {
489493
fsys := fuse.NewFileSystem(c.Config.FUSE.Dir, c.Store)
490494
fsys.AllowOther = c.Config.FUSE.AllowOther
491495
fsys.Debug = c.Config.FUSE.Debug
492-
if err := fsys.Mount(); err != nil {
496+
if err := fsys.Mount(c.noUnmount); err != nil {
493497
return fmt.Errorf("cannot open file system: %s", err)
494498
}
495499

fuse/file_system.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ func (fsys *FileSystem) Path() string { return fsys.path }
5858
func (fsys *FileSystem) Store() *litefs.Store { return fsys.store }
5959

6060
// Mount mounts the file system to the mount point.
61-
func (fsys *FileSystem) Mount() (err error) {
62-
// Attempt to unmount if it did not close cleanly before.
63-
_ = fuse.Unmount(fsys.path)
61+
func (fsys *FileSystem) Mount(noUnmount bool) (err error) {
62+
if !noUnmount {
63+
// Attempt to unmount if it did not close cleanly before.
64+
_ = fuse.Unmount(fsys.path)
65+
}
6466

6567
// Ensure mount directory exists before trying to mount to it.
6668
if err := os.MkdirAll(fsys.path, 0777); err != nil {

fuse/file_system_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ func newOpenFileSystem(tb testing.TB, path string, leaser *litefs.StaticLeaser)
927927
tb.Helper()
928928

929929
fs := newFileSystem(tb, path, leaser)
930-
if err := fs.Mount(); err != nil {
930+
if err := fs.Mount(false); err != nil {
931931
tb.Fatalf("cannot open file system: %s", err)
932932
}
933933

0 commit comments

Comments
 (0)