Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Apple Silicon and Linux Arm64 targets #140

Merged
merged 14 commits into from
Jul 28, 2023
142 changes: 122 additions & 20 deletions build_connectors.sh
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions chains/astar/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
21 changes: 21 additions & 0 deletions chains/bitcoin/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
21 changes: 21 additions & 0 deletions chains/ethereum/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
21 changes: 21 additions & 0 deletions chains/polkadot/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]