Skip to content

Commit

Permalink
Fix update_mmdb and the Docker image to work on Alpine (Jigsaw-Code#559)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Jonathan Cohen authored Jan 17, 2020
1 parent db6aba3 commit c47abc4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/shadowbox/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions src/shadowbox/scripts/update_mmdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c47abc4

Please sign in to comment.