# syntax=docker/dockerfile:1.3

# Copyright (c) 2024 by Alibaba.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

FROM alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:latest as builder

RUN yum install -y perl wget curl clang openssh-clients openssl-devel protobuf-devel git

WORKDIR /usr/src/trustee
COPY . .

# Install Rust
RUN export RUSTUP_DIST_SERVER='https://mirrors.ustc.edu.cn/rust-static' && \
    export RUSTUP_UPDATE_ROOT='https://mirrors.ustc.edu.cn/rust-static/rustup' && \
    curl --proto '=https' --tlsv1.2 -sSf https://mirrors.aliyun.com/repo/rust/rustup-init.sh | \
    sh  -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN export RUSTUP_DIST_SERVER='https://mirrors.ustc.edu.cn/rust-static' && \
    export RUSTUP_UPDATE_ROOT='https://mirrors.ustc.edu.cn/rust-static/rustup' && \
    rustup toolchain install 1.79.0-x86_64-unknown-linux-gnu
RUN printf '\
    [source.crates-io]\n\
    replace-with = "aliyun"\n\
    [source.aliyun]\n\
    registry = "sparse+https://mirrors.aliyun.com/crates.io-index/"\n\
    ' > ~/.cargo/config

RUN cargo build -p kbs-client --locked --release --no-default-features --features sample_only

FROM alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:latest

WORKDIR /tmp

# Copy binaries
COPY --from=builder /usr/src/trustee/target/release/kbs-client /usr/local/bin/trustee-client