Skip to content

Commit

Permalink
Merge pull request #12 from haugene/dev
Browse files Browse the repository at this point in the history
Externalized configuration by environment variables.
  • Loading branch information
haugene committed May 11, 2015
2 parents b4e4e19 + 3b2e2ee commit a43f605
Show file tree
Hide file tree
Showing 33 changed files with 554 additions and 171 deletions.
104 changes: 84 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,102 @@ MAINTAINER Kristian Haugene

VOLUME /data

# Update package sources list
RUN apt-get update

# Add transmission ppa repository for latest releases
RUN apt-get -y install software-properties-common
RUN add-apt-repository ppa:transmissionbt/ppa

# Update packages and install software
RUN apt-get update
RUN apt-get install -y transmission-cli
RUN apt-get install -y transmission-common
RUN apt-get install -y transmission-daemon
RUN apt-get install -y openvpn
RUN apt-get install -y curl

VOLUME /config
RUN apt-get update \
&& apt-get -y install software-properties-common \
&& add-apt-repository ppa:transmissionbt/ppa \
&& apt-get update \
&& apt-get install -y transmission-cli transmission-common transmission-daemon openvpn curl \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& curl -L https://github.com/jwilder/dockerize/releases/download/v0.0.2/dockerize-linux-amd64-v0.0.2.tar.gz | tar -C /usr/local/bin -xzv

# Add configuration and scripts
ADD piaconfig/config.ovpn /etc/openvpn/config.ovpn
ADD piaconfig/* /etc/openvpn/
ADD piaconfig/ca.crt /etc/openvpn/ca.crt
ADD piaconfig/crl.pem /etc/openvpn/crl.pem
ADD transmission/defaultSettings.json /etc/transmission-daemon/settings.json
ADD transmission/defaultSettings.tmpl /etc/transmission-daemon/settings.tmpl
ADD transmission/updateTransmissionPort.sh /etc/transmission-daemon/updatePort.sh
ADD transmission/periodicUpdates.sh /etc/transmission-daemon/periodicUpdates.sh
ADD transmission/run.sh /etc/transmission-daemon/start.sh
ADD transmission/runUpdates.sh /etc/transmission-daemon/startPortUpdates.sh
ADD transmission/down.sh /etc/transmission-daemon/stop.sh
ADD runOpenVpn.sh /etc/openvpn/start.sh

ENV PIA_USERNAME=**None** \
PIA_PASSWORD=**None** \
"TRANSMISSION_ALT_SPEED_DOWN=50" \
"TRANSMISSION_ALT_SPEED_ENABLED=false" \
"TRANSMISSION_ALT_SPEED_TIME_BEGIN=540" \
"TRANSMISSION_ALT_SPEED_TIME_DAY=127" \
"TRANSMISSION_ALT_SPEED_TIME_ENABLED=false" \
"TRANSMISSION_ALT_SPEED_TIME_END=1020" \
"TRANSMISSION_ALT_SPEED_UP=50" \
"TRANSMISSION_BIND_ADDRESS_IPV4=0.0.0.0" \
"TRANSMISSION_BIND_ADDRESS_IPV6=::" \
"TRANSMISSION_BLOCKLIST_ENABLED=false" \
"TRANSMISSION_BLOCKLIST_URL=http://www.example.com/blocklist" \
"TRANSMISSION_CACHE_SIZE_MB=4" \
"TRANSMISSION_DHT_ENABLED=true" \
"TRANSMISSION_DOWNLOAD_DIR=/data/completed" \
"TRANSMISSION_DOWNLOAD_LIMIT=100" \
"TRANSMISSION_DOWNLOAD_LIMIT_ENABLED=0" \
"TRANSMISSION_DOWNLOAD_QUEUE_ENABLED=true" \
"TRANSMISSION_DOWNLOAD_QUEUE_SIZE=5" \
"TRANSMISSION_ENCRYPTION=1" \
"TRANSMISSION_IDLE_SEEDING_LIMIT=30" \
"TRANSMISSION_IDLE_SEEDING_LIMIT_ENABLED=false" \
"TRANSMISSION_INCOMPLETE_DIR=/data/incomplete" \
"TRANSMISSION_INCOMPLETE_DIR_ENABLED=true" \
"TRANSMISSION_LPD_ENABLED=false" \
"TRANSMISSION_MAX_PEERS_GLOBAL=200" \
"TRANSMISSION_MESSAGE_LEVEL=2" \
"TRANSMISSION_PEER_CONGESTION_ALGORITHM=" \
"TRANSMISSION_PEER_ID_TTL_HOURS=6" \
"TRANSMISSION_PEER_LIMIT_GLOBAL=200" \
"TRANSMISSION_PEER_LIMIT_PER_TORRENT=50" \
"TRANSMISSION_PEER_PORT=51413" \
"TRANSMISSION_PEER_PORT_RANDOM_HIGH=65535" \
"TRANSMISSION_PEER_PORT_RANDOM_LOW=49152" \
"TRANSMISSION_PEER_PORT_RANDOM_ON_START=false" \
"TRANSMISSION_PEER_SOCKET_TOS=default" \
"TRANSMISSION_PEX_ENABLED=true" \
"TRANSMISSION_PORT_FORWARDING_ENABLED=false" \
"TRANSMISSION_PREALLOCATION=1" \
"TRANSMISSION_PREFETCH_ENABLED=1" \
"TRANSMISSION_QUEUE_STALLED_ENABLED=true" \
"TRANSMISSION_QUEUE_STALLED_MINUTES=30" \
"TRANSMISSION_RATIO_LIMIT=2" \
"TRANSMISSION_RATIO_LIMIT_ENABLED=false" \
"TRANSMISSION_RENAME_PARTIAL_FILES=true" \
"TRANSMISSION_RPC_AUTHENTICATION_REQUIRED=false" \
"TRANSMISSION_RPC_BIND_ADDRESS=0.0.0.0" \
"TRANSMISSION_RPC_ENABLED=true" \
"TRANSMISSION_RPC_PASSWORD=password" \
"TRANSMISSION_RPC_PORT=9091" \
"TRANSMISSION_RPC_URL=/transmission/" \
"TRANSMISSION_RPC_USERNAME=username" \
"TRANSMISSION_RPC_WHITELIST=127.0.0.1" \
"TRANSMISSION_RPC_WHITELIST_ENABLED=false" \
"TRANSMISSION_SCRAPE_PAUSED_TORRENTS_ENABLED=true" \
"TRANSMISSION_SCRIPT_TORRENT_DONE_ENABLED=false" \
"TRANSMISSION_SCRIPT_TORRENT_DONE_FILENAME=" \
"TRANSMISSION_SEED_QUEUE_ENABLED=false" \
"TRANSMISSION_SEED_QUEUE_SIZE=10" \
"TRANSMISSION_SPEED_LIMIT_DOWN=100" \
"TRANSMISSION_SPEED_LIMIT_DOWN_ENABLED=false" \
"TRANSMISSION_SPEED_LIMIT_UP=100" \
"TRANSMISSION_SPEED_LIMIT_UP_ENABLED=false" \
"TRANSMISSION_START_ADDED_TORRENTS=true" \
"TRANSMISSION_TRASH_ORIGINAL_TORRENT_FILES=false" \
"TRANSMISSION_UMASK=2" \
"TRANSMISSION_UPLOAD_LIMIT=100" \
"TRANSMISSION_UPLOAD_LIMIT_ENABLED=0" \
"TRANSMISSION_UPLOAD_SLOTS_PER_TORRENT=14" \
"TRANSMISSION_UTP_ENABLED=true" \
"TRANSMISSION_WATCH_DIR=/data/watch" \
"TRANSMISSION_WATCH_DIR_ENABLED=true" \
RESOLV_OVERRIDE=**None**

# Expose port and run. Use baseimage-docker's init system
EXPOSE 9091
CMD ["/etc/openvpn/start.sh"]

# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
71 changes: 58 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,64 @@ This Docker container lets you run Transmission with WebUI while connecting to P
The container is available from the Docker registry and this is the simplest way to get it. To run the container use this command:

```
$ docker run --privileged -d -v /your/storage/path/:/data -v /your/config/path/:/config -p 9091:9091 haugene/transmission-openvpn
$ docker run --privileged -d \
-v /your/storage/path/:/data \
-e "PIA_USERNAME=user" \
-e "PIA_PASSWORD=pass" \
-p 9091:9091 \
haugene/transmission-openvpn
```

As you can see, the container expects two volumes to be mounted. One is used for storing your downloads from Transmission, and the other provides configurations. The container comes with a default Transmission settings.json file that expects the folders "completed, incomplete and watch" to be present in /your/storage/path (aka /data). This is where Transmission will store your downloads, incomplete downloads and a watch directory to look for new .torrent files.
or you could optionally specify which vpn server to use by setting an environment variable to one of the ovpn configs avaliable [in this folder](https://github.com/haugene/docker-transmission-openvpn/tree/master/piaconfig).

The only mandatory configuration is a pia-credentials.txt file that needs to be put in /your/config/path/ directory. In the file you supply your username and password for Private Internet Access VPN connections. The file should have two lines; your username on line 1 and your password on line 2. The container will connect to the Private Internet Access VPN servers in Netherlands by default.
```
$ docker run --privileged -d \
-v /your/storage/path/:/data \
-e "PIA_USERNAME=user" \
-e "PIA_PASSWORD=pass" \
-p 9091:9091 \
-e "OPEN_VPN_CONFIG=US West" \
haugene/transmission-openvpn
```

As you can see, the container expects a data volume to be mounted. It is used for storing your downloads from Transmission. The container comes with a default Transmission `settings.json` file that expects the folders `completed`, `incomplete`, and `watch` to be present in /your/storage/path (aka /data). This is where Transmission will store your downloads, incomplete downloads and a watch directory to look for new .torrent files.

The only mandatory configuration is to set two environment variables for your PIA username and password. You must set the environment variables `PIA_USERNAME` and `PIA_PASSWORD` to your login credentials. The container will connect to the Private Internet Access VPN servers in Netherlands by default.

NB: Instructions on how to use your own Transmission settings, and how to connect to the WebUI, is further down in the README.

## Required environment options
| Variable | Function | Example |
|----------|----------|-------|
|`PIA_USERNAME`|Your login username for PIA|`PIA_USERNAME=asdf`|
|`PIA_PASSWORD`|Your login password for PIA|`PIA_PASSWORD=asdf`|

## Network configuration options
| Variable | Function | Example |
|----------|----------|-------|
|`OPEN_VPN_CONFIG` | Sets the PIA endpoint to connect to. | `OPEN_VPN_CONFIG=UK Southampton`|
|`RESOLV_OVERRIDE` | The value of this variable will be written to `/etc/resolv.conf`. | `RESOLV_OVERRIDE=nameserver 8.8.8.8\nnameserver 8.8.4.4\n`|

## Storage options
| Variable | Function | Example |
|----------|----------|-------|
|`KEEP_TRANSMISSION_STATE`|If set, persists transmission data to your /data mount point. Keeps state between restarts. Delete the folder to disable this later. |`KEEP_TRANSMISSION_STATE=YES`|

## Transmission configuration options

You may override transmission options by setting the appropriate environment variable.

The environment variables are the same name as used in the transmission settings.json file and follow the format given in these examples:

| Transmission variable name | Environment variable name |
|----------------------------|---------------------------|
| `speed-limit-up` | `TRANSMISSION_SPEED_LIMIT_UP` |
| `speed-limit-up-enabled` | `TRANSMISSION_SPEED_LIMIT_UP_ENABLED` |
| `ratio-limit` | `TRANSMISSION_RATIO_LIMIT` |
| `ratio-limit-enabled` | `TRANSMISSION_RATIO_LIMIT_ENABLED` |

As you can see the variables are prefixed with `TRANSMISSION_`, the variable is capitalized, and `-` is converted to `_`.

# Building the container yourself
To build this container, clone the repository and cd into it.

Expand All @@ -25,20 +74,16 @@ $ docker build -t="docker-transmission-openvpn" .
```
### Run it:
```
$ docker run --privileged -d -v /your/storage/path/:/data -v /your/config/path/:/config -p 9091:9091 docker-transmission-openvpn
$ docker run --privileged -d \
-v /your/storage/path/:/data \
-e "PIA_USERNAME=user" \
-e "PIA_PASSWORD=pass" \
-p 9091:9091 \
docker-transmission-openvpn
```

As described in the "Run container from Docker registry" section, this will start a container with default settings. This means that you should have the folders "completed, incomplete and watch" in /your/storage/path, and pia-credentials.txt in /your/config/path.

### But I want to provide my own Transmission settings!
OK, so you're advanced. If you want to change the Transmission settings from the defaults, create your own settings.json file or base it on the default config. Then make the container use it by adding a folder called "transmission" in /your/config/path and place your settings.json there.

On container startup it checks for /config/transmission/settings.json and uses /config/transmission as config directory if the settings file is present. This also means that Transmission will store its state here, so that you don't have to add torrents again when the container restarts.

If you enable rpc-authentication in your Transmission settings, you need to provide your credentials in a file called transmission-credentials.txt and place it in your config directory. The file is on the same format as pia-credentials.txt, username and password. This is needed because we run a script hourly to get an open port, making us connectable, from PIA. To set this port in Transmission the script needs to know your rpc-authentication username and password.

NB: Do not change the settings.json file while container is running. Transmission persist its config on shutdown, and this will override your changes. Stop the container, do configurations, then start it again.

### Access the WebUI
But what's going on? My http://my-host:9091 isn't responding?
This is because the VPN is active, and since docker is running in a different ip range than your client the response to your request will be treated as "non-local" traffic and therefore be routed out through the VPN interface.
Expand Down
22 changes: 22 additions & 0 deletions piaconfig/AU Melbourne.ovpn
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
client
dev tun
proto udp
remote aus-melbourne.privateinternetaccess.com 1194
resolv-retry infinite
nobind
persist-key
persist-tun
tls-client
remote-cert-tls server
comp-lzo
verb 1
reneg-sec 0

ca /etc/openvpn/ca.crt
auth-user-pass /config/pia-credentials.txt
crl-verify /etc/openvpn/crl.pem

# OpenVPN control startup and shut down of transmission
script-security 2
up /etc/transmission-daemon/start.sh
down /etc/transmission-daemon/stop.sh
22 changes: 22 additions & 0 deletions piaconfig/AU Sydney.ovpn
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
client
dev tun
proto udp
remote aus.privateinternetaccess.com 1194
resolv-retry infinite
nobind
persist-key
persist-tun
tls-client
remote-cert-tls server
comp-lzo
verb 1
reneg-sec 0

ca /etc/openvpn/ca.crt
auth-user-pass /config/pia-credentials.txt
crl-verify /etc/openvpn/crl.pem

# OpenVPN control startup and shut down of transmission
script-security 2
up /etc/transmission-daemon/start.sh
down /etc/transmission-daemon/stop.sh
10 changes: 7 additions & 3 deletions piaconfig/CA North York.ovpn
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
tls-client
remote-cert-tls server
auth-user-pass
comp-lzo
verb 1
reneg-sec 0
crl-verify crl.pem

ca /etc/openvpn/ca.crt
auth-user-pass /config/pia-credentials.txt
crl-verify /etc/openvpn/crl.pem

# OpenVPN control startup and shut down of transmission
script-security 2
up /etc/transmission-daemon/start.sh
down /etc/transmission-daemon/stop.sh
10 changes: 7 additions & 3 deletions piaconfig/CA Toronto.ovpn
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
tls-client
remote-cert-tls server
auth-user-pass
comp-lzo
verb 1
reneg-sec 0
crl-verify crl.pem

ca /etc/openvpn/ca.crt
auth-user-pass /config/pia-credentials.txt
crl-verify /etc/openvpn/crl.pem

# OpenVPN control startup and shut down of transmission
script-security 2
up /etc/transmission-daemon/start.sh
down /etc/transmission-daemon/stop.sh
10 changes: 7 additions & 3 deletions piaconfig/France.ovpn
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
tls-client
remote-cert-tls server
auth-user-pass
comp-lzo
verb 1
reneg-sec 0
crl-verify crl.pem

ca /etc/openvpn/ca.crt
auth-user-pass /config/pia-credentials.txt
crl-verify /etc/openvpn/crl.pem

# OpenVPN control startup and shut down of transmission
script-security 2
up /etc/transmission-daemon/start.sh
down /etc/transmission-daemon/stop.sh
10 changes: 7 additions & 3 deletions piaconfig/Germany.ovpn
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
tls-client
remote-cert-tls server
auth-user-pass
comp-lzo
verb 1
reneg-sec 0
crl-verify crl.pem

ca /etc/openvpn/ca.crt
auth-user-pass /config/pia-credentials.txt
crl-verify /etc/openvpn/crl.pem

# OpenVPN control startup and shut down of transmission
script-security 2
up /etc/transmission-daemon/start.sh
down /etc/transmission-daemon/stop.sh
10 changes: 7 additions & 3 deletions piaconfig/Hong Kong.ovpn
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
tls-client
remote-cert-tls server
auth-user-pass
comp-lzo
verb 1
reneg-sec 0
crl-verify crl.pem

ca /etc/openvpn/ca.crt
auth-user-pass /config/pia-credentials.txt
crl-verify /etc/openvpn/crl.pem

# OpenVPN control startup and shut down of transmission
script-security 2
up /etc/transmission-daemon/start.sh
down /etc/transmission-daemon/stop.sh
22 changes: 22 additions & 0 deletions piaconfig/Israel.ovpn
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
client
dev tun
proto udp
remote israel.privateinternetaccess.com 1194
resolv-retry infinite
nobind
persist-key
persist-tun
tls-client
remote-cert-tls server
comp-lzo
verb 1
reneg-sec 0

ca /etc/openvpn/ca.crt
auth-user-pass /config/pia-credentials.txt
crl-verify /etc/openvpn/crl.pem

# OpenVPN control startup and shut down of transmission
script-security 2
up /etc/transmission-daemon/start.sh
down /etc/transmission-daemon/stop.sh
Loading

0 comments on commit a43f605

Please sign in to comment.