Skip to content

Commit

Permalink
docker: build IPinfo update image
Browse files Browse the repository at this point in the history
This makes it work on non-x86 architectures. Also, enhance it a bit to
stop gracefully on signal (when not being in foreground, a shell script
is not leader of its process group and the TERM signal does not kill the
commands running in it).
  • Loading branch information
vincentbernat committed May 7, 2024
1 parent deb149d commit 7c4f68a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions console/data/docs/99-changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ identified with a specific icon:
- 🩹 *clickhouse*: disable experimental analyzer on recent versions of ClickHouse
- 🌱 *console*: add support for PostgreSQL and MySQL to store filters
- 🌱 *docker*: update to Traefik 3.0 (not mandatory)
- 🌱 *docker*: build IPinfo update image to make it available for non-x86 architectures

## 1.10.2 - 2024-04-27

Expand Down
10 changes: 10 additions & 0 deletions docker/Dockerfile.ipinfo-geoipupdate
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM alpine:latest

RUN apk add --no-cache curl

WORKDIR /data
VOLUME /data

COPY --chmod=555 ipinfo-geoipupdate.sh /usr/local/bin/ipinfo-geoipupdate.sh

CMD ["/usr/local/bin/ipinfo-geoipupdate.sh"]
4 changes: 3 additions & 1 deletion docker/docker-compose-ipinfo.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
services:
geoip:
image: ipinfo/ipinfo-db:latest
build:
context: .
dockerfile: Dockerfile.ipinfo-geoipupdate
environment:
- IPINFO_TOKEN=a2632ea59736c7
- IPINFO_DATABASES=country asn
Expand Down
21 changes: 21 additions & 0 deletions docker/ipinfo-geoipupdate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

trap exit TERM

while true; do
for DATABASE in ${IPINFO_DATABASES}; do
RESPONSE=$(curl \
-s -w '%{http_code}' -L -o "${DATABASE}.mmdb.new" \
"https://ipinfo.io/data/free/${DATABASE}.mmdb?token=${IPINFO_TOKEN}")
if [ "$RESPONSE" != "200" ]; then
echo "$RESPONSE Failed to download ${DATABASE}.mmdb database."
rm "${DATABASE}.mmdb.new" 2> /dev/null
else
echo "${DATABASE}.mmdb database downloaded in /data volume."
mv "${DATABASE}.mmdb.new" "${DATABASE}.mmdb"
fi
done

sleep "$UPDATE_FREQUENCY" &
wait $!
done

0 comments on commit 7c4f68a

Please sign in to comment.