From c8d367c97f5a4c7cdb7d543fbc433e545804491a Mon Sep 17 00:00:00 2001 From: Ilya Glotov Date: Fri, 28 Jul 2017 12:12:44 +0300 Subject: [PATCH 1/2] Add docker support Based on alpine image, runs as a regular user --- Dockerfile | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f7024d0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM alpine:edge + +COPY ./ /tmp + +WORKDIR /tmp + +RUN apk update \ + && apk add --no-cache ca-certificates \ + libressl \ + llvm-libunwind \ + && apk add --no-cache --virtual .build-rust \ + rust \ + cargo \ + libressl-dev \ + && cargo build --release \ + && mv target/release/iptoasn-webservice /usr/bin/iptoasn-webservice \ + && rm -rf ~/.cargo \ + /var/cache/apk/* \ + /tmp/* \ + && apk del .build-rust + +RUN adduser -D app +USER app + +ENTRYPOINT /usr/bin/iptoasn-webservice --listen 0.0.0.0:10000 From 79f0803fd579c558c3692384d2a90f8e057f1cdf Mon Sep 17 00:00:00 2001 From: Ilya Glotov Date: Mon, 31 Jul 2017 20:44:50 +0300 Subject: [PATCH 2/2] Add entrypoint shell script Listen port and database URL can be configured by using environment variables: IPTOASN_PORT AND IPTOASN_DBURL Docker container for the iptoasn_webservice may be used as a binary - arbitrary args will be passed to the service if supplied --- Dockerfile => docker/Dockerfile | 7 ++++++- docker/iptoasn-entrypoint.sh | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) rename Dockerfile => docker/Dockerfile (72%) create mode 100644 docker/iptoasn-entrypoint.sh diff --git a/Dockerfile b/docker/Dockerfile similarity index 72% rename from Dockerfile rename to docker/Dockerfile index f7024d0..f87b1eb 100644 --- a/Dockerfile +++ b/docker/Dockerfile @@ -12,8 +12,13 @@ RUN apk update \ rust \ cargo \ libressl-dev \ + \ && cargo build --release \ + && strip target/release/iptoasn-webservice \ && mv target/release/iptoasn-webservice /usr/bin/iptoasn-webservice \ + && mv docker/iptoasn-entrypoint.sh /iptoasn-entrypoint.sh \ + && chmod +x /iptoasn-entrypoint.sh \ + \ && rm -rf ~/.cargo \ /var/cache/apk/* \ /tmp/* \ @@ -22,4 +27,4 @@ RUN apk update \ RUN adduser -D app USER app -ENTRYPOINT /usr/bin/iptoasn-webservice --listen 0.0.0.0:10000 +ENTRYPOINT ["/iptoasn-entrypoint.sh"] diff --git a/docker/iptoasn-entrypoint.sh b/docker/iptoasn-entrypoint.sh new file mode 100644 index 0000000..6b22d78 --- /dev/null +++ b/docker/iptoasn-entrypoint.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +DEFAULT_PORT='53661' +DEFAULT_DBURL='https://iptoasn.com/data/ip2asn-combined.tsv.gz' + +if [ $IPTOASN_PORT ] || [ $IPTOASN_DBURL]; then + if ! [ $IPTOASN_PORT ]; then + IPTOASN_PORT=$DEFAULT_PORT + fi + + if ! [ $IPTOASN_DBURL ]; then + IPTOASN_DBURL=$DEFAULT_DBURL + fi + + exec /usr/bin/iptoasn-webservice --listen 0.0.0.0:"$IPTOASN_PORT" --dburl "$IPTOASN_DBURL" +else + exec /usr/bin/iptoasn-webservice $@ +fi