diff --git a/build_connectors.sh b/build_connectors.sh index 99abbd1f..e4b92aae 100755 --- a/build_connectors.sh +++ b/build_connectors.sh @@ -1,20 +1,122 @@ -#!/bin/sh -cargo build -p rosetta-server-bitcoin --target x86_64-unknown-linux-musl --release -mkdir -p target/release/bitcoin/bin -cp target/x86_64-unknown-linux-musl/release/rosetta-server-bitcoin target/release/bitcoin/bin -docker build target/release/bitcoin -f chains/bitcoin/Dockerfile -t analoglabs/connector-bitcoin - -cargo build -p rosetta-server-ethereum --target x86_64-unknown-linux-musl --release -mkdir -p target/release/ethereum/bin -cp target/x86_64-unknown-linux-musl/release/rosetta-server-ethereum target/release/ethereum/bin -docker build target/release/ethereum -f chains/ethereum/Dockerfile -t analoglabs/connector-ethereum - -cargo build -p rosetta-server-polkadot --target x86_64-unknown-linux-musl --release -mkdir -p target/release/polkadot/bin -cp target/x86_64-unknown-linux-musl/release/rosetta-server-polkadot target/release/polkadot/bin -docker build target/release/polkadot -f chains/polkadot/Dockerfile -t analoglabs/connector-polkadot - -cargo build -p rosetta-server-astar --target x86_64-unknown-linux-musl --release -mkdir -p target/release/astar/bin -cp target/x86_64-unknown-linux-musl/release/rosetta-server-astar target/release/astar/bin -docker build target/release/astar -f chains/astar/Dockerfile -t analoglabs/connector-astar +#!/usr/bin/env bash +set -e + +# Check for 'git' and abort if it is not available. +git --version > /dev/null 2>&1 || { echo >&2 "ERROR - requires 'git' to get commit hash and tag."; exit 1; } + +REGISTRY_PATH="docker.io/analoglabs" +VCS_REF="$(git rev-parse HEAD)" +IMAGE_TAG="latest" + +# Check for 'uname' and abort if it is not available. +uname -v > /dev/null 2>&1 || { echo >&2 "ERROR - requires 'uname' to identify the platform."; exit 1; } + +# Check for 'docker' and abort if it is not running. +docker info > /dev/null 2>&1 || { echo >&2 "ERROR - requires 'docker', please start docker and try again."; exit 1; } + +# Check for 'rustup' and abort if it is not available. +rustup -V > /dev/null 2>&1 || { echo >&2 "ERROR - requires 'rustup' for compile the binaries"; exit 1; } + +# Detect host architecture +case "$(uname -m)" in + x86_64) + rustTarget='x86_64-unknown-linux-musl' + muslLinker='x86_64-linux-musl-gcc' + ;; + arm64|aarch64) + rustTarget='aarch64-unknown-linux-musl' + muslLinker='aarch64-linux-musl-gcc' + ;; + *) + echo >&2 "ERROR - unsupported architecture: $(uname -m)" + exit 1 + ;; +esac + +# Check if the musl linker is installed +"$muslLinker" --version > /dev/null 2>&1 || { echo >&2 "ERROR - requires '$muslLinker' linker for compile"; exit 1; } + +# Check if the rust target is installed +if ! rustup target list | grep -q "$rustTarget"; then + echo "Installing the musl target with rustup '$rustTarget'" + rustup target add "$rustTarget" +fi + +# Detect host operating system +case $(uname -s) in + # macOS + Darwin) + buildArgs=( + --release + --target "$rustTarget" + --config "target.$rustTarget.linker='$muslLinker'" + --config "env.CC_$rustTarget='$muslLinker'" + ) + ;; + # Linux + Linux) + buildArgs=( + --release + --target "$rustTarget" + ) + ;; + *) + echo >&2 "ERROR - unsupported or unidentified operating system: $(uname -s)" + exit 1 + ;; +esac + +# Build all Connectors +cargo build \ + -p rosetta-server-bitcoin \ + -p rosetta-server-polkadot \ + -p rosetta-server-ethereum \ + -p rosetta-server-astar \ + "${buildArgs[@]}" || exit 1 + +# Move binaries +mkdir -p target/release/{bitcoin,ethereum,polkadot,astar}/bin +cp "target/$rustTarget/release/rosetta-server-bitcoin" target/release/bitcoin/bin +cp "target/$rustTarget/release/rosetta-server-ethereum" target/release/ethereum/bin +cp "target/$rustTarget/release/rosetta-server-polkadot" target/release/polkadot/bin +cp "target/$rustTarget/release/rosetta-server-astar" target/release/astar/bin + +# Build Bitcoin Connector +docker build target/release/bitcoin \ + -f chains/bitcoin/Dockerfile \ + -t analoglabs/connector-bitcoin \ + --build-arg "REGISTRY_PATH=$REGISTRY_PATH" \ + --build-arg "VCS_REF=$VCS_REF" \ + --build-arg "BUILD_DATE=$(date +%Y%m%d)" \ + --build-arg "IMAGE_VERSION=$IMAGE_TAG" \ + --no-cache + +# Build Ethereum Connector +docker build target/release/ethereum \ + -f chains/ethereum/Dockerfile \ + -t analoglabs/connector-ethereum \ + --build-arg "REGISTRY_PATH=$REGISTRY_PATH" \ + --build-arg "VCS_REF=$VCS_REF" \ + --build-arg "BUILD_DATE=$(date +%Y%m%d)" \ + --build-arg "IMAGE_VERSION=$IMAGE_TAG" \ + --no-cache + +# Build Polkadot Connector +docker build target/release/polkadot \ + -f chains/polkadot/Dockerfile \ + -t analoglabs/connector-polkadot \ + --build-arg "REGISTRY_PATH=$REGISTRY_PATH" \ + --build-arg "VCS_REF=$VCS_REF" \ + --build-arg "BUILD_DATE=$(date +%Y%m%d)" \ + --build-arg "IMAGE_VERSION=$IMAGE_TAG" \ + --no-cache + +# Build Astar Connector +docker build target/release/astar \ + -f chains/astar/Dockerfile \ + -t analoglabs/connector-astar \ + --build-arg "REGISTRY_PATH=$REGISTRY_PATH" \ + --build-arg "VCS_REF=$VCS_REF" \ + --build-arg "BUILD_DATE=$(date +%Y%m%d)" \ + --build-arg "IMAGE_VERSION=$IMAGE_TAG" \ + --no-cache diff --git a/chains/astar/Dockerfile b/chains/astar/Dockerfile index b40a2902..21ae7275 100644 --- a/chains/astar/Dockerfile +++ b/chains/astar/Dockerfile @@ -1,3 +1,24 @@ +ARG REGISTRY_PATH +ARG IMAGE_VERSION +ARG VCS_REF +ARG BUILD_DATE + FROM scratch + +# metadata +LABEL summary="Analog’s connectors for astar parachain" \ + name="${REGISTRY_PATH}/connector-astar" \ + version="${IMAGE_VERSION}" \ + description="Astar chain connector" \ + one.analog.image.vendor="Analog One Foundation" \ + one.analog.image.source="https://github.com/Analog-Labs/chain-connectors/blob/${VCS_REF}/\ +chains/astar/Dockerfile" \ + one.analog.image.revision="${VCS_REF}" \ + one.analog.image.created="${BUILD_DATE}" + COPY bin/rosetta-server-astar rosetta-server-astar + +# check if executable works in this container +RUN ["/rosetta-server-astar", "--help"] + ENTRYPOINT ["/rosetta-server-astar"] diff --git a/chains/bitcoin/Dockerfile b/chains/bitcoin/Dockerfile index acfc2232..07b72665 100644 --- a/chains/bitcoin/Dockerfile +++ b/chains/bitcoin/Dockerfile @@ -1,3 +1,24 @@ +ARG REGISTRY_PATH +ARG IMAGE_VERSION +ARG VCS_REF +ARG BUILD_DATE + FROM scratch + +# metadata +LABEL summary="Analog’s connectors for bitcoin network" \ + name="${REGISTRY_PATH}/connector-bitcoin" \ + version="${IMAGE_VERSION}" \ + description="Bitcoin chain connector" \ + one.analog.image.vendor="Analog One Foundation" \ + one.analog.image.source="https://github.com/Analog-Labs/chain-connectors/blob/${VCS_REF}/\ +chains/bitcoin/Dockerfile" \ + one.analog.image.revision="${VCS_REF}" \ + one.analog.image.created="${BUILD_DATE}" + COPY bin/rosetta-server-bitcoin rosetta-server-bitcoin + +# check if executable works in this container +RUN ["/rosetta-server-bitcoin", "--help"] + ENTRYPOINT ["/rosetta-server-bitcoin"] diff --git a/chains/ethereum/Dockerfile b/chains/ethereum/Dockerfile index 83ecc419..d811bc17 100644 --- a/chains/ethereum/Dockerfile +++ b/chains/ethereum/Dockerfile @@ -1,3 +1,24 @@ +ARG REGISTRY_PATH +ARG IMAGE_VERSION +ARG VCS_REF +ARG BUILD_DATE + FROM scratch + +# metadata +LABEL summary="Analog’s connectors for ethereum network" \ + name="${REGISTRY_PATH}/connector-ethereum" \ + version="${IMAGE_VERSION}" \ + description="Ethereum chain connector" \ + one.analog.image.vendor="Analog One Foundation" \ + one.analog.image.source="https://github.com/Analog-Labs/chain-connectors/blob/${VCS_REF}/\ +chains/ethereum/Dockerfile" \ + one.analog.image.revision="${VCS_REF}" \ + one.analog.image.created="${BUILD_DATE}" + COPY bin/rosetta-server-ethereum rosetta-server-ethereum + +# check if executable works in this container +RUN ["/rosetta-server-ethereum", "--help"] + ENTRYPOINT ["/rosetta-server-ethereum"] diff --git a/chains/polkadot/Dockerfile b/chains/polkadot/Dockerfile index 88c1ab4e..714b5d20 100644 --- a/chains/polkadot/Dockerfile +++ b/chains/polkadot/Dockerfile @@ -1,3 +1,24 @@ +ARG REGISTRY_PATH +ARG IMAGE_VERSION +ARG VCS_REF +ARG BUILD_DATE + FROM scratch + +# metadata +LABEL summary="Analog’s connectors for polkadot network" \ + name="${REGISTRY_PATH}/connector-polkadot" \ + version="${IMAGE_VERSION}" \ + description="Polkadot chain connector" \ + one.analog.image.vendor="Analog One Foundation" \ + one.analog.image.source="https://github.com/Analog-Labs/chain-connectors/blob/${VCS_REF}/\ +chains/polkadot/Dockerfile" \ + one.analog.image.revision="${VCS_REF}" \ + one.analog.image.created="${BUILD_DATE}" + COPY bin/rosetta-server-polkadot rosetta-server-polkadot + +# check if executable works in this container +RUN ["/rosetta-server-polkadot", "--help"] + ENTRYPOINT ["/rosetta-server-polkadot"]