diff --git a/docker/sui-source-service/Dockerfile b/docker/sui-source-service/Dockerfile new file mode 100644 index 0000000000000..4a1657ab8f1b3 --- /dev/null +++ b/docker/sui-source-service/Dockerfile @@ -0,0 +1,53 @@ +FROM rust:1.70.0 AS chef +WORKDIR sui +ARG GIT_REVISION +ENV GIT_REVISION=$GIT_REVISION +RUN apt-get update && apt-get install -y cmake clang + +# Plan out the 3rd-party dependencies that need to be built. +# +# This is done by: +# 1. Copy in Cargo.toml, Cargo.lock, and the workspace-hack crate +# 2. Removing all workspace crates, other than the workpsace-hack +# crate, from the workspace Cargo.toml file. +# 3. Update the lockfile in order to reflect the changes to the +# root Cargo.toml file. +# FROM chef AS planner +# COPY Cargo.toml Cargo.lock ./ +# COPY crates/workspace-hack crates/workspace-hack +# RUN sed -i '/crates\/workspace-hack/b; /crates/d; /narwhal/d' Cargo.toml \ +# && cargo metadata -q >/dev/null + +# Build and cache all dependencies. +# +# In a fresh layer, copy in the "plan" generated by the planner +# and run `cargo build` in order to create a caching Docker layer +# with all dependencies built. +FROM chef AS builder +# COPY --from=planner /sui/Cargo.toml Cargo.toml +# COPY --from=planner /sui/Cargo.lock Cargo.lock +# COPY --from=planner /sui/crates/workspace-hack crates/workspace-hack +# RUN cargo build --release + +# Build application +# +# Copy in the rest of the crates (and an unmodified Cargo.toml and Cargo.lock) +# and build the application. At this point no dependencies should need to be +# built as they were built and cached by the previous layer. +COPY Cargo.toml Cargo.lock ./ +COPY crates crates +COPY sui-execution sui-execution +COPY narwhal narwhal +COPY external-crates external-crates +RUN cargo build --release \ + --bin sui-source-validation-service + +# Production Image +FROM debian:bullseye-slim AS runtime +WORKDIR sui +COPY --from=builder /sui/target/release/sui-source-validation-service /usr/local/bin + +ARG BUILD_DATE +ARG GIT_REVISION +LABEL build-date=$BUILD_DATE +LABEL git-revision=$GIT_REVISION diff --git a/docker/sui-source-service/build.sh b/docker/sui-source-service/build.sh new file mode 100755 index 0000000000000..26f02740e8592 --- /dev/null +++ b/docker/sui-source-service/build.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# Copyright (c) Mysten Labs, Inc. +# SPDX-License-Identifier: Apache-2.0 + +# fast fail. +set -e + +DIR="$( cd "$( dirname "$0" )" && pwd )" +REPO_ROOT="$(git rev-parse --show-toplevel)" +DOCKERFILE="$DIR/Dockerfile" +GIT_REVISION="$(git describe --always --dirty --exclude '*')" +BUILD_DATE="$(date -u +'%Y-%m-%d')" + +echo +echo "Building sui-source-service docker image" +echo "Dockerfile: \t$DOCKERFILE" +echo "docker context: $REPO_ROOT" +echo "build date: \t$BUILD_DATE" +echo "git revision: \t$GIT_REVISION" +echo + +docker build -f "$DOCKERFILE" "$REPO_ROOT" \ + --build-arg GIT_REVISION="$GIT_REVISION" \ + --build-arg BUILD_DATE="$BUILD_DATE" \ + "$@"