From 64633e0c6ca7284cdb6be4343947c057082a4b14 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Fri, 24 Mar 2023 17:33:47 +0100 Subject: [PATCH 1/4] build(rs-drive-abci): fix arm64 build issues --- packages/rs-drive-abci/Dockerfile | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/rs-drive-abci/Dockerfile b/packages/rs-drive-abci/Dockerfile index 607a46e82ce..567c3f9d55a 100644 --- a/packages/rs-drive-abci/Dockerfile +++ b/packages/rs-drive-abci/Dockerfile @@ -72,16 +72,24 @@ ARG ACTIONS_RUNTIME_TOKEN ARG CARGO_INCREMENTAL=false # Run the build, with extensive caching. +# +# Note: +# 1. All these --mount... are to cache reusable info between runs. # See https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci -# --mount=type=cache,sharing=private,target=/usr/src/platform/target \ +# 2. We add `--config net.git-fetch-with-cli=true` to address ARM build issue, +# see https://github.com/rust-lang/cargo/issues/10781#issuecomment-1441071052 +# 3. To preserve space on github cache, we call `cargo clean`. RUN --mount=type=cache,sharing=shared,target=/root/.cache/sccache \ --mount=type=cache,sharing=shared,target=${CARGO_HOME}/.crates.toml \ --mount=type=cache,sharing=shared,target=${CARGO_HOME}/.crates2.json \ --mount=type=cache,sharing=shared,target=${CARGO_HOME}/registry/index \ --mount=type=cache,sharing=shared,target=${CARGO_HOME}/registry/cache \ --mount=type=cache,sharing=shared,target=${CARGO_HOME}/git/db \ - cargo build -p drive-abci \ - && cp /usr/src/platform/target/${CARGO_BUILD_PROFILE}/drive-abci /usr/src/platform/drive-abci + cargo build \ + --package drive-abci \ + --config net.git-fetch-with-cli=true && \ + cp /usr/src/platform/target/${CARGO_BUILD_PROFILE}/drive-abci /usr/src/platform/drive-abci && \ + cargo clean # # FINAL IMAGE From cd3edf9e5ba5ec2cfc1fc7d81fbfcba8261e53d8 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Mon, 27 Mar 2023 14:26:13 +0200 Subject: [PATCH 2/4] build(drive-abci): Dockerfile uses Alpine --- packages/rs-drive-abci/Dockerfile | 66 +++++++++++++++---------------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/packages/rs-drive-abci/Dockerfile b/packages/rs-drive-abci/Dockerfile index 567c3f9d55a..3f77f1a4646 100644 --- a/packages/rs-drive-abci/Dockerfile +++ b/packages/rs-drive-abci/Dockerfile @@ -7,47 +7,41 @@ # - build - actual build process # - release - final image # -# We use Debian as base, because Alpine causes segmentation fault in git2 rust crate. + +ARG ALPINE_VERSION=3.17 # # DEPS: INSTALL AND CACHE DEPENDENCIES # -FROM rust:bullseye as deps +FROM rust:alpine${ALPINE_VERSION} as deps -LABEL maintainer="Dash Developers " -LABEL description="Drive ABCI Rust" +# +# Update Rust runtime +# +ARG CARGO_BUILD_PROFILE=debug +RUN rustup install stable -RUN --mount=type=cache,sharing=locked,target=/var/lib/apt/lists \ - --mount=type=cache,sharing=locked,target=/var/cache/apt \ - rm -f /etc/apt/apt.conf.d/docker-clean \ - && apt-get update \ - && apt-get install --yes \ - build-essential \ - libclang-dev \ - libssl-dev \ - protobuf-compiler \ +RUN apk add --no-cache \ + alpine-sdk \ + bash \ + clang-dev \ git \ - wget \ + linux-headers \ + openssl-dev \ + perl \ + sccache \ unzip \ - bash + wget SHELL ["/bin/bash", "-c"] -# -# Install sccache - build cache for Rust -# -ARG SCCACHE_URL="https://github.com/mozilla/sccache/releases/download/v0.4.0/sccache-v0.4.0-x86_64-unknown-linux-musl.tar.gz" -RUN wget -q -O /tmp/sccache.tar.gz ${SCCACHE_URL} \ - && mkdir -p /tmp/sccache \ - && tar -z -C /tmp/sccache -xf /tmp/sccache.tar.gz \ - && cp /tmp/sccache/sccache*/sccache /usr/bin/sccache \ - && rm -r /tmp/sccache.tar.gz /tmp/sccache - -# -# Update Rust runtime -# -ARG CARGO_BUILD_PROFILE=debug -RUN rustup install stable +# Install protoc - protobuf compiler +# The one shipped with Alpine does not work +ARG PROTOC_ARCH=x86_64 +RUN wget -q -O /tmp/protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v22.2/protoc-22.2-linux-${PROTOC_ARCH}.zip && \ + unzip -qd /opt/protoc /tmp/protoc.zip && \ + rm /tmp/protoc.zip && \ + ln -s /opt/protoc/bin/protoc /usr/bin/ # # EXECUTE BUILD @@ -61,7 +55,6 @@ COPY . . # # Configure sccache # - # Set RUSTC_WRAPPER=/usr/bin/sccache to enable `sccache` caching. ARG RUSTC_WRAPPER=/usr/bin/sccache # Set args below to use Github Actions cache; see https://github.com/mozilla/sccache/blob/main/docs/GHA.md @@ -94,7 +87,10 @@ RUN --mount=type=cache,sharing=shared,target=/root/.cache/sccache \ # # FINAL IMAGE # -FROM debian:bullseye-slim AS release +FROM alpine:${ALPINE_VERSION} AS release + +LABEL maintainer="Dash Developers " +LABEL description="Drive ABCI Rust" VOLUME /var/lib/platform @@ -114,9 +110,9 @@ COPY --from=build /usr/src/platform/packages/rs-drive-abci/.env.example /var/lib ARG USERNAME=platform ARG USER_UID=1000 ARG USER_GID=$USER_UID -RUN groupadd --gid $USER_GID $USERNAME \ - && useradd --uid $USER_UID --gid $USER_GID --home /var/lib/platform/rs-drive-abci --create-home $USERNAME \ - && chown -R $USER_UID:$USER_GID /var/lib/platform/rs-drive-abci +RUN addgroup -g $USER_GID $USERNAME && \ + adduser -D -u $USER_UID -G $USERNAME -h /var/lib/platform/rs-drive-abci $USERNAME && \ + chown -R $USER_UID:$USER_GID /var/lib/platform/rs-drive-abci USER $USERNAME From 28a7b4a47965cef9fda3d6938a10ce262d2ce6f4 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Thu, 30 Mar 2023 10:55:28 +0200 Subject: [PATCH 3/4] build(rs-drive-abci): improve ARG and ENV vars --- packages/rs-drive-abci/Dockerfile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/rs-drive-abci/Dockerfile b/packages/rs-drive-abci/Dockerfile index 3f77f1a4646..5f43ba5549f 100644 --- a/packages/rs-drive-abci/Dockerfile +++ b/packages/rs-drive-abci/Dockerfile @@ -55,14 +55,15 @@ COPY . . # # Configure sccache # -# Set RUSTC_WRAPPER=/usr/bin/sccache to enable `sccache` caching. -ARG RUSTC_WRAPPER=/usr/bin/sccache # Set args below to use Github Actions cache; see https://github.com/mozilla/sccache/blob/main/docs/GHA.md ARG SCCACHE_GHA_ENABLED ARG ACTIONS_CACHE_URL ARG ACTIONS_RUNTIME_TOKEN + +# Activate sccache for Rust code +ENV RUSTC_WRAPPER=/usr/bin/sccache # Disable incremental buildings, not supported by sccache -ARG CARGO_INCREMENTAL=false +ENV CARGO_INCREMENTAL=false # Run the build, with extensive caching. # @@ -73,8 +74,6 @@ ARG CARGO_INCREMENTAL=false # see https://github.com/rust-lang/cargo/issues/10781#issuecomment-1441071052 # 3. To preserve space on github cache, we call `cargo clean`. RUN --mount=type=cache,sharing=shared,target=/root/.cache/sccache \ - --mount=type=cache,sharing=shared,target=${CARGO_HOME}/.crates.toml \ - --mount=type=cache,sharing=shared,target=${CARGO_HOME}/.crates2.json \ --mount=type=cache,sharing=shared,target=${CARGO_HOME}/registry/index \ --mount=type=cache,sharing=shared,target=${CARGO_HOME}/registry/cache \ --mount=type=cache,sharing=shared,target=${CARGO_HOME}/git/db \ From a9087f9a1c1075797787683aa79729028e616329 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Thu, 30 Mar 2023 11:08:21 +0200 Subject: [PATCH 4/4] build(rs-drive-abci): add some docs to Dockerfile --- packages/rs-drive-abci/Dockerfile | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/rs-drive-abci/Dockerfile b/packages/rs-drive-abci/Dockerfile index 5f43ba5549f..16e9a6cd6b2 100644 --- a/packages/rs-drive-abci/Dockerfile +++ b/packages/rs-drive-abci/Dockerfile @@ -7,7 +7,15 @@ # - build - actual build process # - release - final image # - +# The following build arguments can be provided using --build-arg: +# - CARGO_BUILD_PROFILE - set to `release` to build final binary, without debugging information +# - SCCACHE_GHA_ENABLED, ACTIONS_CACHE_URL, ACTIONS_RUNTIME_TOKEN - store sccache caches inside github actions +# cache instead of Docker cache mounts (not tested yet) +# - PROTOC_ARCH - select architecture of protobuf compiler; one of: `x86_64` (default), `aarch_64` +# - ALPINE_VERSION - use different version of Alpine base image; requires also rust:apline... +# image to be available +# - USERNAME, USER_UID, USER_GID - specification of user used to run the binary +# ARG ALPINE_VERSION=3.17 #