From c96519f5c8cc8accc5876bdbb6c2c411f27ff387 Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Wed, 31 Jul 2024 19:15:00 +0700 Subject: [PATCH 1/2] feat: release script" --- Dockerfile.release.aarch64 | 25 ++++++++++++++++++ Dockerfile.release.x86_64 | 24 +++++++++++++++++ release_binaries.sh | 53 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 Dockerfile.release.aarch64 create mode 100644 Dockerfile.release.x86_64 create mode 100755 release_binaries.sh diff --git a/Dockerfile.release.aarch64 b/Dockerfile.release.aarch64 new file mode 100644 index 0000000000..56574f41c3 --- /dev/null +++ b/Dockerfile.release.aarch64 @@ -0,0 +1,25 @@ +# Use the official Rust image based on Debian Bullseye +FROM rust@sha256:4c45f61ebe054560190f232b7d883f174ff287e1a0972c8f6d7ab88da0188870 + +# Install necessary packages +RUN apt-get update && apt-get install -y \ + clang \ + cmake \ + git \ + wget \ + bash \ + unzip \ + gcc-aarch64-linux-gnu \ + && rm -rf /var/lib/apt/lists/* + +# Add Rust target +RUN rustup target add aarch64-unknown-linux-gnu + +# Install protoc - protobuf compiler +RUN wget -q -O /tmp/protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v25.2/protoc-25.2-linux-aarch_64.zip && \ + unzip -qd /opt/protoc /tmp/protoc.zip && \ + rm /tmp/protoc.zip && \ + ln -s /opt/protoc/bin/protoc /usr/bin/ + +# Set the working directory inside the container +WORKDIR /app diff --git a/Dockerfile.release.x86_64 b/Dockerfile.release.x86_64 new file mode 100644 index 0000000000..a94ce51425 --- /dev/null +++ b/Dockerfile.release.x86_64 @@ -0,0 +1,24 @@ +# Use the official Rust image based on Debian Bullseye +FROM rust@sha256:4c45f61ebe054560190f232b7d883f174ff287e1a0972c8f6d7ab88da0188870 + +# Install necessary packages +RUN apt-get update && apt-get install -y \ + clang \ + cmake \ + git \ + wget \ + bash \ + unzip \ + && rm -rf /var/lib/apt/lists/* + +# Add Rust target +RUN rustup target add x86_64-unknown-linux-gnu + +# Install protoc - protobuf compiler +RUN wget -q -O /tmp/protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v25.2/protoc-25.2-linux-x86_64.zip && \ + unzip -qd /opt/protoc /tmp/protoc.zip && \ + rm /tmp/protoc.zip && \ + ln -s /opt/protoc/bin/protoc /usr/bin/ + +# Set the working directory inside the container +WORKDIR /app diff --git a/release_binaries.sh b/release_binaries.sh new file mode 100755 index 0000000000..cdf4e0d062 --- /dev/null +++ b/release_binaries.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +set -e + +# Function to build the Docker image if it doesn't exist +build_docker_image() { + local arch=$1 + local dockerfile=$2 + local image_name=$3 + + if ! docker images | grep -q ${image_name}; then + echo "Building Docker image ${image_name}..." + docker build -t ${image_name} -f ${dockerfile} . + else + echo "Docker image ${image_name} already exists." + fi +} + +# Function to build and strip the binary for a specific target +build_and_strip() { + local target=$1 + local output_name=$2 + local strip_tool=$3 + local image_name=$4 + + echo "Building for target ${target}..." + docker run --rm -v "$(pwd):/app" -w /app -u "$(id -u):$(id -g)" -e RUSTFLAGS='-C target-feature=+crt-static' ${image_name} cargo build --release --locked --target ${target} -p drive-abci + + echo "Renaming output binary to ${output_name}..." + mv target/${target}/release/drive-abci ${output_name} + + echo "Stripping binary ${output_name}..." + ${strip_tool} ${output_name} + + echo "Creating tar.gz archive for ${output_name}..." + tar -czf ${output_name}.tar.gz ${output_name} +} + +# Main script +main() { + build_docker_image x86_64 Dockerfile.release.x86_64 rust-build-env-x86_64 + build_docker_image aarch64 Dockerfile.release.aarch64 rust-build-env-aarch64 + + # Build and strip for x86_64 + build_and_strip x86_64-unknown-linux-gnu drive-abci-linux-gnu-x86_64 strip rust-build-env-x86_64 + + # Build and strip for aarch64 + build_and_strip aarch64-unknown-linux-gnu drive-abci-linux-gnu-aarch64 aarch64-linux-gnu-strip rust-build-env-aarch64 + + echo "Release process completed successfully." +} + +main From 5d3b487a4c4f9c54f3bc0e3d130cde5ed5ca260f Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 31 Jul 2024 21:58:36 +0700 Subject: [PATCH 2/2] chore: fix x86 build and refactor --- Dockerfile.release.aarch64 | 25 ---------------- Dockerfile.release.x86_64 | 24 --------------- Dockerfile.rust-build | 29 ++++++++++++++++++ release_binaries.sh | 53 --------------------------------- scripts/release_binaries.sh | 59 +++++++++++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+), 102 deletions(-) delete mode 100644 Dockerfile.release.aarch64 delete mode 100644 Dockerfile.release.x86_64 create mode 100644 Dockerfile.rust-build delete mode 100755 release_binaries.sh create mode 100755 scripts/release_binaries.sh diff --git a/Dockerfile.release.aarch64 b/Dockerfile.release.aarch64 deleted file mode 100644 index 56574f41c3..0000000000 --- a/Dockerfile.release.aarch64 +++ /dev/null @@ -1,25 +0,0 @@ -# Use the official Rust image based on Debian Bullseye -FROM rust@sha256:4c45f61ebe054560190f232b7d883f174ff287e1a0972c8f6d7ab88da0188870 - -# Install necessary packages -RUN apt-get update && apt-get install -y \ - clang \ - cmake \ - git \ - wget \ - bash \ - unzip \ - gcc-aarch64-linux-gnu \ - && rm -rf /var/lib/apt/lists/* - -# Add Rust target -RUN rustup target add aarch64-unknown-linux-gnu - -# Install protoc - protobuf compiler -RUN wget -q -O /tmp/protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v25.2/protoc-25.2-linux-aarch_64.zip && \ - unzip -qd /opt/protoc /tmp/protoc.zip && \ - rm /tmp/protoc.zip && \ - ln -s /opt/protoc/bin/protoc /usr/bin/ - -# Set the working directory inside the container -WORKDIR /app diff --git a/Dockerfile.release.x86_64 b/Dockerfile.release.x86_64 deleted file mode 100644 index a94ce51425..0000000000 --- a/Dockerfile.release.x86_64 +++ /dev/null @@ -1,24 +0,0 @@ -# Use the official Rust image based on Debian Bullseye -FROM rust@sha256:4c45f61ebe054560190f232b7d883f174ff287e1a0972c8f6d7ab88da0188870 - -# Install necessary packages -RUN apt-get update && apt-get install -y \ - clang \ - cmake \ - git \ - wget \ - bash \ - unzip \ - && rm -rf /var/lib/apt/lists/* - -# Add Rust target -RUN rustup target add x86_64-unknown-linux-gnu - -# Install protoc - protobuf compiler -RUN wget -q -O /tmp/protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v25.2/protoc-25.2-linux-x86_64.zip && \ - unzip -qd /opt/protoc /tmp/protoc.zip && \ - rm /tmp/protoc.zip && \ - ln -s /opt/protoc/bin/protoc /usr/bin/ - -# Set the working directory inside the container -WORKDIR /app diff --git a/Dockerfile.rust-build b/Dockerfile.rust-build new file mode 100644 index 0000000000..b961e8e10f --- /dev/null +++ b/Dockerfile.rust-build @@ -0,0 +1,29 @@ +# Use the official Rust image based on Debian Bullseye 1.76-bullseye +FROM rust@sha256:607b5e64b8d51f78ac5a37984e64f6493e9a7f90b605fa068be86ff035f48141 + +# Install necessary packages +RUN apt-get update && apt-get install -y \ + clang \ + cmake \ + git \ + wget \ + bash \ + unzip \ + && if [[ "$TARGETARCH" == "arm64" ]] ; then apt-get install -y gcc-aarch64-linux-gnu; fi \ + && rm -rf /var/lib/apt/lists/* + +# Add Rust target +RUN if [[ "$TARGETARCH" == "arm64" ]] ; then RUST_TARGET=aarch64-unknown-linux-gnu; else RUST_TARGET=x86_64-unknown-linux-gnu; fi; \ + rustup target add ${RUST_TARGET} + +# Install protoc - protobuf compiler +ARG PROTOC_VERSION="25.2" +RUN if [[ "$TARGETARCH" == "arm64" ]] ; then export PROTOC_ARCH=aarch_64; else export PROTOC_ARCH=x86_64; fi; \ + curl -Ls https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-${PROTOC_ARCH}.zip \ + -o /tmp/protoc.zip && \ + unzip -qd /opt/protoc /tmp/protoc.zip && \ + rm /tmp/protoc.zip && \ + ln -s /opt/protoc/bin/protoc /usr/bin/ + +# Set the working directory inside the container +WORKDIR /app diff --git a/release_binaries.sh b/release_binaries.sh deleted file mode 100755 index cdf4e0d062..0000000000 --- a/release_binaries.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash - -set -e - -# Function to build the Docker image if it doesn't exist -build_docker_image() { - local arch=$1 - local dockerfile=$2 - local image_name=$3 - - if ! docker images | grep -q ${image_name}; then - echo "Building Docker image ${image_name}..." - docker build -t ${image_name} -f ${dockerfile} . - else - echo "Docker image ${image_name} already exists." - fi -} - -# Function to build and strip the binary for a specific target -build_and_strip() { - local target=$1 - local output_name=$2 - local strip_tool=$3 - local image_name=$4 - - echo "Building for target ${target}..." - docker run --rm -v "$(pwd):/app" -w /app -u "$(id -u):$(id -g)" -e RUSTFLAGS='-C target-feature=+crt-static' ${image_name} cargo build --release --locked --target ${target} -p drive-abci - - echo "Renaming output binary to ${output_name}..." - mv target/${target}/release/drive-abci ${output_name} - - echo "Stripping binary ${output_name}..." - ${strip_tool} ${output_name} - - echo "Creating tar.gz archive for ${output_name}..." - tar -czf ${output_name}.tar.gz ${output_name} -} - -# Main script -main() { - build_docker_image x86_64 Dockerfile.release.x86_64 rust-build-env-x86_64 - build_docker_image aarch64 Dockerfile.release.aarch64 rust-build-env-aarch64 - - # Build and strip for x86_64 - build_and_strip x86_64-unknown-linux-gnu drive-abci-linux-gnu-x86_64 strip rust-build-env-x86_64 - - # Build and strip for aarch64 - build_and_strip aarch64-unknown-linux-gnu drive-abci-linux-gnu-aarch64 aarch64-linux-gnu-strip rust-build-env-aarch64 - - echo "Release process completed successfully." -} - -main diff --git a/scripts/release_binaries.sh b/scripts/release_binaries.sh new file mode 100755 index 0000000000..ac6568e304 --- /dev/null +++ b/scripts/release_binaries.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +set -e + +FULL_PATH=$(realpath "$0") +DIR_PATH=$(dirname "$FULL_PATH") +ROOT_PATH=$(dirname "$DIR_PATH") + +IMAGE_NAME="rust-build-env" + +# Function to build the Docker image if it doesn't exist +build_docker_image() { + echo "Building Docker image $IMAGE_NAME..." + docker buildx build -t $IMAGE_NAME \ + -f "$ROOT_PATH/Dockerfile.rust-build" \ + --platform linux/amd64,linux/arm64 \ + --load \ + "$ROOT_PATH" +} + +# Function to build and strip the binary for a specific target +build() { + local target=$1 + local output_name=$2 + local arch=$3 + + echo "Building Drive for target ${target}..." + docker run --rm \ + -v "$ROOT_PATH:/app" \ + -w /app \ + -u "$(id -u):$(id -g)" \ + --platform "$arch" \ + "$IMAGE_NAME" \ + cargo build --release \ + --locked \ + --target "$target" \ + -p drive-abci + + echo "Renaming output binary to ${output_name}..." + mv "$ROOT_PATH/target/$target/release/drive-abci" "$ROOT_PATH/$output_name" + + echo "Creating tar.gz archive for $output_name..." + tar -czf "$ROOT_PATH/$output_name.tar.gz" "$ROOT_PATH/$output_name" +} + +# Main script +main() { + build_docker_image + + # Build for x86_64 + build x86_64-unknown-linux-gnu drive-abci-linux-gnu-x86_64 linux/amd64 + + # Build for aarch64 + build aarch64-unknown-linux-gnu drive-abci-linux-gnu-aarch64 linux/arm64 + + echo "Release process completed successfully." +} + +main