From 8e67b9c215a28d964ab7af19d29ffec240a1fe9e Mon Sep 17 00:00:00 2001 From: Rijnard van Tonder Date: Wed, 2 Aug 2023 10:56:19 -0600 Subject: [PATCH] move: source service docker file (#13082) ## Description As in title. ## Test Plan How did you test the new or updated feature? Built the image with docker, N/A --- If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process. ### Type of Change (Check all that apply) - [ ] protocol change - [ ] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes --- docker/sui-source-service/Dockerfile | 53 ++++++++++++++++++++++++++++ docker/sui-source-service/build.sh | 25 +++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 docker/sui-source-service/Dockerfile create mode 100755 docker/sui-source-service/build.sh 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" \ + "$@"