Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
huseyz committed Jun 16, 2024
1 parent 449b348 commit 22de2dd
Show file tree
Hide file tree
Showing 24 changed files with 1,400 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# syntax=docker/dockerfile:1

FROM golang:1.22.3

# Set destination for COPY
WORKDIR /app

# Download Go modules
COPY go.mod go.sum ./
RUN go mod download

COPY . ./

# Build
RUN CGO_ENABLED=0 GOOS=linux go build -o /dockarr cmd/dockarr/main.go

# Run
CMD ["/dockarr"]
100 changes: 100 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Dockarr

> Dockarr is still pre-release. Use at your own risk.
Dockarr is a companion app for people running the [\*arr](https://wiki.servarr.com/) stack using docker-compose and using [Prowlarr](https://wiki.servarr.com/prowlarr) to keep Indexers in sync.

Dockarr automatically discovers your "\*arr" services and adds them to the discovered Prowlarr instance as applications. It runs in an infite loop to apply the future changes.

It also adds the discovered download clients to discovered \*arr services.

By default, Dockarr uses your docker container name as the hostname, extracts the service apiKey, urlBase, protocol and the port from the `config.xml` file.

It currently supports:

Arr* services:

- Radarr
- Sonarr
- Lidarr
- Readarr

Download clients:

- Transmission


Coming later:

- Other \*arr services: LazyLibrarian, Mylar, Whisparr etc.
- Download clients: SABnzbd etc.

## Usage

1. Add dockarr to your `docker-compose.yaml` and mount docker socket to it.
2. Label your \*arr services with discovery label: `dockarr.discover`
3. Profit?

```
dockarr:
container_name: dockarr
image: ghcr.io/huseyz/dockarr:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock
```

```
prowlarr:
container_name: prowlarr
image: ghcr.io/hotio/prowlarr:latest
restart: unless-stopped
ports:
- 9696:9696
labels:
- dockarr.discover
sonarr:
container_name: sonarr
image: ghcr.io/hotio/sonarr:latest
restart: unless-stopped
ports:
- 8989:8989
labels:
- dockarr.discover
```

Check the example docker-compose file [here](https://github.com/huseyz/dockarr/blob/main/deploy/docker-compose.yaml) for a more complete example.

## Configuration

Dockarr has two types of configuration support. For general config it uses environment variables. For service specific configuration, use labels.

### Environment variables

| Environment Variable | Description | Default | Possible Values |
| -------------------- | ---------------------------------------------------------------------------------------- | ------- | ------------------------ |
| LOG_LEVEL | Log level for the Dockarr service. | Info | Debug, Info, Warn, Error |
| DELETE_BEHAVIOUR | When Dockarr does not discover an existing *arr application, this tells it what to do | Ignore | Delete, Disable, Ignore |
| SYNC_INTERVAL | The interval Dockarr discovers and syncs your services, in seconds. | 60 | Any integer |

### Labels

You can override certain settings per service using docker labels.

#### *arr Services

You can override the SyncLevel or the complete address of a service.

| Label | Description |
| -------------------------- | ----------------------------------------------------------------------------------------------------------- |
| dockarr.override.address | Full address of the application, including protocol(http(s)), hostname, port and base url. |
| dockarr.override.syncLevel | By default Dockarr sets application-indexer sync level to fullSync. Use `addOnly` or `disabled` to override |

#### Transmission

| Label | Description |
| -------------------------- | ----------------------------------------------------------------------------------------------------------- |
| dockarr.override.host | Hostname of the transmision |
| dockarr.override.port | Port of the transmision |
| dockarr.override.ssl | Whether to use SSL for the transmision connection |
| dockarr.override.urlbase | RPC Url base of transmision |
48 changes: 48 additions & 0 deletions cmd/dockarr/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"fmt"
"log/slog"
"os"
"time"

"github.com/docker/docker/client"
"github.com/huseyz/dockarr/internal/config"
"github.com/huseyz/dockarr/internal/dockerclient"
"github.com/huseyz/dockarr/internal/service"
"github.com/huseyz/dockarr/internal/syncer"
)

func sync(discoverer *service.ServiceDiscoverer, syncer *syncer.Syncer) {
slog.Debug("Syncing...")

services, _ := discoverer.DiscoverServices()

syncer.SyncServices(services)

}

func main() {
dockarrConfig := config.InitConfig()
slog.Info("Initializing Dockarr", "Config", fmt.Sprintf("%+v\n", dockarrConfig))

logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: dockarrConfig.LogLevel}))
slog.SetDefault(logger)

cli, _ := client.NewClientWithOpts(client.FromEnv)

dockerClient := dockerclient.NewClient(cli)

discoverer := service.NewServiceDiscoverer(dockerClient)
syncer := syncer.NewSyncer(dockarrConfig, dockerClient)

slog.Info("Starting the sync loop.", "sync interval", dockarrConfig.SyncInterval)
sync(discoverer, syncer)

ticker := time.NewTicker(dockarrConfig.SyncInterval)
defer ticker.Stop()

for range ticker.C {
sync(discoverer, syncer)
}
}
90 changes: 90 additions & 0 deletions deploy/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
services:
prowlarr:
container_name: prowlarr
image: ghcr.io/hotio/prowlarr:latest
restart: unless-stopped
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/Luxembourg
ports:
- 9696:9696
labels:
- dockarr.discover

sonarr:
container_name: sonarr
image: ghcr.io/hotio/sonarr:latest
restart: unless-stopped
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/Luxembourg
ports:
- 8989:8989
labels:
- dockarr.discover

radarr:
container_name: radarr
image: ghcr.io/hotio/radarr:latest
restart: unless-stopped
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/Luxembourg
ports:
- 7878:7878
labels:
- dockarr.discover

lidarr:
container_name: lidarr
image: ghcr.io/hotio/lidarr
ports:
- "8686:8686"
environment:
- PUID=1000
- PGID=1000
- UMASK=002
- TZ=Etc/UTC
labels:
- dockarr.discover

readarr:
container_name: readarr
image: ghcr.io/hotio/readarr
ports:
- "8787:8787"
environment:
- PUID=1000
- PGID=1000
- UMASK=002
- TZ=Etc/UTC
labels:
- dockarr.discover

transmission:
image: linuxserver/transmission:latest
container_name: transmission
restart: unless-stopped
environment:
- PGID=1000
- PUID=1000
- TZ=Etc/UTC
- USER=user
- PASS=pass
ports:
- 9091:9091
labels:
- dockarr.discover

dockarr:
container_name: dockarr
image: dockarr
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
- DELETE_BEHAVIOUR=disable
- LOG_LEVEL=debug
- SYNC_INTERVAL=10
24 changes: 24 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module github.com/huseyz/dockarr

go 1.22.3

require (
github.com/Microsoft/go-winio v0.4.14 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v26.1.4+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect
go.opentelemetry.io/otel v1.27.0 // indirect
go.opentelemetry.io/otel/metric v1.27.0 // indirect
go.opentelemetry.io/otel/trace v1.27.0 // indirect
golang.org/x/sys v0.1.0 // indirect
)
77 changes: 77 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
github.com/Microsoft/go-winio v0.4.14 h1:+hMXMk01us9KgxGb7ftKQt2Xpf5hH/yky+TDA+qxleU=
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/docker v26.1.4+incompatible h1:vuTpXDuoga+Z38m1OZHzl7NKisKWaWlhjQk7IDPSLsU=
github.com/docker/docker v26.1.4+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v27.0.0+incompatible h1:JRugTYuelmWlW0M3jakcIadDx2HUoUO6+Tf2C5jVfwA=
github.com/docker/docker v27.0.0+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 h1:9l89oX4ba9kHbBol3Xin3leYJ+252h0zszDtBwyKe2A=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0/go.mod h1:XLZfZboOJWHNKUv7eH0inh0E9VV6eWDFB/9yJyTLPp0=
go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg=
go.opentelemetry.io/otel v1.27.0/go.mod h1:DMpAK8fzYRzs+bi3rS5REupisuqTheUlSZJ1WnZaPAQ=
go.opentelemetry.io/otel/metric v1.27.0 h1:hvj3vdEKyeCi4YaYfNjv2NUje8FqKqUY8IlF0FxV/ik=
go.opentelemetry.io/otel/metric v1.27.0/go.mod h1:mVFgmRlhljgBiuk/MP/oKylr4hs85GZAylncepAX/ak=
go.opentelemetry.io/otel/trace v1.27.0 h1:IqYb813p7cmbHk0a5y6pD5JPakbVfftRXABGt5/Rscw=
go.opentelemetry.io/otel/trace v1.27.0/go.mod h1:6RiD1hkAprV4/q+yd2ln1HG9GoPx39SuvvstaLBl+l4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Loading

0 comments on commit 22de2dd

Please sign in to comment.