Fix update_mmdb and the Docker image to work on Alpine (#559)

* Fix the for loop in update_mmdb to be `dash` compatible

for x in {a..b} is bash-only, and alpine's default shell is `dash`.

* Fix other issues related to using musl/Busybox/dash

* Use `[[` instead of `((` for the branch
* Make sure to update to GNU coreutils in the image in order to use
`date --date`

* Respond to review comments
This commit is contained in:
Jonathan Cohen 2020-01-17 16:17:19 -05:00 committed by GitHub
parent db6aba33b2
commit c47abc4973
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 8 deletions

View file

@ -16,7 +16,7 @@
FROM node:8.15.0-alpine
# Versions can be found at https://github.com/Jigsaw-Code/outline-ss-server/releases
ARG SS_VERSION=1.0.7
ARG SS_VERSION=1.0.8
# Save metadata on the software versions we are using.
LABEL shadowbox.node_version=8.15.0
@ -25,8 +25,9 @@ LABEL shadowbox.outline-ss-server_version="${SS_VERSION}"
ARG GITHUB_RELEASE
LABEL shadowbox.github.release="${GITHUB_RELEASE}"
# We use curl to detect the server's public IP.
RUN apk add --no-cache curl
# We use curl to detect the server's public IP. We need to use the --date option in `date` to
# safely grab the ip-to-country database
RUN apk add --no-cache --upgrade coreutils curl
COPY src/shadowbox/scripts scripts/
COPY src/shadowbox/scripts/update_mmdb.sh /etc/periodic/weekly/update_mmdb

View file

@ -5,15 +5,17 @@
# IP Geolocation by DB-IP (https://db-ip.com)
# Note that this runs on BusyBox sh, which lacks bash features.
TMPDIR="$(mktemp -d)"
FILENAME="ip-country.mmdb"
# We need to make sure that we grab an existing database at install-time
for monthdelta in {0..10}; do
newdate=$(date --date="-$monthdelta month" +%Y-%m)
ADDRESS="https://download.db-ip.com/free/ip-country-${newdate}.mmdb.gz"
curl --fail --silent "${ADDRESS}" -o "$TMPDIR/$FILENAME.gz" > /dev/null && break
if (( monthdelta == 10 )); then
for monthdelta in $(seq 10); do
newdate=$(date --date="-$monthdelta months" +%Y-%m)
ADDRESS="https://download.db-ip.com/free/dbip-country-lite-${newdate}.mmdb.gz"
curl --fail --silent "${ADDRESS}" -o "$TMPDIR/$FILENAME.gz" > /dev/null && break
if [[ $monthdelta -eq 10 ]]; then
# A weird exit code on purpose -- we should catch this long before it triggers
exit 2
fi