Skip to content

Commit e9b9b19

Browse files
committed
Initial
1 parent 6360fcf commit e9b9b19

File tree

11 files changed

+138
-42
lines changed

11 files changed

+138
-42
lines changed

.github/workflows/BuildImage.yml

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
name: Build Image
22

3-
on:
4-
push:
5-
pull_request_target:
6-
workflow_dispatch:
7-
inputs:
8-
mod_version:
9-
type: string
10-
required: false
3+
on: [push, pull_request_target, workflow_dispatch]
114

125
env:
136
GITHUB_REPO: "linuxserver/docker-mods" #don't modify
147
ENDPOINT: "linuxserver/mods" #don't modify
15-
BASEIMAGE: "replace_baseimage" #replace
16-
MODNAME: "replace_modname" #replace
17-
MOD_VERSION: ${{ inputs.mod_version }} #don't modify
18-
MULTI_ARCH: "true" #set to false if not needed
8+
BASEIMAGE: "swag" #replace
9+
MODNAME: "ipinfo" #replace
1910

2011
jobs:
2112
set-vars:
@@ -28,23 +19,15 @@ jobs:
2819
echo "ENDPOINT=${{ env.ENDPOINT }}" >> $GITHUB_OUTPUT
2920
echo "BASEIMAGE=${{ env.BASEIMAGE }}" >> $GITHUB_OUTPUT
3021
echo "MODNAME=${{ env.MODNAME }}" >> $GITHUB_OUTPUT
31-
echo "MULTI_ARCH=${{ env.MULTI_ARCH }}" >> $GITHUB_OUTPUT
32-
if [[ -z "${{ env.MOD_VERSION }}" ]]; then
33-
# **** If the mod needs to be versioned, set the versioning logic below. Otherwise leave as is. ****
34-
MOD_VERSION=""
35-
else
36-
MOD_VERSION=${{ env.MOD_VERSION }}
37-
echo "MOD_VERSION_OVERRIDE=true" >> $GITHUB_OUTPUT
38-
fi
22+
# **** If the mod needs to be versioned, set the versioning logic below. Otherwise leave as is. ****
23+
MOD_VERSION=""
3924
echo "MOD_VERSION=${MOD_VERSION}" >> $GITHUB_OUTPUT
4025
outputs:
4126
GITHUB_REPO: ${{ steps.outputs.outputs.GITHUB_REPO }}
4227
ENDPOINT: ${{ steps.outputs.outputs.ENDPOINT }}
4328
BASEIMAGE: ${{ steps.outputs.outputs.BASEIMAGE }}
4429
MODNAME: ${{ steps.outputs.outputs.MODNAME }}
45-
MULTI_ARCH: ${{ steps.outputs.outputs.MULTI_ARCH }}
4630
MOD_VERSION: ${{ steps.outputs.outputs.MOD_VERSION }}
47-
MOD_VERSION_OVERRIDE: ${{ steps.outputs.outputs.MOD_VERSION_OVERRIDE }}
4831

4932
build:
5033
uses: linuxserver/github-workflows/.github/workflows/docker-mod-builder.yml@v1
@@ -59,6 +42,4 @@ jobs:
5942
ENDPOINT: ${{ needs.set-vars.outputs.ENDPOINT }}
6043
BASEIMAGE: ${{ needs.set-vars.outputs.BASEIMAGE }}
6144
MODNAME: ${{ needs.set-vars.outputs.MODNAME }}
62-
MULTI_ARCH: ${{ needs.set-vars.outputs.MULTI_ARCH }}
6345
MOD_VERSION: ${{ needs.set-vars.outputs.MOD_VERSION }}
64-
MOD_VERSION_OVERRIDE: ${{ needs.set-vars.outputs.MOD_VERSION_OVERRIDE }}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
FROM scratch
44

5-
LABEL maintainer="username"
5+
LABEL maintainer="quietsy"
66

77
# copy local files
88
COPY root/ /

README.md

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,65 @@
1-
# Rsync - Docker mod for openssh-server
1+
# IPINFO Docker mod for Nginx based images
22

3-
This mod adds rsync to openssh-server, to be installed/updated during container start.
3+
This mod downloads the `ipinfo_lite.mmdb` database under `/config/geoip2db`, the database is updated daily.
44

5-
In openssh-server docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:openssh-server-rsync`
5+
**This mod should not be enabled together with swag-maxmind or swag-dbip mods.**
66

7-
If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:openssh-server-rsync|linuxserver/mods:openssh-server-mod2`
7+
Follow these steps to enable the ipinfo mod:
88

9-
# Mod creation instructions
9+
1. Sign up and aquire an ipinfo token here: https://ipinfo.io/signup
10+
2. In the container's docker arguments, set the following environment variables:
11+
- `IPINFO_TOKEN=<token>` with your token.
12+
3. In the container's docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:swag-ipinfo`
13+
14+
If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:swag-ipinfo|linuxserver/mods:swag-mod2`
15+
4. Recreate the container to apply the changes.
16+
5. Add the following line to `/config/nginx/nginx.conf` under the `http` section:
17+
18+
```nginx
19+
include /config/nginx/ipinfo.conf;
20+
```
21+
6. Edit `/config/nginx/ipinfo.conf` and add countries to the blocklist / whitelist according to the comments, for example:
22+
23+
```nginx
24+
map $geoip2_data_country_iso_code $geo-whitelist {
25+
default no;
26+
UK yes;
27+
}
1028
11-
* Fork the repo, create a new branch based on the branch `template`.
12-
* Edit the `Dockerfile` for the mod. `Dockerfile.complex` is only an example and included for reference; it should be deleted when done.
13-
* Inspect the `root` folder contents. Edit, add and remove as necessary.
14-
* After all init scripts and services are created, run `find ./ -path "./.git" -prune -o \( -name "run" -o -name "finish" -o -name "check" \) -not -perm -u=x,g=x,o=x -print -exec chmod +x {} +` to fix permissions.
15-
* Edit this readme with pertinent info, delete these instructions.
16-
* Finally edit the `.github/workflows/BuildImage.yml`. Customize the vars for `BASEIMAGE` and `MODNAME`. Set the versioning logic and `MULTI_ARCH` if needed.
17-
* Ask the team to create a new branch named `<baseimagename>-<modname>`. Baseimage should be the name of the image the mod will be applied to. The new branch will be based on the `template` branch.
18-
* Submit PR against the branch created by the team.
29+
map $geoip2_data_country_iso_code $geo-blacklist {
30+
default yes;
31+
US no;
32+
}
33+
```
34+
7. Use the definitions in the following way:
35+
```nginx
36+
server {
37+
listen 443 ssl;
38+
listen [::]:443 ssl;
1939
40+
server_name some-app.*;
41+
include /config/nginx/ssl.conf;
42+
client_max_body_size 0;
2043
21-
## Tips and tricks
44+
if ($lan-ip = yes) { set $geo-whitelist yes; }
45+
if ($geo-whitelist = no) { return 404; }
2246
23-
* Some images have helpers built in, these images are currently:
24-
* [Openvscode-server](https://github.com/linuxserver/docker-openvscode-server/pull/10/files)
25-
* [Code-server](https://github.com/linuxserver/docker-code-server/pull/95)
47+
location / {
48+
```
49+
Or for blacklist with both some countries and continents:
50+
```nginx
51+
server {
52+
listen 443 ssl;
53+
listen [::]:443 ssl;
54+
55+
server_name some-app.*;
56+
include /config/nginx/ssl.conf;
57+
client_max_body_size 0;
58+
59+
if ($lan-ip = yes) { set $geo-blacklist yes; }
60+
if ($geo-blacklist = no) { return 404; }
61+
if ($continent-blacklist = no) { return 404; }
62+
63+
location / {
64+
```
65+
8. Restart the container to apply the changes.

root/defaults/ipinfo.conf

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
geoip2 /config/geoip2db/ipinfo_lite.mmdb {
2+
auto_reload 1w;
3+
$geoip2_data_network network;
4+
$geoip2_data_country country;
5+
$geoip2_data_country_iso_code country_code;
6+
$geoip2_data_continent continent;
7+
$geoip2_data_continent_code continent_code;
8+
$geoip2_data_asn asn;
9+
$geoip2_data_as_name as_name;
10+
$geoip2_data_as_domain as_domain;
11+
}
12+
13+
# Country Codes: https://en.wikipedia.org/wiki/ISO_3166-2
14+
15+
map $geoip2_data_country_iso_code $geo-whitelist {
16+
default yes;
17+
# Example for whitelisting a country, comment out 'default yes;' above and uncomment 'default no;' and the whitelisted country below
18+
# default no;
19+
# GB yes;
20+
}
21+
22+
map $geoip2_data_country_iso_code $geo-blacklist {
23+
default yes;
24+
# Example for blacklisting a country, uncomment the blacklisted country below
25+
# GB no;
26+
}
27+
28+
# Continents:
29+
# Options: AF, AS, EU, NA, OC, SA, AN
30+
31+
map $geoip2_data_continent_code $continent-blacklist {
32+
default yes;
33+
# Example blacklisting a continent, uncomment the blacklisted continent bellow
34+
# SA no; # South America
35+
}
36+
37+
geo $lan-ip {
38+
default no;
39+
10.0.0.0/8 yes;
40+
172.16.0.0/12 yes;
41+
192.168.0.0/16 yes;
42+
127.0.0.1 yes;
43+
}

root/etc/periodic/daily/ipinfo

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
if [[ ! -n "${IPINFO_TOKEN}" ]]; then
4+
echo "IPINFO_TOKEN env var is missing."
5+
exit 1
6+
fi
7+
8+
FILE="https://ipinfo.io/data/ipinfo_lite.mmdb?token=${IPINFO_TOKEN}"
9+
10+
wget -O /tmp/ipinfo_lite.mmdb $FILE
11+
mv -f /tmp/ipinfo_lite.mmdb /config/geoip2db/ipinfo_lite.mmdb
12+
exit 0

root/etc/s6-overlay/s6-rc.d/init-mod-swag-ipinfo-setup/dependencies.d/init-mods

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
echo "Applying the ipinfo mod..."
4+
5+
chmod +x /etc/periodic/daily/ipinfo
6+
7+
# check GeoIP2 database
8+
if [ ! -f /config/geoip2db/ipinfo_lite.mmdb ]; then
9+
echo "Downloading GeoIP2 City database."
10+
mkdir -p "/config/geoip2db"
11+
/etc/periodic/daily/ipinfo
12+
fi
13+
14+
if [ ! -f /config/nginx/ipinfo.conf ]; then
15+
cp /defaults/ipinfo.conf /config/nginx/ipinfo.conf
16+
fi
17+
18+
echo "Applied the ipinfo mod"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oneshot
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/etc/s6-overlay/s6-rc.d/init-mod-swag-ipinfo-setup/run

root/etc/s6-overlay/s6-rc.d/init-mods-end/dependencies.d/init-mod-swag-ipinfo-setup

Whitespace-only changes.

0 commit comments

Comments
 (0)