Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 42 additions & 38 deletions packages/rs-drive-abci/Dockerfile
Comment thread
lklimek marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <dev@dash.org>"
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
Expand All @@ -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
Expand All @@ -72,21 +65,32 @@ ARG ACTIONS_RUNTIME_TOKEN
ARG CARGO_INCREMENTAL=false
Comment thread
lklimek marked this conversation as resolved.
Outdated

# 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 debian:bullseye-slim AS release
FROM alpine:${ALPINE_VERSION} AS release

LABEL maintainer="Dash Developers <dev@dash.org>"
LABEL description="Drive ABCI Rust"

VOLUME /var/lib/platform

Expand All @@ -106,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

Expand Down