Skip to content

Commit ea27cac

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

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.21.5 as builder
1+
FROM golang:1.21.5 AS builder
22

33
WORKDIR /src/litefs
44
COPY . .
@@ -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", "-skip-unmount"]

cmd/litefs/mount_linux.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ type MountCommand struct {
3434
cmd *exec.Cmd // subcommand
3535
execCh chan error // subcommand error channel
3636

37+
// Skip unmounting any existing mount
38+
skipUnmount bool
39+
3740
Config Config
3841

3942
OS litefs.OS
@@ -73,6 +76,7 @@ func (c *MountCommand) ParseFlags(ctx context.Context, args []string) (err error
7376
fs := flag.NewFlagSet("litefs-mount", flag.ContinueOnError)
7477
configPath := fs.String("config", "", "config file path")
7578
noExpandEnv := fs.Bool("no-expand-env", false, "do not expand env vars in config")
79+
skipUnmount := fs.Bool("skip-unmount", false, "skip unmounting any existing mount")
7680
fuseDebug := fs.Bool("fuse.debug", false, "enable FUSE debug logging")
7781
debug := fs.Bool("debug", false, "enable DEBUG level logging")
7882
tracing := fs.Bool("tracing", false, "enable trace logging to stdout")
@@ -110,6 +114,8 @@ Arguments:
110114
c.Config.Exec = ExecConfigSlice{{Cmd: strings.Join(args1, " ")}}
111115
}
112116

117+
c.skipUnmount = *skipUnmount
118+
113119
// Override "debug" field if specified on the CLI.
114120
if *fuseDebug {
115121
c.Config.FUSE.Debug = true
@@ -489,7 +495,7 @@ func (c *MountCommand) initFileSystem(ctx context.Context) error {
489495
fsys := fuse.NewFileSystem(c.Config.FUSE.Dir, c.Store)
490496
fsys.AllowOther = c.Config.FUSE.AllowOther
491497
fsys.Debug = c.Config.FUSE.Debug
492-
if err := fsys.Mount(); err != nil {
498+
if err := fsys.Mount(c.skipUnmount); err != nil {
493499
return fmt.Errorf("cannot open file system: %s", err)
494500
}
495501

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(skipUnmount bool) (err error) {
62+
if !skipUnmount {
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)