diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..2c7d170 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: + # Maintain dependencies for GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 0000000..aaa0963 --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,42 @@ +name: ci + +on: + push: + branches: + - master + tags: + - '*' + +jobs: + main: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Docker meta + id: docker_meta + uses: crazy-max/ghaction-docker-meta@v1 + with: + images: distribyted/distribyted + tag-sha: true + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + push: true + tags: ${{ steps.docker_meta.outputs.tags }} + labels: ${{ steps.docker_meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1271dcd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +#=============== +# Stage 1: Build +#=============== + +FROM golang:1.15-alpine as builder + +ENV BIN_REPO=github.com/distribyted/distribyted +ENV BIN_PATH=$GOPATH/src/$BIN_REPO + +COPY . $BIN_PATH +WORKDIR $BIN_PATH + +RUN apk add fuse-dev git gcc libc-dev g++ make + +RUN BIN_OUTPUT=/bin/distribyted make build + +#=============== +# Stage 2: Run +#=============== + +FROM alpine:3 + +RUN apk add gcc libc-dev fuse-dev + +COPY --from=builder /bin/distribyted /bin/distribyted +RUN chmod +x /bin/distribyted + +RUN mkdir /distribyted-data + +RUN echo "user_allow_other" >> /etc/fuse.conf +ENV DISTRIBYTED_FUSE_ALLOW_OTHER=true + +ENTRYPOINT ["./bin/distribyted"] diff --git a/Makefile b/Makefile index 65f1586..d9dbf34 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ VERSION := $(shell git describe --tags) BUILD := $(shell git rev-parse --short HEAD) +BIN_OUTPUT ?= bin/distribyted-$(VERSION)-`go env GOOS`-`go env GOARCH``go env GOEXE` PROJECTNAME := $(shell basename "$(PWD)") go-cross-compile: GOPATH=~/go @@ -29,8 +30,8 @@ test: cross-compile: go-generate go-cross-compile go-build: - @echo " > Building binary..." - go build -o bin/distribyted-$(VERSION)-`go env GOOS`-`go env GOARCH``go env GOEXE` -tags "release" -ldflags='$(LDFLAGS)' cmd/distribyted/main.go + @echo " > Building binary on $(BIN_OUTPUT)..." + go build -o $(BIN_OUTPUT) -tags "release" -ldflags='$(LDFLAGS)' cmd/distribyted/main.go go-generate: @echo " > Generating code files..." diff --git a/README.md b/README.md index 69fd900..a9ee90e 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ - [Getting Started](#getting-started) - [Prerequisites on windows](#prerequisites-on-windows) - [Usage](#usage) + - [Docker](#docker) - [Configuration File](#configuration-file) - [root](#root) - [mountpoints](#mountpoints) @@ -109,6 +110,43 @@ It contains information about the mounted routes and torrent files like download You can also modify the configuration file and reload the server from here: `http://localhost:4444/config` . +### Docker + +Docker run example: + +```shell +docker run \ + --rm -p 4444:4444 \ + --cap-add SYS_ADMIN \ + --device /dev/fuse \ + --security-opt apparmor:unconfined \ + -v /tmp/mountpoints:/distribyted-data/mountpoints:shared \ + -v /tmp/metadata:/distribyted-data/metadata \ + -v /tmp/config:/distribyted-data/config \ + distribyted/distribyted:latest +``` + +Docker compose example: + +```yaml +distribyted: + container_name: distribyted + image: distribyted/distribyted:latest + restart: always + ports: + - "4444:4444/tcp" + volumes: + - /home/user/mountpoints:/distribyted-data/mountpoints:shared + - /home/user/metadata:/distribyted-data/metadata + - /home/user/config:/distribyted-data/config + security_opt: + - apparmor:unconfined + devices: + - /dev/fuse + cap_add: + - SYS_ADMIN +``` + ### Configuration File #### root diff --git a/cmd/distribyted/main.go b/cmd/distribyted/main.go index f7df776..358122b 100644 --- a/cmd/distribyted/main.go +++ b/cmd/distribyted/main.go @@ -31,7 +31,7 @@ func main() { Flags: []cli.Flag{ &cli.StringFlag{ Name: configFlag, - Value: "./distribyted-data/config.yaml", + Value: "./distribyted-data/config/config.yaml", EnvVars: []string{"DISTRIBYTED_CONFIG"}, Usage: "YAML file containing distribyted configuration.", }, diff --git a/fuse/mount.go b/fuse/mount.go index 5f71cc7..927dc5a 100644 --- a/fuse/mount.go +++ b/fuse/mount.go @@ -26,7 +26,7 @@ func NewFS(fss []fs.Filesystem) fuse.FileSystemInterface { func (fs *FS) Open(path string, flags int) (errc int, fh uint64) { fh, err := fs.fh.OpenHolder(path) if err == os.ErrNotExist { - logrus.WithField("path", path).Warn("file does not exists") + logrus.WithField("path", path).Debug("file does not exists") return -fuse.ENOENT, fhNone } @@ -50,7 +50,7 @@ func (cfs *FS) Getattr(path string, stat *fuse.Stat_t, fh uint64) (errc int) { file, err := cfs.fh.GetFile(path, fh) if err == os.ErrNotExist { - logrus.WithField("path", path).Warn("file does not exists") + logrus.WithField("path", path).Debug("file does not exists") return -fuse.ENOENT }