diff --git a/.travis.yml b/.travis.yml index 91cda94..64f7222 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,6 @@ before_install: install: - "go get -u -v github.com/kevinburke/go-bindata/..." - - "go get -u -v honnef.co/go/tools/cmd/staticcheck" before_script: - "make magneticod" diff --git a/Dockerfile.magneticod b/Dockerfile.magneticod index d1b0af0..93c8922 100644 --- a/Dockerfile.magneticod +++ b/Dockerfile.magneticod @@ -1,6 +1,7 @@ # Start from a Debian image with the latest version of Go installed # and a workspace (GOPATH) configured at /go. -FROM golang:1.12-alpine AS build +FROM golang:1.13-alpine AS build +WORKDIR /magnetico RUN apk add --no-cache build-base curl git @@ -10,15 +11,14 @@ ADD ./pkg /magnetico/pkg ADD ./go.mod /magnetico/go.mod ADD ./cmd/magneticod /magnetico/cmd/magneticod -WORKDIR /magnetico/ RUN make magneticod FROM alpine:latest LABEL maintainer="bora@boramalper.org" WORKDIR / +VOLUME /root/.local/share/magneticod +VOLUME /root/.config/magneticod + COPY --from=build /go/bin/magneticod /magneticod -RUN adduser -D -S magnetico -USER magnetico - ENTRYPOINT ["/magneticod"] diff --git a/Dockerfile.magneticow b/Dockerfile.magneticow index 2971b75..3e3d878 100644 --- a/Dockerfile.magneticow +++ b/Dockerfile.magneticow @@ -1,10 +1,11 @@ # Start from a Debian image with the latest version of Go installed # and a workspace (GOPATH) configured at /go. -FROM golang:1.12-alpine AS build +FROM golang:1.13-alpine AS build +WORKDIR /magnetico RUN export PATH=$PATH:/go/bin - RUN apk add --no-cache build-base curl git +RUN go get -u github.com/kevinburke/go-bindata/... # Copy the local package files to the container's workspace. ADD ./Makefile /magnetico/ @@ -12,24 +13,18 @@ ADD ./pkg /magnetico/pkg ADD ./go.mod /magnetico/go.mod ADD ./cmd/magneticow /magnetico/cmd/magneticow -WORKDIR /magnetico - -RUN go get -u github.com/kevinburke/go-bindata/... - -RUN echo $PATH -RUN ls /go/bin - RUN make magneticow FROM alpine:latest LABEL maintainer="bora@boramalper.org" +# the service listens on port 8080 +EXPOSE 8080 WORKDIR / +VOLUME /root/.local/share/magneticod + +RUN mkdir -p "/root/.config/magneticow/" +RUN echo 'magnetico:$2y$06$8VzJvXegA2X/tfmTXN7NM.FH5HRh8fbvXUmrtW52xLH5JNDhldexG' > "/root/.config/magneticow/credentials" + COPY --from=build /go/bin/magneticow /magneticow -RUN adduser -D -S magnetico -USER magnetico - ENTRYPOINT ["/magneticow"] - -# Document that the service listens on port 8080. -EXPOSE 8080 diff --git a/cmd/magneticod/README.md b/cmd/magneticod/README.md index 8ae02a2..141f010 100644 --- a/cmd/magneticod/README.md +++ b/cmd/magneticod/README.md @@ -54,15 +54,12 @@ You need to mount hence run: ```bash - docker run \ + docker run -it --rm \ -v ~/.local/share/magneticod:/root/.local/share/magneticod/ \ -v ~/.config/magneticod/configuration.toml:/root/.config/magneticod/configuration.toml \ - magneticod + boramalper/magneticod ``` -__Tip:__ Containers that you terminate won't be removed; run -`docker rm $(docker ps -q -f status=exited)` to remove exited containers. - ### Remark About the Network Usage **magneticod** does *not* have any built-in rate limiter *yet*, and it will literally suck the hell out of your bandwidth. Unless you are running **magneticod** on a separate machine dedicated for it, you might want to consider diff --git a/cmd/magneticod/dht/mainline/indexingService.go b/cmd/magneticod/dht/mainline/indexingService.go index 0a6d029..2dcdc78 100644 --- a/cmd/magneticod/dht/mainline/indexingService.go +++ b/cmd/magneticod/dht/mainline/indexingService.go @@ -230,15 +230,15 @@ func (is *IndexingService) onSampleInfohashesResponse(msg *Message, addr *net.UD // TODO /* - target := make([]byte, 20) - _, err := rand.Read(target) - if err != nil { - zap.L().Panic("Could NOT generate random bytes!") - } - is.protocol.SendMessage( - NewSampleInfohashesQuery(is.nodeID, []byte("aa"), target), - &node.Addr, - ) + target := make([]byte, 20) + _, err := rand.Read(target) + if err != nil { + zap.L().Panic("Could NOT generate random bytes!") + } + is.protocol.SendMessage( + NewSampleInfohashesQuery(is.nodeID, []byte("aa"), target), + &node.Addr, + ) */ } } diff --git a/cmd/magneticod/main.go b/cmd/magneticod/main.go index 938d0bf..7b2148a 100644 --- a/cmd/magneticod/main.go +++ b/cmd/magneticod/main.go @@ -56,7 +56,7 @@ func main() { return } - zap.L().Info("magneticod v0.8.0 has been started.") + zap.L().Info("magneticod v0.8.2 has been started.") zap.L().Info("Copyright (C) 2017-2019 Mert Bora ALPER .") zap.L().Info("Dedicated to Cemile Binay, in whose hands I thrived.") zap.S().Infof("Compiled on %s", compiledOn) diff --git a/cmd/magneticow/README.md b/cmd/magneticow/README.md index 4ab1737..f64166c 100644 --- a/cmd/magneticow/README.md +++ b/cmd/magneticow/README.md @@ -80,11 +80,13 @@ You need to mount hence run: ```bash - docker run \ + docker run -it --rm \ -v ~/.local/share/magneticod:/root/.local/share/magneticod/ \ -v ~/.config/magneticow/configuration.toml:/root/.config/magneticow/configuration.toml \ - magneticow + boramalper/magneticow ``` + +Using Docker, the default username & password is `magnetico` and `magnetico`. ### Searching * Only the **titles** of the torrents are being searched. diff --git a/cmd/magneticow/main.go b/cmd/magneticow/main.go index 4414b9b..bcb350d 100644 --- a/cmd/magneticow/main.go +++ b/cmd/magneticow/main.go @@ -5,7 +5,6 @@ import ( "bytes" "encoding/hex" "fmt" - "github.com/pkg/errors" "html/template" "io" "net/http" @@ -17,6 +16,8 @@ import ( "syscall" "time" + "github.com/pkg/errors" + "github.com/Wessie/appdirs" "github.com/dustin/go-humanize" "github.com/gorilla/mux" @@ -60,7 +61,7 @@ func main() { defer logger.Sync() zap.ReplaceGlobals(logger) - zap.L().Info("magneticow v0.8 has been started.") + zap.L().Info("magneticow v0.8.2 has been started.") zap.L().Info("Copyright (C) 2017-2019 Mert Bora ALPER .") zap.L().Info("Dedicated to Cemile Binay, in whose hands I thrived.") zap.S().Infof("Compiled on %s", compiledOn) @@ -287,7 +288,7 @@ func loadCred(cred string) error { */ re := regexp.MustCompile(`^[a-z](?:_?[a-z0-9])*:\$2[aby]?\$\d{1,2}\$[./A-Za-z0-9]{53}$`) if !re.Match(line) { - return fmt.Errorf("on line %d: format should be: :", lineno) + return fmt.Errorf("on line %d: format should be: :, instead got: %s", lineno, line) } tokens := bytes.Split(line, []byte(":")) diff --git a/docker-compose.yml b/docker-compose.yml index db22b07..42c125b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,4 @@ -version: "3" - -volumes: - home: +version: "2" services: magneticod: @@ -9,17 +6,22 @@ services: context: . dockerfile: Dockerfile.magneticod volumes: - - home:/home/magnetico + - magneticod-data:/root/.local/share/magneticod + - magneticod-config:/root/.config/magneticod magneticow: build: context: . dockerfile: Dockerfile.magneticow volumes: - - home:/home/magnetico + - magneticod-data:/root/.local/share/magneticod depends_on: # It doesn't necessarily "depend" on magneticod, but you would probably like to start them at the same time. - magneticod - ports: - "8080:8080" + +volumes: + magneticod-config: + + magneticod-data: