From 9b73243a863515ef1abd9f735a0c508522ae136e Mon Sep 17 00:00:00 2001 From: Saleem Rashid Date: Thu, 3 Apr 2025 10:50:33 +0100 Subject: [PATCH 1/3] ci: Update deprecated action versions --- .github/workflows/docker_image.yml | 12 ++++++------ .github/workflows/push.yml | 22 +++++++++++----------- .github/workflows/release.yml | 6 +++--- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/docker_image.yml b/.github/workflows/docker_image.yml index 1940e93..dda94a8 100644 --- a/.github/workflows/docker_image.yml +++ b/.github/workflows/docker_image.yml @@ -23,10 +23,10 @@ jobs: VERSION: "${{ github.event_name == 'release' && github.event.release.name || github.ref_name }}" steps: - - uses: actions/checkout@v3 - - uses: docker/setup-qemu-action@v2 - - uses: docker/setup-buildx-action@v2 - - uses: docker/login-action@v2 + - uses: actions/checkout@v4 + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 id: login env: token_is_present: "${{ secrets.DOCKERHUB_TOKEN && true }}" @@ -36,7 +36,7 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} - id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v5 with: images: flyio/litefs tags: | @@ -47,7 +47,7 @@ jobs: type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} - - uses: docker/build-push-action@v4 + - uses: docker/build-push-action@v6 with: context: . push: ${{ steps.login.outcome != 'skipped' }} diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 224f3c6..4f9a41b 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -14,9 +14,9 @@ jobs: name: "Build" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: go-version-file: 'go.mod' @@ -34,9 +34,9 @@ jobs: matrix: journal_mode: [delete, persist, truncate, wal] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: go-version-file: 'go.mod' @@ -71,9 +71,9 @@ jobs: matrix: journal_mode: [delete, persist, truncate, wal] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: go-version-file: 'go.mod' @@ -94,13 +94,13 @@ jobs: name: "Staticcheck" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: go-version-file: 'go.mod' - - uses: dominikh/staticcheck-action@v1.2.0 + - uses: dominikh/staticcheck-action@v1.3.1 with: install-go: false @@ -108,9 +108,9 @@ jobs: name: "Errcheck" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: go-version-file: 'go.mod' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2f75969..098c7d1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,8 +37,8 @@ jobs: MAIN_VERSION: "${{ github.event_name == 'release' && github.event.release.name || '' }}" steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: go-version-file: 'go.mod' @@ -62,7 +62,7 @@ jobs: tar -czvf litefs-${{ env.VERSION }}-${{ env.GOOS }}-${{ env.GOARCH }}${{ env.GOARM }}.tar.gz litefs - name: Upload binary artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: litefs-${{ env.VERSION }}-${{ env.GOOS }}-${{ env.GOARCH }}${{ env.GOARM }} path: dist/litefs From b4184a7b49fa8aa79fefe36f9ac7086e76fd5e3f Mon Sep 17 00:00:00 2001 From: Saleem Rashid Date: Thu, 3 Apr 2025 11:41:55 +0100 Subject: [PATCH 2/3] ci: Increase test timeouts --- .github/workflows/push.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 4f9a41b..418bffc 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -53,14 +53,14 @@ jobs: run: go test -v . ./internal/... - name: Run FUSE tests - run: go test -v -p 1 -timeout 5m ./fuse -long -journal-mode ${{ matrix.journal_mode }} + run: go test -v -p 1 -timeout 10m ./fuse -long -journal-mode ${{ matrix.journal_mode }} timeout-minutes: 5 - name: Start consul in dev mode run: consul agent -dev & - name: Run cmd tests - run: go test -v -p 1 -timeout 5m ./cmd/litefs -journal-mode ${{ matrix.journal_mode }} + run: go test -v -p 1 -timeout 10m ./cmd/litefs -journal-mode ${{ matrix.journal_mode }} timeout-minutes: 5 functional: From 221f09148fd1c5044afbdcae541daa7d7003afca Mon Sep 17 00:00:00 2001 From: Saleem Rashid Date: Thu, 3 Apr 2025 04:57:46 +0100 Subject: [PATCH 3/3] Dockerfile: Add sidecar support --- Dockerfile | 9 ++++++--- cmd/litefs/mount_linux.go | 8 +++++++- fuse/file_system.go | 8 +++++--- fuse/file_system_test.go | 2 +- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2f91312..9104de3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.21.5 as builder +FROM golang:1.21.5 AS builder WORKDIR /src/litefs COPY . . @@ -10,8 +10,11 @@ RUN --mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/go/pkg \ 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 +FROM alpine + +RUN apk add --no-cache fuse3 -FROM scratch COPY --from=builder /usr/local/bin/litefs /usr/local/bin/litefs + ENTRYPOINT ["/usr/local/bin/litefs"] -CMD [] +CMD ["mount", "-skip-unmount"] diff --git a/cmd/litefs/mount_linux.go b/cmd/litefs/mount_linux.go index 303f236..4d137b7 100644 --- a/cmd/litefs/mount_linux.go +++ b/cmd/litefs/mount_linux.go @@ -34,6 +34,9 @@ type MountCommand struct { cmd *exec.Cmd // subcommand execCh chan error // subcommand error channel + // Skip unmounting any existing mount + skipUnmount bool + Config Config OS litefs.OS @@ -73,6 +76,7 @@ func (c *MountCommand) ParseFlags(ctx context.Context, args []string) (err error fs := flag.NewFlagSet("litefs-mount", flag.ContinueOnError) configPath := fs.String("config", "", "config file path") noExpandEnv := fs.Bool("no-expand-env", false, "do not expand env vars in config") + skipUnmount := fs.Bool("skip-unmount", false, "skip unmounting any existing mount") fuseDebug := fs.Bool("fuse.debug", false, "enable FUSE debug logging") debug := fs.Bool("debug", false, "enable DEBUG level logging") tracing := fs.Bool("tracing", false, "enable trace logging to stdout") @@ -110,6 +114,8 @@ Arguments: c.Config.Exec = ExecConfigSlice{{Cmd: strings.Join(args1, " ")}} } + c.skipUnmount = *skipUnmount + // Override "debug" field if specified on the CLI. if *fuseDebug { c.Config.FUSE.Debug = true @@ -489,7 +495,7 @@ func (c *MountCommand) initFileSystem(ctx context.Context) error { fsys := fuse.NewFileSystem(c.Config.FUSE.Dir, c.Store) fsys.AllowOther = c.Config.FUSE.AllowOther fsys.Debug = c.Config.FUSE.Debug - if err := fsys.Mount(); err != nil { + if err := fsys.Mount(c.skipUnmount); err != nil { return fmt.Errorf("cannot open file system: %s", err) } diff --git a/fuse/file_system.go b/fuse/file_system.go index 770c95b..58f1f1b 100644 --- a/fuse/file_system.go +++ b/fuse/file_system.go @@ -58,9 +58,11 @@ func (fsys *FileSystem) Path() string { return fsys.path } func (fsys *FileSystem) Store() *litefs.Store { return fsys.store } // Mount mounts the file system to the mount point. -func (fsys *FileSystem) Mount() (err error) { - // Attempt to unmount if it did not close cleanly before. - _ = fuse.Unmount(fsys.path) +func (fsys *FileSystem) Mount(skipUnmount bool) (err error) { + if !skipUnmount { + // Attempt to unmount if it did not close cleanly before. + _ = fuse.Unmount(fsys.path) + } // Ensure mount directory exists before trying to mount to it. if err := os.MkdirAll(fsys.path, 0777); err != nil { diff --git a/fuse/file_system_test.go b/fuse/file_system_test.go index a19e7da..48f45a4 100644 --- a/fuse/file_system_test.go +++ b/fuse/file_system_test.go @@ -927,7 +927,7 @@ func newOpenFileSystem(tb testing.TB, path string, leaser *litefs.StaticLeaser) tb.Helper() fs := newFileSystem(tb, path, leaser) - if err := fs.Mount(); err != nil { + if err := fs.Mount(false); err != nil { tb.Fatalf("cannot open file system: %s", err) }