Skip to content

Commit 5aeb83b

Browse files
committed
adding rough draft docs for review
1 parent c02f8e7 commit 5aeb83b

File tree

6 files changed

+236
-3
lines changed

6 files changed

+236
-3
lines changed

.travis.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
sudo: true
2+
3+
language: bash
4+
5+
services:
6+
- docker
7+
8+
env:
9+
global:
10+
- DOCKERHUB="user/endpoint"
11+
12+
jobs:
13+
include:
14+
- stage: BuildImage
15+
if: (NOT (type IN (pull_request)))
16+
script:
17+
# Build image
18+
- docker build --no-cache -t ${DOCKERHUB}:${TRAVIS_COMMIT} .
19+
- docker tag ${DOCKERHUB}:${TRAVIS_COMMIT} ${DOCKERHUB}:latest
20+
# Login to DockerHub
21+
- echo $DOCKERPASS | docker login -u $DOCKERUSER --password-stdin
22+
# Push all of the tags
23+
- docker push ${DOCKERHUB}:${TRAVIS_COMMIT}
24+
- docker push ${DOCKERHUB}:latest

Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM scratch
2+
3+
# copy local files
4+
COPY root/ /

Dockerfile.complex

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Buildstage ##
2+
FROM lsiobase/alpine:3.9 as buildstage
3+
4+
RUN \
5+
echo "**** install packages ****" && \
6+
apk add --no-cache \
7+
curl && \
8+
echo "**** grab rclone ****" && \
9+
mkdir -p /root-layer && \
10+
curl -o \
11+
/root-layer/rclone.deb -L \
12+
"https://downloads.rclone.org/v1.47.0/rclone-v1.47.0-linux-amd64.deb"
13+
14+
# copy local files
15+
COPY root/ /root-layer/
16+
17+
## Single layer deployed image ##
18+
FROM scratch
19+
20+
# Add files from buildstage
21+
COPY --from=buildstage /root-layer/ /

README.md

+157-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,159 @@
1-
THIS IS NOT SOMETHING FOR PUBLIC USE
1+
# Intro
22

3-
YOU HAVE BEEN WARNED !!!!
3+
The purpose of the repository is to provide examples and guidance in creating and storing a user consumable modification layer for the Library of Linuxserver.io Dockerhub Containers.
4+
At it's core a Docker Mod is a tarball of files stored on Dockerhub that is downloaded and extracted on container boot before any init logic is run.
5+
This allows:
46

5-
HERE BE DRAGONS
7+
* Developers and community users to modify base containers to suit their needs without the need to maintain a fork of the main docker repository
8+
* Mods to be shared with the Linuxserver.io userbase as individual independent projects with their own support channels and development ideologies
9+
* Zero cost hosting and build pipelines for these modifications leveraging Github and Dockerhub
10+
* Full custom configuration management layers for hooking containers into each other using environment variables contained in a compose file
11+
12+
It is important to note to end users of this system that there are not only extreme security implications to consuming files from souces outside of our control, but by leveraging community Mods you essentially lose direct support from the core LinuxServer team. Our first and foremost troubleshooting step will be to remove the `DOCKER_MODS` environment variable when running into issues and replace the container with a clean LSIO one.
13+
14+
Again, when pulling in logic from external sources practice caution and trust the sources/community you get them from.
15+
16+
## Using a Docker Mod
17+
18+
Before consuming a Docker Mod ensure that the source code for it is publicly posted along with it's build pipeline pushing to Dockerhub.
19+
20+
Consumption of a Docker Mod is intended to be as user friendly as possible and can be achieved with the following environment variables being passed to the container:
21+
22+
* DOCKER_MODS- This can be a single endpoint `user/endpoint:tag` or an array of endpoints separated by `|` `user/endpoint:tag|user2/endpoint2:tag`
23+
* RUN_BANNED_MODS- If this is set to any value you will bypass our centralized filter of banned Dockerhub users and run Mods regardless of a ban
24+
25+
Full example:
26+
27+
```
28+
docker create \
29+
--name=nzbget \
30+
-e DOCKER_MODS=taisun/nzbget-mod:latest \
31+
-e PUID=1000 \
32+
-e PGID=1000 \
33+
-e TZ=Europe/London \
34+
-p 6789:6789 \
35+
-v <path to data>:/config \
36+
-v <path/to/downloads>:/downloads \
37+
--restart unless-stopped \
38+
linuxserver/nzbget
39+
```
40+
41+
This will spinup an nzbget container and apply the custom logic found in the following repository:
42+
43+
https://github.com/Taisun-Docker/Linuxserver-Mod-Demo
44+
45+
This basic demo installs Pip and a couple dependencies for plugins some users leverage with nzbget.
46+
47+
## Creating and maintaining a Docker Mod
48+
49+
We will always recommend to our users consuming Mods that they leverage ones from active community members or projects so transparency is key here. We understand that image layers can be pushed on the back end behind these pipelines, but every little bit helps.
50+
In this repository we will be going over two basic methods of making a Mod along with an example of the Travis-CI.org build logic to get this into a Dockerhub endpoint. Though we are not officially endorsing Travis-CI here it is one of the most popular Open Source free build pipelines and only requires a Github account to get started. If you prefer others feel free to use them as long as build jobs are transparent.
51+
52+
One of the core ideas to remember when creating a Mod is that it can only contain a single image layer, the examples below will show you how to add files standardly and how to run complex logic to assemble the files in a build layer to copy them over into this single layer.
53+
54+
### Docker Mod Simple - just add scripts
55+
56+
In this repository you will find the `Dockerfile` containing:
57+
58+
```
59+
FROM scratch
60+
61+
# copy local files
62+
COPY root/ /
63+
```
64+
65+
For most users this will suffice and anything in the root/ folder of the repository will be added to the end users Docker container / path.
66+
67+
The most common paths to leverage for Linuxserver images will be:
68+
69+
* root/etc/cont-init.d/<25-script-name> - Contains init logic scripts that run before the services in the container start these should exit 0 and are ordered by filename
70+
* root/etc/services.d/<yourservice>/run - Contains scripts that run in the foreground for persistent services IE NGINX
71+
* root/defaults - Contains base config files that are copied/modified on first spinup
72+
73+
The example files in this repo contain a script to install sshutil and a service file to run the installed utility.
74+
75+
### Docker Mod Complex - Sky is the limit
76+
77+
In this repository you will find the `Dockerfile.complex` containing:
78+
79+
```
80+
## Buildstage ##
81+
FROM lsiobase/alpine:3.9 as buildstage
82+
83+
RUN \
84+
echo "**** install packages ****" && \
85+
apk add --no-cache \
86+
curl && \
87+
echo "**** grab rclone ****" && \
88+
mkdir -p /root-layer && \
89+
curl -o \
90+
/root-layer/rclone.deb -L \
91+
"https://downloads.rclone.org/v1.47.0/rclone-v1.47.0-linux-amd64.deb"
92+
93+
# copy local files
94+
COPY root/ /root-layer/
95+
96+
## Single layer deployed image ##
97+
FROM scratch
98+
99+
# Add files from buildstage
100+
COPY --from=buildstage /root-layer/ /
101+
```
102+
103+
Here we are leveraging a multi stage DockerFile to run custom logic and pull down an Rclone deb from the Internet to include in our image layer for distribution. Any amount of logic can be run in this build stage or even multiple build stages as long as the files in the end are combined into a single folder for the COPY command in the final output.
104+
105+
## Full loop - getting a Mod to Dockerhub
106+
107+
First and foremost to publish a Mod you will need the following accounts:
108+
Github- https://github.com/join
109+
DockerHub- https://hub.docker.com/signup
110+
111+
We reccomend using this repositroy as a template for your first Mod, so in this section we assume the code is finished and we will only concentrate on plugging into Travis/Dockerhub.
112+
113+
The only code change you need to make to the build logic file `.travis.yml` will be to modify the DOCKERHUB endpoint to your own image:
114+
```
115+
env:
116+
global:
117+
- DOCKERHUB="user/endpoint"
118+
```
119+
120+
User is your Dockerhub user and endpoint is your own custom name. You do not need to create this endpoint beforehand, the build logic will push it and create it on first run.
121+
122+
Head over to https://travis-ci.org/ and click on signup:
123+
124+
![signup](https://s3-us-west-2.amazonaws.com/linuxserver-docs/images/signup.png)
125+
126+
This will use Github to auth you in. Once in the dashboard click on "Add new Repository":
127+
128+
![addnew](https://s3-us-west-2.amazonaws.com/linuxserver-docs/images/addnew.png)
129+
130+
Click on settings for the repo you want to add:
131+
132+
![settings](https://s3-us-west-2.amazonaws.com/linuxserver-docs/images/settings.png)
133+
134+
Under the "Environment Variables" section add DOCKERUSER and DOCKERPASS as shown below, these will be your live Dockerhub credentials:
135+
136+
![env](https://s3-us-west-2.amazonaws.com/linuxserver-docs/images/env.png)
137+
138+
Once these are set click on the "Current" tab and "Activate repository":
139+
140+
![activate](https://s3-us-west-2.amazonaws.com/linuxserver-docs/images/activate.png)
141+
142+
Travis will trigger a build off of your repo and will push to Dockerhub on success. This Dockerhub endpoint is the Mod variable you can use to customize your container now.
143+
144+
145+
## Appendix
146+
147+
### Inspecting mods
148+
149+
To inspect the file contents of external Mods dive is a great CLI tool:
150+
151+
https://github.com/wagoodman/dive
152+
153+
Basic usage:
154+
155+
```
156+
docker run --rm -it \
157+
-v /var/run/docker.sock:/var/run/docker.sock \
158+
wagoodman/dive:latest <Image Name>
159+
```

root/etc/cont-init.d/99-vpn-config

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
# Determine if setup is needed
4+
if [ ! -f /usr/local/lib/python***/dist-packages/sshuttle ] && \
5+
[ -f /usr/bin/apt ]; then
6+
## Ubuntu
7+
apt-get update
8+
apt-get install --no-install-recommends -y \
9+
iptables \
10+
openssh-client \
11+
python3 \
12+
python3-pip
13+
pip3 install sshuttle
14+
fi
15+
if [ ! -f /usr/lib/python***/site-packages/sshuttle ] && \
16+
[ -f /sbin/apk ]; then
17+
# Alpine
18+
apk add --no-cache \
19+
iptables \
20+
openssh \
21+
py3-pip \
22+
python3
23+
pip3 install sshuttle
24+
fi
25+
26+
chown -R root:root /root
27+
chmod -R 600 /root/.ssh

root/etc/services.d/sshvpn/run

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
sshuttle --dns --remote root@${HOST}:${PORT} 0/0 -x 172.17.0.0/16

0 commit comments

Comments
 (0)