Skip to content

Commit

Permalink
docker: add dockerfile for building a number of sui binaries (MystenL…
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill authored Jun 15, 2022
1 parent 801b115 commit 8f3e46b
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
54 changes: 54 additions & 0 deletions docker/sui-tools/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
FROM rust:1.60.0 AS chef
WORKDIR sui
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' 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
RUN cargo build --release \
--bin sui-node \
--bin sui \
--bin wallet \
--bin sui-move

# Production Image
FROM debian:bullseye-slim AS runtime
WORKDIR sui
COPY --from=builder /sui/target/release/sui-node /usr/local/bin
COPY --from=builder /sui/target/release/sui /usr/local/bin
COPY --from=builder /sui/target/release/wallet /usr/local/bin
COPY --from=builder /sui/target/release/sui-move /usr/local/bin

ARG BUILD_DATE
ARG GIT_REVISION
LABEL build-date=$BUILD_DATE
LABEL git-revision=$GIT_REVISION
25 changes: 25 additions & 0 deletions docker/sui-tools/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
# Copyright (c) 2022, Mysten Labs, Inc.
# SPDX-License-Identifier: Apache-2.0

# fast fail.
set -eo pipefail

DIR="$( cd "$( dirname "$0" )" && pwd )"
REPO_ROOT="$(git rev-parse --show-toplevel)"
DOCKERFILE="$DIR/Dockerfile"
GIT_REVISION="$(git describe --always --dirty)"
BUILD_DATE="$(date -u +'%Y-%m-%d')"

echo
echo "Building sui-node 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" \
"$@"

0 comments on commit 8f3e46b

Please sign in to comment.