Docker image (#22)

- Config file now is inside a config folder by default, to make easier
docker integration.
- File not found errors now are debug log outputs.
- Added dependabot integration for github action versions.

Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
This commit is contained in:
Antonio Navarro Perez 2020-11-14 16:28:50 +01:00 committed by GitHub
parent 8882d80232
commit 0a4438b1ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 126 additions and 5 deletions

7
.github/dependabot.yml vendored Normal file
View file

@ -0,0 +1,7 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

42
.github/workflows/docker.yaml vendored Normal file
View file

@ -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 }}

33
Dockerfile Normal file
View file

@ -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"]

View file

@ -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..."

View file

@ -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

View file

@ -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.",
},

View file

@ -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
}