Added PIA username/password to env vars

Added transmission settings to env vars. Fixed #8.
Updated readme.
Added ability to override /etc/resolv.conf. Fixes #4.
Save docker image size by combining all apt commands into a single RUN statement.
This commit is contained in:
Ian Neubert 2015-05-09 12:49:07 -07:00
parent 29618ffbcb
commit 268480358d
4 changed files with 215 additions and 98 deletions

View File

@ -7,22 +7,14 @@ MAINTAINER Kristian Haugene
VOLUME /data 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 # Update packages and install software
RUN apt-get update RUN apt-get update \
RUN apt-get install -y transmission-cli && apt-get -y install software-properties-common \
RUN apt-get install -y transmission-common && add-apt-repository ppa:transmissionbt/ppa \
RUN apt-get install -y transmission-daemon && apt-get update \
RUN apt-get install -y openvpn && apt-get install -y transmission-cli transmission-common transmission-daemon openvpn curl \
RUN apt-get install -y 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
VOLUME /config
# Add configuration and scripts # Add configuration and scripts
ADD piaconfig/* /etc/openvpn/ ADD piaconfig/* /etc/openvpn/
@ -36,9 +28,81 @@ ADD transmission/runUpdates.sh /etc/transmission-daemon/startPortUpdates.sh
ADD transmission/down.sh /etc/transmission-daemon/stop.sh ADD transmission/down.sh /etc/transmission-daemon/stop.sh
ADD runOpenVpn.sh /etc/openvpn/start.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={425745bf3914984c2abcc013276f40e8fa5d84ecC5.df8oF" \
"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 port and run. Use baseimage-docker's init system
EXPOSE 9091 EXPOSE 9091
CMD ["/etc/openvpn/start.sh"] CMD ["/etc/openvpn/start.sh"]
# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

View File

@ -8,26 +8,55 @@ The container is available from the Docker registry and this is the simplest way
``` ```
$ docker run --privileged -d \ $ docker run --privileged -d \
-v /your/storage/path/:/data \ -v /your/storage/path/:/data \
-v /your/config/path/:/config \ -e "PIA_USERNAME=user" \
-e "PIA_PASSWORD=pass" \
-p 9091:9091 \ -p 9091:9091 \
haugene/transmission-openvpn haugene/transmission-openvpn
``` ```
or you could optionally specify which vpn server to use by setting an environment variable to one of the ovpn configs avaliable in <a href="https://github.com/haugene/docker-transmission-openvpn/tree/master/piaconfig">this folder</a>. 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).
``` ```
$ docker run --privileged -d \ $ docker run --privileged -d \
-v /your/storage/path/:/data \ -v /your/storage/path/:/data \
-v /your/config/path/:/config \ -e "PIA_USERNAME=user" \
-e "PIA_PASSWORD=pass" \
-p 9091:9091 \ -p 9091:9091 \
-e "OPEN_VPN_CONFIG=US West" \ -e "OPEN_VPN_CONFIG=US West" \
haugene/transmission-openvpn 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. 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 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. 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. 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`|
## 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 # Building the container yourself
To build this container, clone the repository and cd into it. To build this container, clone the repository and cd into it.
@ -40,7 +69,8 @@ $ docker build -t="docker-transmission-openvpn" .
``` ```
$ docker run --privileged -d \ $ docker run --privileged -d \
-v /your/storage/path/:/data \ -v /your/storage/path/:/data \
-v /your/config/path/:/config \ -e "PIA_USERNAME=user" \
-e "PIA_PASSWORD=pass" \
-p 9091:9091 \ -p 9091:9091 \
docker-transmission-openvpn docker-transmission-openvpn
``` ```

View File

@ -5,14 +5,37 @@ then
if [ -f /etc/openvpn/"${OPEN_VPN_CONFIG}".ovpn ] if [ -f /etc/openvpn/"${OPEN_VPN_CONFIG}".ovpn ]
then then
echo "Starting OpenVPN using config ${OPEN_VPN_CONFIG}.ovpn" echo "Starting OpenVPN using config ${OPEN_VPN_CONFIG}.ovpn"
exec openvpn --config /etc/openvpn/"${OPEN_VPN_CONFIG}".ovpn OPEN_VPN_CONFIG=/etc/openvpn/${OPEN_VPN_CONFIG}.ovpn
else else
echo "Supplied config ${OPEN_VPN_CONFIG}.ovpn could not be found." echo "Supplied config ${OPEN_VPN_CONFIG}.ovpn could not be found."
echo "Using default OpenVPN gateway: Netherlands" echo "Using default OpenVPN gateway: Netherlands"
exec openvpn --config /etc/openvpn/Netherlands.ovpn OPEN_VPN_CONFIG=/etc/openvpn/Netherlands.ovpn
fi fi
else else
echo "No VPN configuration provided. Using default: Netherlands" echo "No VPN configuration provided. Using default: Netherlands"
exec openvpn --config /etc/openvpn/Netherlands.ovpn OPEN_VPN_CONFIG=/etc/openvpn/Netherlands.ovpn
fi fi
# override resolv.conf
if [ "$RESOLV_OVERRIDE" != "**None**" ];
then
echo "Overriding resolv.conf..."
printf "$RESOLV_OVERRIDE" > /etc/resolv.conf
fi
# add PIA user/pass
if [ "$PIA_USERNAME" != "**None**" ];
then
echo "Setting PIA credentials..."
mkdir -p /config
echo $PIA_USERNAME > /config/pia-credentials.txt
echo $PIA_PASSWORD >> /config/pia-credentials.txt
else
echo "Not setting PIA credentials."
fi
dockerize \
-template /etc/transmission-daemon/settings.json:/etc/transmission-daemon/settings.json \
true
exec openvpn --config "$OPEN_VPN_CONFIG"

View File

@ -1,74 +1,74 @@
{ {
"alt-speed-down": 50, "alt-speed-down": {{ .Env.TRANSMISSION_ALT_SPEED_DOWN }},
"alt-speed-enabled": false, "alt-speed-enabled": {{ .Env.TRANSMISSION_ALT_SPEED_ENABLED }},
"alt-speed-time-begin": 540, "alt-speed-time-begin": {{ .Env.TRANSMISSION_ALT_SPEED_TIME_BEGIN }},
"alt-speed-time-day": 127, "alt-speed-time-day": {{ .Env.TRANSMISSION_ALT_SPEED_TIME_DAY }},
"alt-speed-time-enabled": false, "alt-speed-time-enabled": {{ .Env.TRANSMISSION_ALT_SPEED_TIME_ENABLED }},
"alt-speed-time-end": 1020, "alt-speed-time-end": {{ .Env.TRANSMISSION_ALT_SPEED_TIME_END }},
"alt-speed-up": 50, "alt-speed-up": {{ .Env.TRANSMISSION_ALT_SPEED_UP }},
"bind-address-ipv4": "0.0.0.0", "bind-address-ipv4": "{{ .Env.TRANSMISSION_BIND_ADDRESS_IPV4 }}",
"bind-address-ipv6": "::", "bind-address-ipv6": "{{ .Env.TRANSMISSION_BIND_ADDRESS_IPV6 }}",
"blocklist-enabled": false, "blocklist-enabled": {{ .Env.TRANSMISSION_BLOCKLIST_ENABLED }},
"blocklist-url": "http://www.example.com/blocklist", "blocklist-url": "{{ .Env.TRANSMISSION_BLOCKLIST_URL }}",
"cache-size-mb": 4, "cache-size-mb": {{ .Env.TRANSMISSION_CACHE_SIZE_MB }},
"dht-enabled": true, "dht-enabled": {{ .Env.TRANSMISSION_DHT_ENABLED }},
"download-dir": "/data/completed", "download-dir": "{{ .Env.TRANSMISSION_DOWNLOAD_DIR }}",
"download-limit": 100, "download-limit": {{ .Env.TRANSMISSION_DOWNLOAD_LIMIT }},
"download-limit-enabled": 0, "download-limit-enabled": {{ .Env.TRANSMISSION_DOWNLOAD_LIMIT_ENABLED }},
"download-queue-enabled": true, "download-queue-enabled": {{ .Env.TRANSMISSION_DOWNLOAD_QUEUE_ENABLED }},
"download-queue-size": 5, "download-queue-size": {{ .Env.TRANSMISSION_DOWNLOAD_QUEUE_SIZE }},
"encryption": 1, "encryption": {{ .Env.TRANSMISSION_ENCRYPTION }},
"idle-seeding-limit": 30, "idle-seeding-limit": {{ .Env.TRANSMISSION_IDLE_SEEDING_LIMIT }},
"idle-seeding-limit-enabled": false, "idle-seeding-limit-enabled": {{ .Env.TRANSMISSION_IDLE_SEEDING_LIMIT_ENABLED }},
"incomplete-dir": "/data/incomplete", "incomplete-dir": "{{ .Env.TRANSMISSION_INCOMPLETE_DIR }}",
"incomplete-dir-enabled": true, "incomplete-dir-enabled": {{ .Env.TRANSMISSION_INCOMPLETE_DIR_ENABLED }},
"lpd-enabled": false, "lpd-enabled": {{ .Env.TRANSMISSION_LPD_ENABLED }},
"max-peers-global": 200, "max-peers-global": {{ .Env.TRANSMISSION_MAX_PEERS_GLOBAL }},
"message-level": 2, "message-level": {{ .Env.TRANSMISSION_MESSAGE_LEVEL }},
"peer-congestion-algorithm": "", "peer-congestion-algorithm": "{{ .Env.TRANSMISSION_PEER_CONGESTION_ALGORITHM }}",
"peer-id-ttl-hours": 6, "peer-id-ttl-hours": {{ .Env.TRANSMISSION_PEER_ID_TTL_HOURS }},
"peer-limit-global": 200, "peer-limit-global": {{ .Env.TRANSMISSION_PEER_LIMIT_GLOBAL }},
"peer-limit-per-torrent": 50, "peer-limit-per-torrent": {{ .Env.TRANSMISSION_PEER_LIMIT_PER_TORRENT }},
"peer-port": 51413, "peer-port": {{ .Env.TRANSMISSION_PEER_PORT }},
"peer-port-random-high": 65535, "peer-port-random-high": {{ .Env.TRANSMISSION_PEER_PORT_RANDOM_HIGH }},
"peer-port-random-low": 49152, "peer-port-random-low": {{ .Env.TRANSMISSION_PEER_PORT_RANDOM_LOW }},
"peer-port-random-on-start": false, "peer-port-random-on-start": {{ .Env.TRANSMISSION_PEER_PORT_RANDOM_ON_START }},
"peer-socket-tos": "default", "peer-socket-tos": "{{ .Env.TRANSMISSION_PEER_SOCKET_TOS }}",
"pex-enabled": true, "pex-enabled": {{ .Env.TRANSMISSION_PEX_ENABLED }},
"port-forwarding-enabled": false, "port-forwarding-enabled": {{ .Env.TRANSMISSION_PORT_FORWARDING_ENABLED }},
"preallocation": 1, "preallocation": {{ .Env.TRANSMISSION_PREALLOCATION }},
"prefetch-enabled": 1, "prefetch-enabled": {{ .Env.TRANSMISSION_PREFETCH_ENABLED }},
"queue-stalled-enabled": true, "queue-stalled-enabled": {{ .Env.TRANSMISSION_QUEUE_STALLED_ENABLED }},
"queue-stalled-minutes": 30, "queue-stalled-minutes": {{ .Env.TRANSMISSION_QUEUE_STALLED_MINUTES }},
"ratio-limit": 2, "ratio-limit": {{ .Env.TRANSMISSION_RATIO_LIMIT }},
"ratio-limit-enabled": false, "ratio-limit-enabled": {{ .Env.TRANSMISSION_RATIO_LIMIT_ENABLED }},
"rename-partial-files": true, "rename-partial-files": {{ .Env.TRANSMISSION_RENAME_PARTIAL_FILES }},
"rpc-authentication-required": false, "rpc-authentication-required": {{ .Env.TRANSMISSION_RPC_AUTHENTICATION_REQUIRED }},
"rpc-bind-address": "0.0.0.0", "rpc-bind-address": "{{ .Env.TRANSMISSION_RPC_BIND_ADDRESS }}",
"rpc-enabled": true, "rpc-enabled": {{ .Env.TRANSMISSION_RPC_ENABLED }},
"rpc-password": "{425745bf3914984c2abcc013276f40e8fa5d84ecC5.df8oF", "rpc-password": "{{ .Env.TRANSMISSION_RPC_PASSWORD }}",
"rpc-port": 9091, "rpc-port": {{ .Env.TRANSMISSION_RPC_PORT }},
"rpc-url": "/transmission/", "rpc-url": "{{ .Env.TRANSMISSION_RPC_URL }}",
"rpc-username": "username", "rpc-username": "{{ .Env.TRANSMISSION_RPC_USERNAME }}",
"rpc-whitelist": "127.0.0.1", "rpc-whitelist": "{{ .Env.TRANSMISSION_RPC_WHITELIST }}",
"rpc-whitelist-enabled": false, "rpc-whitelist-enabled": {{ .Env.TRANSMISSION_RPC_WHITELIST_ENABLED }},
"scrape-paused-torrents-enabled": true, "scrape-paused-torrents-enabled": {{ .Env.TRANSMISSION_SCRAPE_PAUSED_TORRENTS_ENABLED }},
"script-torrent-done-enabled": false, "script-torrent-done-enabled": {{ .Env.TRANSMISSION_SCRIPT_TORRENT_DONE_ENABLED }},
"script-torrent-done-filename": "", "script-torrent-done-filename": "{{ .Env.TRANSMISSION_SCRIPT_TORRENT_DONE_FILENAME }}",
"seed-queue-enabled": false, "seed-queue-enabled": {{ .Env.TRANSMISSION_SEED_QUEUE_ENABLED }},
"seed-queue-size": 10, "seed-queue-size": {{ .Env.TRANSMISSION_SEED_QUEUE_SIZE }},
"speed-limit-down": 100, "speed-limit-down": {{ .Env.TRANSMISSION_SPEED_LIMIT_DOWN }},
"speed-limit-down-enabled": false, "speed-limit-down-enabled": {{ .Env.TRANSMISSION_SPEED_LIMIT_DOWN_ENABLED }},
"speed-limit-up": 100, "speed-limit-up": {{ .Env.TRANSMISSION_SPEED_LIMIT_UP }},
"speed-limit-up-enabled": false, "speed-limit-up-enabled": {{ .Env.TRANSMISSION_SPEED_LIMIT_UP_ENABLED }},
"start-added-torrents": true, "start-added-torrents": {{ .Env.TRANSMISSION_START_ADDED_TORRENTS }},
"trash-original-torrent-files": false, "trash-original-torrent-files": {{ .Env.TRANSMISSION_TRASH_ORIGINAL_TORRENT_FILES }},
"umask": 2, "umask": {{ .Env.TRANSMISSION_UMASK }},
"upload-limit": 100, "upload-limit": {{ .Env.TRANSMISSION_UPLOAD_LIMIT }},
"upload-limit-enabled": 0, "upload-limit-enabled": {{ .Env.TRANSMISSION_UPLOAD_LIMIT_ENABLED }},
"upload-slots-per-torrent": 14, "upload-slots-per-torrent": {{ .Env.TRANSMISSION_UPLOAD_SLOTS_PER_TORRENT }},
"utp-enabled": true, "utp-enabled": {{ .Env.TRANSMISSION_UTP_ENABLED }},
"watch-dir": "/data/watch", "watch-dir": "{{ .Env.TRANSMISSION_WATCH_DIR }}",
"watch-dir-enabled": true "watch-dir-enabled": {{ .Env.TRANSMISSION_WATCH_DIR_ENABLED }}
} }