fix Docker setup

This commit is contained in:
Bora M. Alper 2019-09-18 01:21:30 +01:00
parent 93d424344a
commit 0e9dcba5b6
9 changed files with 44 additions and 48 deletions

View File

@ -16,7 +16,6 @@ before_install:
install: install:
- "go get -u -v github.com/kevinburke/go-bindata/..." - "go get -u -v github.com/kevinburke/go-bindata/..."
- "go get -u -v honnef.co/go/tools/cmd/staticcheck"
before_script: before_script:
- "make magneticod" - "make magneticod"

View File

@ -1,6 +1,7 @@
# Start from a Debian image with the latest version of Go installed # Start from a Debian image with the latest version of Go installed
# and a workspace (GOPATH) configured at /go. # 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 RUN apk add --no-cache build-base curl git
@ -10,15 +11,14 @@ ADD ./pkg /magnetico/pkg
ADD ./go.mod /magnetico/go.mod ADD ./go.mod /magnetico/go.mod
ADD ./cmd/magneticod /magnetico/cmd/magneticod ADD ./cmd/magneticod /magnetico/cmd/magneticod
WORKDIR /magnetico/
RUN make magneticod RUN make magneticod
FROM alpine:latest FROM alpine:latest
LABEL maintainer="bora@boramalper.org" LABEL maintainer="bora@boramalper.org"
WORKDIR / WORKDIR /
VOLUME /root/.local/share/magneticod
VOLUME /root/.config/magneticod
COPY --from=build /go/bin/magneticod /magneticod COPY --from=build /go/bin/magneticod /magneticod
RUN adduser -D -S magnetico
USER magnetico
ENTRYPOINT ["/magneticod"] ENTRYPOINT ["/magneticod"]

View File

@ -1,10 +1,11 @@
# Start from a Debian image with the latest version of Go installed # Start from a Debian image with the latest version of Go installed
# and a workspace (GOPATH) configured at /go. # 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 export PATH=$PATH:/go/bin
RUN apk add --no-cache build-base curl git 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. # Copy the local package files to the container's workspace.
ADD ./Makefile /magnetico/ ADD ./Makefile /magnetico/
@ -12,24 +13,18 @@ ADD ./pkg /magnetico/pkg
ADD ./go.mod /magnetico/go.mod ADD ./go.mod /magnetico/go.mod
ADD ./cmd/magneticow /magnetico/cmd/magneticow 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 RUN make magneticow
FROM alpine:latest FROM alpine:latest
LABEL maintainer="bora@boramalper.org" LABEL maintainer="bora@boramalper.org"
# the service listens on port 8080
EXPOSE 8080
WORKDIR / 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 COPY --from=build /go/bin/magneticow /magneticow
RUN adduser -D -S magnetico
USER magnetico
ENTRYPOINT ["/magneticow"] ENTRYPOINT ["/magneticow"]
# Document that the service listens on port 8080.
EXPOSE 8080

View File

@ -54,15 +54,12 @@ You need to mount
hence run: hence run:
```bash ```bash
docker run \ docker run -it --rm \
-v ~/.local/share/magneticod:/root/.local/share/magneticod/ \ -v ~/.local/share/magneticod:/root/.local/share/magneticod/ \
-v ~/.config/magneticod/configuration.toml:/root/.config/magneticod/configuration.toml \ -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 ### 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 **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 bandwidth. Unless you are running **magneticod** on a separate machine dedicated for it, you might want to consider

View File

@ -56,7 +56,7 @@ func main() {
return 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 <bora@boramalper.org>.") zap.L().Info("Copyright (C) 2017-2019 Mert Bora ALPER <bora@boramalper.org>.")
zap.L().Info("Dedicated to Cemile Binay, in whose hands I thrived.") zap.L().Info("Dedicated to Cemile Binay, in whose hands I thrived.")
zap.S().Infof("Compiled on %s", compiledOn) zap.S().Infof("Compiled on %s", compiledOn)

View File

@ -80,12 +80,14 @@ You need to mount
hence run: hence run:
```bash ```bash
docker run \ docker run -it --rm \
-v ~/.local/share/magneticod:/root/.local/share/magneticod/ \ -v ~/.local/share/magneticod:/root/.local/share/magneticod/ \
-v ~/.config/magneticow/configuration.toml:/root/.config/magneticow/configuration.toml \ -v ~/.config/magneticow/configuration.toml:/root/.config/magneticow/configuration.toml \
magneticow boramalper/magneticow
``` ```
Using Docker, the default username & password is `magnetico` and `magnetico`.
### Searching ### Searching
* Only the **titles** of the torrents are being searched. * Only the **titles** of the torrents are being searched.
* Search is case-insensitive. * Search is case-insensitive.

View File

@ -5,7 +5,6 @@ import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"github.com/pkg/errors"
"html/template" "html/template"
"io" "io"
"net/http" "net/http"
@ -17,6 +16,8 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/pkg/errors"
"github.com/Wessie/appdirs" "github.com/Wessie/appdirs"
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@ -60,7 +61,7 @@ func main() {
defer logger.Sync() defer logger.Sync()
zap.ReplaceGlobals(logger) 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 <bora@boramalper.org>.") zap.L().Info("Copyright (C) 2017-2019 Mert Bora ALPER <bora@boramalper.org>.")
zap.L().Info("Dedicated to Cemile Binay, in whose hands I thrived.") zap.L().Info("Dedicated to Cemile Binay, in whose hands I thrived.")
zap.S().Infof("Compiled on %s", compiledOn) 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}$`) re := regexp.MustCompile(`^[a-z](?:_?[a-z0-9])*:\$2[aby]?\$\d{1,2}\$[./A-Za-z0-9]{53}$`)
if !re.Match(line) { if !re.Match(line) {
return fmt.Errorf("on line %d: format should be: <USERNAME>:<BCRYPT HASH>", lineno) return fmt.Errorf("on line %d: format should be: <USERNAME>:<BCRYPT HASH>, instead got: %s", lineno, line)
} }
tokens := bytes.Split(line, []byte(":")) tokens := bytes.Split(line, []byte(":"))

View File

@ -1,7 +1,4 @@
version: "3" version: "2"
volumes:
home:
services: services:
magneticod: magneticod:
@ -9,17 +6,22 @@ services:
context: . context: .
dockerfile: Dockerfile.magneticod dockerfile: Dockerfile.magneticod
volumes: volumes:
- home:/home/magnetico - magneticod-data:/root/.local/share/magneticod
- magneticod-config:/root/.config/magneticod
magneticow: magneticow:
build: build:
context: . context: .
dockerfile: Dockerfile.magneticow dockerfile: Dockerfile.magneticow
volumes: volumes:
- home:/home/magnetico - magneticod-data:/root/.local/share/magneticod
depends_on: depends_on:
# It doesn't necessarily "depend" on magneticod, but you would probably like to start them at the same time. # It doesn't necessarily "depend" on magneticod, but you would probably like to start them at the same time.
- magneticod - magneticod
ports: ports:
- "8080:8080" - "8080:8080"
volumes:
magneticod-config:
magneticod-data: