Skip to content

Commit

Permalink
Merge pull request #19 from GilbN/alpine-3.20
Browse files Browse the repository at this point in the history
Rebase to Alpine 3.20
  • Loading branch information
GilbN authored Jul 28, 2024
2 parents 227264e + 6d0ac81 commit 32a3ee1
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 24 deletions.
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
FROM lsiobase/alpine:3.15
FROM lsiobase/alpine:3.20
LABEL maintainer="GilbN"

WORKDIR /geoip2influx
COPY requirements.txt geoip2influx.py /geoip2influx/
RUN \
echo " ## Installing packages ## " && \
apk add --no-cache --virtual=build-dependencies \
python3 \
python3-dev \
py3-pip \
logrotate \
libmaxminddb && \
echo "**** install packages ****" && \
apk add --no-cache \
python3 && \
echo " ## Installing python modules ## " && \
python3 -m venv /lsiopy && \
pip3 install --no-cache-dir -r requirements.txt
COPY root/ /
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Add the ones that differ on your system.
| INFLUX_RETENTION | 7d | Sets the retention for the database. Optional, defaults to example.|
| INFLUX_SHARD | 1d | Set the shard for the database. Optional, defaults to example. |
| MAXMINDDB_LICENSE_KEY | xxxxxxx | Add your Maxmind licence key |
| MAXMINDDB_USER_ID | xxxxxxx| Add your Maxmind account id |


### MaxMind Geolite2
Expand Down Expand Up @@ -68,6 +69,7 @@ docker create \
-e INFLUX_HOST=<influxdb host> \
-e INFLUX_HOST_PORT=<influxdb port> \
-e MAXMINDDB_LICENSE_KEY=<license key>\
-e MAXMINDDB_USER_ID=<account id>\
-v /path/to/appdata/geoip2influx:/config \
-v /path/to/nginx/accesslog/:/config/log/nginx/ \
--restart unless-stopped \
Expand All @@ -89,6 +91,7 @@ services:
- INFLUX_HOST=<influxdb host>
- INFLUX_HOST_PORT=<influxdb port>
- MAXMINDDB_LICENSE_KEY=<license key>
- MAXMINDDB_USER_ID=<account id>
volumes:
- /path/to/appdata/geoip2influx:/config
- /path/to/nginx/accesslog/:/config/log/nginx/
Expand Down Expand Up @@ -148,6 +151,8 @@ Then use the `/config/log/nginx/access.log` file in the `NGINX_LOG_PATH` variabl

## Updates

**xx.xx.24** - Refactor to alpine 3.20. New env required. MAXMINDDB_USER_ID.

**21.06.20** - Added $host(domain) to the nginx log metrics. This will break your nginx logs parsing, as you need to update the custom log format.

**06.06.20** - Added influx retention policy to try and mitigate max-values-per-tag limit exceeded errors.
Expand Down
2 changes: 1 addition & 1 deletion root/etc/logrotate.d/geoip2influx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
missingok
notifempty
postrotate
s6-svc -r /var/run/s6/services/geoip2influx
s6-svc -1 /run/service/svc-geoip2influx
endscript
su abc abc
}
11 changes: 11 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/init-adduser/branding
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

██████╗ ███████╗ ██████╗ ██╗██████╗ ██████╗ ██╗███╗ ██╗███████╗██╗ ██╗ ██╗██╗ ██╗
██╔════╝ ██╔════╝██╔═══██╗██║██╔══██╗╚════██╗██║████╗ ██║██╔════╝██║ ██║ ██║╚██╗██╔╝
██║ ███╗█████╗ ██║ ██║██║██████╔╝ █████╔╝██║██╔██╗ ██║█████╗ ██║ ██║ ██║ ╚███╔╝
██║ ██║██╔══╝ ██║ ██║██║██╔═══╝ ██╔═══╝ ██║██║╚██╗██║██╔══╝ ██║ ██║ ██║ ██╔██╗
╚██████╔╝███████╗╚██████╔╝██║██║ ███████╗██║██║ ╚████║██║ ███████╗╚██████╔╝██╔╝ ██╗
╚═════╝ ╚══════╝ ╚═════╝ ╚═╝╚═╝ ╚══════╝╚═╝╚═╝ ╚═══╝╚═╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝


Made by @gilbN
https://github.com/GilbN/geoip2influx
Empty file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash

echo -e "Variables set:\\n\
echo -e "[init-geoip2influx-setup] Starting"

echo -e "[init-geoip2influx-setup] Variables set:\\n\
NGINX_LOG_PATH=${NGINX_LOG_PATH}\\n\
INFLUX_HOST=${INFLUX_HOST}\\n\
INFLUX_HOST_PORT=${INFLUX_HOST_PORT}\\n\
Expand All @@ -14,31 +17,19 @@ LOG_MEASUREMENT=${LOG_MEASUREMENT}\\n\
SEND_NGINX_LOGS=${SEND_NGINX_LOGS}\\n\
GEOIP2INFLUX_LOG_LEVEL=${GEOIP2INFLUX_LOG_LEVEL}\\n\
GEOIP2INFLUX_LOG_PATH=${GEOIP2INFLUX_LOG_PATH}\\n\
MAXMINDDB_USER_ID=${MAXMINDDB_USER_ID}\\n\
MAXMINDDB_LICENSE_KEY=${MAXMINDDB_LICENSE_KEY}\\n"

mkdir -p \
/config/geoip2db \
/config/log/geoip2influx
cp -f /geoip2influx/geoip2influx.py /config/geoip2db
# move old log if needed
if [ -f /config/geoip2db/geoip2influx.log ]; then
echo -e "[init-geoip2influx-setup] Moving old log"
mv /config/geoip2db/geoip2influx.log /config/log/geoip2influx
fi
# create GeoIP2 folder symlink
[[ -d /var/lib/libmaxminddb ]] && [[ ! -L /var/lib/libmaxminddb ]] && \
rm -rf /var/lib/libmaxminddb
[[ ! -d /var/lib/libmaxminddb ]] && \
ln -s /config/geoip2db /var/lib/libmaxminddb
# check GeoIP2 database
if [ -n "$MAXMINDDB_LICENSE_KEY" ]; then
sed -i "s|.*MAXMINDDB_LICENSE_KEY.*|MAXMINDDB_LICENSE_KEY=\"${MAXMINDDB_LICENSE_KEY}\"|g" /etc/libmaxminddb.cron.conf
if [ ! -f /var/lib/libmaxminddb/GeoLite2-City.mmdb ]; then
echo "Downloading GeoIP2 City database."
/etc/periodic/weekly/libmaxminddb
fi
fi

# permissions
chown -R abc:abc /config/geoip2db
chmod +x /config/geoip2db/geoip2influx.py
chmod -R 0644 /etc/logrotate.d
chmod -R 0644 /etc/logrotate.d

echo -e "[init-geoip2influx-setup] Finished"
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-geoip2influx-setup/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-geoip2influx-setup/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-geoip2influx-setup/run
34 changes: 34 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/init-maxmind-setup/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/with-contenv bash

echo -e "[init-maxmind-setup] init started"

# create GeoIP2 folder symlink
mkdir -p \
/config/geoip2db
if [[ -d /var/lib/libmaxminddb ]] && [[ ! -L /var/lib/libmaxminddb ]]; then
rm -rf /var/lib/libmaxminddb
fi
if [[ ! -d /var/lib/libmaxminddb ]]; then
ln -s /config/geoip2db /var/lib/libmaxminddb
fi
# check GeoIP2 database
if [[ -n "${MAXMINDDB_USER_ID}" ]]; then
sed -i "s|.*MAXMINDDB_USER_ID.*|MAXMINDDB_USER_ID=\"${MAXMINDDB_USER_ID}\"|g" /etc/libmaxminddb.cron.conf
else
echo -e "[init-maxmind-setup] Starting with Alpine 3.20 rebase, MaxMindDB now requires setting the env var MAXMINDDB_USER_ID with your account's user id."
fi
if [[ -n "${MAXMINDDB_LICENSE_KEY}" ]]; then
sed -i "s|.*MAXMINDDB_LICENSE_KEY.*|MAXMINDDB_LICENSE_KEY=\"${MAXMINDDB_LICENSE_KEY}\"|g" /etc/libmaxminddb.cron.conf
if [[ ! -f /var/lib/libmaxminddb/GeoLite2-City.mmdb ]]; then
echo -e "[init-maxmind-setup] Downloading GeoIP2 City database."
/etc/periodic/weekly/libmaxminddb
fi
elif [[ -f /var/lib/libmaxminddb/GeoLite2-City.mmdb ]]; then
echo -e "[init-maxmind-setup] Currently using the user provided GeoLite2-City.mmdb.\nIf you want to enable weekly auto-updates of the database, retrieve a free license key from MaxMind,\nand add a new env variable \"MAXMINDDB_LICENSE_KEY\", set to your license key."
else
echo -e "[init-maxmind-setup] Starting 2019/12/30, GeoIP2 databases require personal license key to download. Please retrieve a free license key from MaxMind,\nand add a new env variable \"MAXMINDDB_LICENSE_KEY\", set to your license key."
fi

# permissions
lsiown -R abc:abc /config/geoip2db
echo "[init-maxmind-setup] init finished"
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-maxmind-setup/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-maxmind-setup/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-maxmind-setup/run
Empty file.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash

exec \
python3 /config/geoip2db/geoip2influx.py
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/svc-geoip2influx/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Empty file.
Empty file.
3 changes: 0 additions & 3 deletions root/etc/services.d/cron/run

This file was deleted.

0 comments on commit 32a3ee1

Please sign in to comment.