diff --git a/Dockerfile b/Dockerfile index 8f81689..b270b38 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,49 @@ +FROM alpine:latest as builder +COPY exporter/requirements.txt /work/exporter/requirements.txt +RUN set -xeu; \ + mkdir -p /work/wheels; \ + apk add \ + python3-dev \ + openssl-dev \ + gcc \ + musl-dev \ + libffi-dev \ + make \ + ; \ + python3 -m ensurepip; \ + pip3 install -U \ + pip \ + wheel \ + ; +RUN pip3 --use-feature=2020-resolver wheel -r /work/exporter/requirements.txt -w /work/wheels +COPY exporter /work/exporter/ + FROM alpine:latest -LABEL maintainer="docker@ix.ai" \ - ai.ix.repository="ix.ai/crypto-exporter" +LABEL maintainer="docker@ix.ai" +LABEL ai.ix.repository="ix.ai/crypto-exporter" + +COPY --from=builder /work / -COPY exporter/requirements.txt /exporter/requirements.txt +RUN set -xeu; \ + ls -lashi /wheels; \ + apk add --no-cache python3; \ + python3 -m ensurepip; \ + pip3 install --no-cache-dir -U pip;\ + pip3 install \ + --no-index \ + --use-feature=2020-resolver \ + --no-cache-dir \ + --find-links /wheels \ + --requirement /exporter/requirements.txt \ + ; \ + rm -rf /wheels; \ + addgroup crypto-exporter; \ + adduser -G crypto-exporter -D -H crypto-exporter -RUN apk --no-cache upgrade && \ - apk add --no-cache py3-prometheus-client \ - py3-requests \ - py3-cryptography \ - py3-multidict \ - py3-aiohttp \ - py3-pip \ - py3-toml \ - py3-numpy \ - py3-pynacl \ - py3-urllib3 \ - py3-yarl && \ - apk add --no-cache python3-dev gcc musl-dev libffi-dev make && \ - pip3 install --no-cache-dir -r exporter/requirements.txt && \ - apk del --purge --no-cache gcc musl-dev python3-dev py3-pip libffi-dev +COPY crypto-exporter /usr/local/bin/crypto-exporter -COPY exporter/ /exporter -COPY crypto-exporter.sh /usr/local/bin/crypto-exporter.sh +USER crypto-exporter:crypto-exporter EXPOSE 9188 -ENTRYPOINT ["/usr/local/bin/crypto-exporter.sh"] +ENTRYPOINT ["/usr/local/bin/crypto-exporter"] diff --git a/build.sh b/build.sh index 75c5417..f19f6e4 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,7 @@ #!/usr/bin/env sh -echo "Setting VERSION" -find . -name .git -type d -prune -o -type f -name constants.py -exec sed -i s/^VERSION.*/VERSION\ =\ \'${CI_COMMIT_REF_NAME:-None}\'/g {} + -exec grep VERSION {} + -echo "Setting BUILD" -find . -name .git -type d -prune -o -type f -name constants.py -exec sed -i s/^BUILD.*/BUILD\ =\ \'${CI_PIPELINE_ID:-None}\'/g {} + -exec grep BUILD {} + +set -xeu + +if [ -n "${CI_PIPELINE_ID:-}" ]; then + sed -i "s|^BUILD.*|BUILD = '${CI_PIPELINE_ID}'|g" exporter/lib/constants.py +fi diff --git a/crypto-exporter.sh b/crypto-exporter similarity index 100% rename from crypto-exporter.sh rename to crypto-exporter diff --git a/exporter/lib/constants.py b/exporter/lib/constants.py index 41d6774..c27cb76 100644 --- a/exporter/lib/constants.py +++ b/exporter/lib/constants.py @@ -4,6 +4,6 @@ WARN_TICKER_SLOW_LOAD = 'Exchange doesn\'t support fetching all the tickers in one go. Loading them individually.' -# These get set at build time -VERSION = None -BUILD = None +VERSION = 'v1.7.9' +# Gets set automatically at build time +BUILD = 'dev' diff --git a/exporter/requirements.txt b/exporter/requirements.txt index 4917867..ee707f3 100644 --- a/exporter/requirements.txt +++ b/exporter/requirements.txt @@ -1,5 +1,5 @@ -ccxt==1.36.80 prometheus_client==0.8.0 requests==2.24.0 pygelf==0.3.6 stellar-sdk==2.8.1 +ccxt==1.36.80 diff --git a/test.sh b/test.sh index 304b1c9..1328a4a 100755 --- a/test.sh +++ b/test.sh @@ -4,7 +4,7 @@ set -e ./build.sh for EXCHANGE in "kraken" "binance" "coinbasepro"; do - EXCHANGE="${EXCHANGE}" REFERENCE_CURRENCY="EUR" SYMBOLS="BTC/EUR" TEST=y ./crypto-exporter.sh + EXCHANGE="${EXCHANGE}" REFERENCE_CURRENCY="EUR" SYMBOLS="BTC/EUR" TEST=y ./crypto-exporter done # ETH @@ -12,17 +12,17 @@ if [ -n "${ETHERSCAN_API_KEY}" ]; then ADDRESSES='0x742d35Cc6634C0532925a3b844Bc454e4438f44e' # binance ADDRESSES="${ADDRESSES},0x53d284357ec70cE289D6D64134DfAc8E511c8a3D" # kraken TOKENS='[{"contract":"0x9b70740e708a083c6ff38df52297020f5dfaa5ee","name":"Daneel","short":"DAN","decimals": 10},{"contract":"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","name":"USD Coin","short":"USDC","decimals": 6}]' - EXCHANGE="etherscan" ADDRESSES="${ADDRESSES}" TOKENS="${TOKENS}" API_KEY="${ETHERSCAN_API_KEY}" TEST=y ./crypto-exporter.sh + EXCHANGE="etherscan" ADDRESSES="${ADDRESSES}" TOKENS="${TOKENS}" API_KEY="${ETHERSCAN_API_KEY}" TEST=y ./crypto-exporter fi # Ripple ADDRESSES='rDbWJ9C7uExThZYAwV8m6LsZ5YSX3sa6US' # ripple.com ADDRESSES="${ADDRESSES},rEy8TFcrAPvhpKrwyrscNYyqBGUkE9hKaJ" # binance ADDRESSES="${ADDRESSES},rLHzPsX6oXkzU2qL12kHCH8G8cnZv1rBJh" # kraken -EXCHANGE="ripple" ADDRESSES="${ADDRESSES}" TEST=y ./crypto-exporter.sh +EXCHANGE="ripple" ADDRESSES="${ADDRESSES}" TEST=y ./crypto-exporter # Stellar ADDRESSES='GA5XIGA5C7QTPTWXQHY6MCJRMTRZDOSHR6EFIBNDQTCQHG262N4GGKTM' # kraken ADDRESSES="${ADDRESSES},GD6RMKTCHQGEOGYWIKSY5G7QWXPZOAEZIKPKEVZUAXOQCZRVBRRFGLJM" # NydroEnergy ADDRESSES="${ADDRESSES},GCNSGHUCG5VMGLT5RIYYZSO7VQULQKAJ62QA33DBC5PPBSO57LFWVV6P" # InterstellarExchange -EXCHANGE="stellar" ADDRESSES="${ADDRESSES}" TEST=y ./crypto-exporter.sh +EXCHANGE="stellar" ADDRESSES="${ADDRESSES}" TEST=y ./crypto-exporter