Skip to content

Commit

Permalink
[example][nginx grafana]add support for Docker building on x86_64 and…
Browse files Browse the repository at this point in the history
… arm64 (#811)

* add support for Docker building on x86_64 and arm64

* show the 1st 10 lines from a batch geolookup
  • Loading branch information
ayewo authored Aug 14, 2024
1 parent 62694ee commit d52cb5f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
42 changes: 28 additions & 14 deletions examples/nginx-grafana/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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 <<EOF > ~/.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

Expand Down
3 changes: 3 additions & 0 deletions examples/nginx-grafana/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ services:
args:
- PROTON_HOST=proton
- IPINFO_KEY=$IPINFO_KEY
platforms:
- linux/amd64
- linux/arm64
depends_on:
- proton
networks:
Expand Down
1 change: 1 addition & 0 deletions examples/nginx-grafana/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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!"

Expand Down

0 comments on commit d52cb5f

Please sign in to comment.