diff --git a/examples/nginx-grafana/Dockerfile b/examples/nginx-grafana/Dockerfile index fefd31b630..73f88a405d 100644 --- a/examples/nginx-grafana/Dockerfile +++ b/examples/nginx-grafana/Dockerfile @@ -1,10 +1,11 @@ FROM ghcr.io/timeplus-io/proton:latest AS proton WORKDIR / - # Proton's image: https://github.com/timeplus-io/proton/blob/develop/docker/server/Dockerfile -# is based on Ubuntu:20.04 which is too old for ipinfo CLI hence the switch to Ubuntu:22.04 -FROM ubuntu:22.04 +# is based on Ubuntu:20.04 which uses a libc version that is too old for ipinfo CLI +# this is why Ubuntu:22.04 is used to build the image +FROM --platform=$BUILDPLATFORM ubuntu:22.04 AS builder +ARG TARGETARCH ARG PROTON_HOST ARG IPINFO_KEY @@ -14,24 +15,37 @@ ENV IPINFO_KEY ${IPINFO_KEY} # Copy the Proton binary COPY --from=proton /usr/bin/proton /usr/bin/ -RUN apt-get update \ - && apt-get -y install curl wget libc6 +RUN apt-get update && apt-get -y install curl wget libc6 ca-certificates + +# Install IPinfo CLI based on architecture +RUN if [ "$TARGETARCH" = "amd64" ]; then \ + curl -LO https://github.com/ipinfo/cli/releases/download/ipinfo-3.3.1/ipinfo_3.3.1_linux_amd64.deb && \ + dpkg -i ipinfo_3.3.1_linux_amd64.deb; \ + elif [ "$TARGETARCH" = "arm64" ]; then \ + curl -LO https://github.com/ipinfo/cli/releases/download/ipinfo-3.3.1/ipinfo_3.3.1_linux_arm64.deb && \ + dpkg -i ipinfo_3.3.1_linux_arm64.deb; \ + else \ + echo "Unsupported architecture: $TARGETARCH" && exit 1; \ + fi -# Install IPinfo CLI -RUN curl -LO https://github.com/ipinfo/cli/releases/download/ipinfo-3.3.1/ipinfo_3.3.1_linux_amd64.deb -RUN dpkg -i ipinfo_3.3.1_linux_amd64.deb +# Write your IPinfo API key in the env var to disk +RUN mkdir -p ~/.config/ipinfo && \ + echo '{"cache_enabled":true,"token":"'$IPINFO_KEY'","open_browser":true}' > ~/.config/ipinfo/config.json +FROM --platform=$TARGETPLATFORM ubuntu:22.04 +ARG PROTON_HOST +ARG IPINFO_KEY -# Store your IPinfo API key to disk -RUN mkdir -p ~/.config/ipinfo -RUN cat < ~/.config/ipinfo/config.json -{"cache_enabled":true,"token":"$IPINFO_KEY","open_browser":true} -EOF +ENV PROTON_HOST ${PROTON_HOST?proton} +ENV IPINFO_KEY ${IPINFO_KEY} +COPY --from=builder /usr/bin/proton /usr/bin/ +COPY --from=builder /usr/local/bin/ipinfo /usr/local/bin/ +COPY --from=builder /root/.config/ipinfo/config.json /root/.config/ipinfo/config.json +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt COPY 01_nginx-access-log.sql /tmp/01_nginx-access-log.sql COPY 02_csv-export.sql /tmp/02_csv-export.sql -#COPY 03_csv-import.sql /tmp/03_csv-import.sql COPY 03_csv-import-01.sql /tmp/03_csv-import-01.sql COPY 03_csv-import-02.sql /tmp/03_csv-import-02.sql diff --git a/examples/nginx-grafana/docker-compose.yaml b/examples/nginx-grafana/docker-compose.yaml index 1ea41d6149..b1e1606ebf 100644 --- a/examples/nginx-grafana/docker-compose.yaml +++ b/examples/nginx-grafana/docker-compose.yaml @@ -31,6 +31,9 @@ services: args: - PROTON_HOST=proton - IPINFO_KEY=$IPINFO_KEY + platforms: + - linux/amd64 + - linux/arm64 depends_on: - proton networks: diff --git a/examples/nginx-grafana/entrypoint.sh b/examples/nginx-grafana/entrypoint.sh index a4643053a5..b178aaaaac 100644 --- a/examples/nginx-grafana/entrypoint.sh +++ b/examples/nginx-grafana/entrypoint.sh @@ -33,6 +33,7 @@ echo "Geo-locating all the IP addresses in bulk using the IPInfo API (https://ip ip_count=$(wc "$DEST"/$export_ipinfo | awk '{print $1}') echo " Total IP addresses that will be looked up in bulk using $DEST/$export_ipinfo: $ip_count." cat "$DEST"/$export_ipinfo | ipinfo -c > "$DEST"/"$import_ipinfo" +head "$DEST"/"$import_ipinfo" echo " Geo-lookup of $ip_count IP addresses written to file: $DEST/$import_ipinfo." echo " Complete!"