diff --git a/.github/workflows/release_docker.yml b/.github/workflows/release_docker.yml index ba9cb957cad..0cdf3645e19 100644 --- a/.github/workflows/release_docker.yml +++ b/.github/workflows/release_docker.yml @@ -35,6 +35,15 @@ jobs: - name: Checkout code uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 + - name: Read Rust toolchain version from TOML + id: read_toolchain + run: | + TOOLCHAIN_VERSION=$(grep -oE 'channel = "[^"]+' ./rust-toolchain.toml | sed 's/channel = "//') + echo "TOOLCHAIN_VERSION=${TOOLCHAIN_VERSION}" >> $GITHUB_ENV + + - name: Log Rust toolchain version + run: echo "Rust toolchain version is ${{ env.TOOLCHAIN_VERSION }}" + - name: Set up QEMU uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0 @@ -78,6 +87,8 @@ jobs: with: context: . file: docker/iota-node/Dockerfile + build-args: | + RUST_IMAGE_VERSION=${{ env.TOOLCHAIN_VERSION }}-bookworm platforms: linux/amd64 tags: ${{ steps.meta-node.outputs.tags }} push: true @@ -94,6 +105,15 @@ jobs: - name: Checkout code uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 + - name: Read Rust toolchain version from TOML + id: read_toolchain + run: | + TOOLCHAIN_VERSION=$(grep -oE 'channel = "[^"]+' ./rust-toolchain.toml | sed 's/channel = "//') + echo "TOOLCHAIN_VERSION=${TOOLCHAIN_VERSION}" >> $GITHUB_ENV + + - name: Log Rust toolchain version + run: echo "Rust toolchain version is ${{ env.TOOLCHAIN_VERSION }}" + - name: Set up QEMU uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0 @@ -137,6 +157,8 @@ jobs: with: context: . file: docker/iota-indexer/Dockerfile + build-args: | + RUST_IMAGE_VERSION=${{ env.TOOLCHAIN_VERSION }}-bookworm platforms: linux/amd64 tags: ${{ steps.meta-indexer.outputs.tags }} push: true @@ -153,6 +175,15 @@ jobs: - name: Checkout code uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 + - name: Read Rust toolchain version from TOML + id: read_toolchain + run: | + TOOLCHAIN_VERSION=$(grep -oE 'channel = "[^"]+' ./rust-toolchain.toml | sed 's/channel = "//') + echo "TOOLCHAIN_VERSION=${TOOLCHAIN_VERSION}" >> $GITHUB_ENV + + - name: Log Rust toolchain version + run: echo "Rust toolchain version is ${{ env.TOOLCHAIN_VERSION }}" + - name: Set up QEMU uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0 @@ -196,6 +227,8 @@ jobs: with: context: . file: docker/iota-tools/Dockerfile + build-args: | + RUST_IMAGE_VERSION=${{ env.TOOLCHAIN_VERSION }}-bookworm platforms: linux/amd64 tags: ${{ steps.meta-tools.outputs.tags }} push: true @@ -212,6 +245,15 @@ jobs: - name: Checkout code uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 + - name: Read Rust toolchain version from TOML + id: read_toolchain + run: | + TOOLCHAIN_VERSION=$(grep -oE 'channel = "[^"]+' ./rust-toolchain.toml | sed 's/channel = "//') + echo "TOOLCHAIN_VERSION=${TOOLCHAIN_VERSION}" >> $GITHUB_ENV + + - name: Log Rust toolchain version + run: echo "Rust toolchain version is ${{ env.TOOLCHAIN_VERSION }}" + - name: Set up QEMU uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0 @@ -255,6 +297,8 @@ jobs: with: context: . file: docker/iota-graphql-rpc/Dockerfile + build-args: | + RUST_IMAGE_VERSION=${{ env.TOOLCHAIN_VERSION }}-bookworm platforms: linux/amd64 tags: ${{ steps.meta-tools.outputs.tags }} push: true diff --git a/crates/iota-rosetta/README.md b/crates/iota-rosetta/README.md index 06d8d16afd8..ae79306cb62 100644 --- a/crates/iota-rosetta/README.md +++ b/crates/iota-rosetta/README.md @@ -45,7 +45,7 @@ This will generate the `rosetta-cli.json` and `iota.ros` file to be used by the #### 1. CD into the Dockerfile directory ```shell -cd /crate/iota-rosetta/docker/iota-rosetta-local +cd /docker/iota-rosetta-local ``` #### 2. Build the image diff --git a/crates/iota-rosetta/docker/iota-rosetta-devnet/Dockerfile b/crates/iota-rosetta/docker/iota-rosetta-devnet/Dockerfile deleted file mode 100644 index 9f5c85f10ab..00000000000 --- a/crates/iota-rosetta/docker/iota-rosetta-devnet/Dockerfile +++ /dev/null @@ -1,33 +0,0 @@ -FROM ubuntu:latest AS chef -WORKDIR iota -ARG GIT_REVISION -ENV GIT_REVISION=$GIT_REVISION -RUN apt-get update && apt-get install -y build-essential libssl-dev pkg-config curl cmake clang git ca-certificates -RUN curl https://sh.rustup.rs -sSf | bash -s -- -y -ENV PATH="/root/.cargo/bin:${PATH}" - -FROM chef AS builder - -RUN git clone https://github.com/iotaledger/iota . -RUN git checkout devnet - -RUN curl -sSfL https://raw.githubusercontent.com/coinbase/rosetta-cli/master/scripts/install.sh | sh -s -RUN curl -fLJO https://github.com/iotaledger/iota-genesis/raw/main/devnet/genesis.blob - -RUN cargo build --release --bin iota --bin iota-rosetta --bin iota-node - -# Production Image -FROM ubuntu:latest AS runtime -WORKDIR iota -RUN apt-get update && apt-get install -y ca-certificates -COPY --from=builder /iota/target/release/iota /usr/local/bin -COPY --from=builder /iota/target/release/iota-node /usr/local/bin -COPY --from=builder /iota/target/release/iota-rosetta /usr/local/bin -COPY --from=builder /iota/bin/rosetta-cli /usr/local/bin -COPY --from=builder /iota/crates/iota-config/data/fullnode-template.yaml /iota/devnet/fullnode.yaml -COPY --from=builder /iota/genesis.blob /iota/devnet/genesis.blob -RUN /usr/local/bin/iota genesis - -ARG BUILD_DATE -LABEL build-date=$BUILD_DATE -LABEL git-revision=$GIT_REVISION diff --git a/crates/iota-rosetta/docker/iota-rosetta-devnet/build.sh b/crates/iota-rosetta/docker/iota-rosetta-devnet/build.sh deleted file mode 100755 index 5c618a0b863..00000000000 --- a/crates/iota-rosetta/docker/iota-rosetta-devnet/build.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh -# Copyright (c) Mysten Labs, Inc. -# Modifications Copyright (c) 2024 IOTA Stiftung -# 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 --abbrev=12 --dirty --exclude '*')" -BUILD_DATE="$(date -u +'%Y-%m-%d')" - -echo -echo "Building iota-rosetta 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" \ - -t iotaledger/iota-rosetta-devnet \ - --build-arg GIT_REVISION="$GIT_REVISION" \ - --build-arg BUILD_DATE="$BUILD_DATE" \ - "$@" diff --git a/crates/iota-rosetta/docker/iota-rosetta-local/Dockerfile b/crates/iota-rosetta/docker/iota-rosetta-local/Dockerfile deleted file mode 100644 index 9a30acfef66..00000000000 --- a/crates/iota-rosetta/docker/iota-rosetta-local/Dockerfile +++ /dev/null @@ -1,35 +0,0 @@ -FROM ubuntu:latest AS chef -WORKDIR iota -ARG GIT_REVISION -ENV GIT_REVISION=$GIT_REVISION -RUN apt-get update && apt-get install -y build-essential libssl-dev pkg-config curl cmake clang ca-certificates -RUN curl https://sh.rustup.rs -sSf | bash -s -- -y -ENV PATH="/root/.cargo/bin:${PATH}" - -# Build application -FROM chef AS builder - -RUN curl -sSfL https://raw.githubusercontent.com/coinbase/rosetta-cli/master/scripts/install.sh | sh -s - -COPY Cargo.toml Cargo.lock ./ -COPY consensus consensus -COPY crates crates -COPY iota-execution iota-execution -COPY external-crates external-crates -COPY docs docs - -RUN cargo build --release --bin iota --bin iota-rosetta - -# Production Image -FROM ubuntu:latest AS runtime -WORKDIR iota -RUN apt-get update && apt-get install -y ca-certificates -COPY --from=builder /iota/target/release/iota /usr/local/bin -COPY --from=builder /iota/target/release/iota-rosetta /usr/local/bin -COPY --from=builder /iota/bin/rosetta-cli /usr/local/bin -COPY --from=builder /iota/crates/iota-config/data/fullnode-template.yaml /iota/devnet/fullnode.yaml -RUN /usr/local/bin/iota genesis - -ARG BUILD_DATE -LABEL build-date=$BUILD_DATE -LABEL git-revision=$GIT_REVISION diff --git a/crates/iota-rosetta/docker/iota-rosetta-local/build.sh b/crates/iota-rosetta/docker/iota-rosetta-local/build.sh deleted file mode 100755 index 5fd6e8c8645..00000000000 --- a/crates/iota-rosetta/docker/iota-rosetta-local/build.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh -# Copyright (c) Mysten Labs, Inc. -# Modifications Copyright (c) 2024 IOTA Stiftung -# 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 --abbrev=12 --dirty --exclude '*')" -BUILD_DATE="$(date -u +'%Y-%m-%d')" - -echo -echo "Building iota-rosetta 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" \ - -t iotaledger/iota-rosetta-local \ - --build-arg GIT_REVISION="$GIT_REVISION" \ - --build-arg BUILD_DATE="$BUILD_DATE" \ - "$@" diff --git a/docker/iota-bridge-indexer/Dockerfile b/docker/iota-bridge-indexer/Dockerfile index 6c74d925bee..9dd2957ed93 100644 --- a/docker/iota-bridge-indexer/Dockerfile +++ b/docker/iota-bridge-indexer/Dockerfile @@ -1,40 +1,61 @@ -# Build application -# -# Copy in all crates, Cargo.toml and Cargo.lock unmodified, -# and build the application. -FROM rust:bullseye AS builder +# Build image (the specific rust version can also be passed, e.g. "1.82-bookworm") +ARG RUST_IMAGE_VERSION=bookworm +FROM rust:${RUST_IMAGE_VERSION} AS builder + ARG PROFILE=release +ARG CARGO_BUILD_FEATURES +# The GIT_REVISION environment variable is used during build time inside the rust crates ARG GIT_REVISION ENV GIT_REVISION=$GIT_REVISION -WORKDIR "$WORKDIR/iota" -RUN apt-get update && apt-get install -y cmake clang +WORKDIR "/iota" -# bridge-indexer needs postgres libpq5 and ca-certificates -RUN apt update && apt install -y libpq5 ca-certificates libpq-dev postgresql +# Install build dependencies, including clang and lld for faster linking +RUN apt update && apt install -y cmake clang lld -COPY Cargo.toml Cargo.lock ./ +# Configure Rust to use clang and lld as the linker +RUN mkdir -p ~/.cargo && \ + echo -e "[target.x86_64-unknown-linux-gnu]\nlinker = \"clang\"\nrustflags = [\"-C\", \"link-arg=-fuse-ld=lld\"]" > ~/.cargo/config.toml + +# Install additional dependencies +RUN apt install -y libpq5 libpq-dev ca-certificates + +# Copy in all crates, Cargo.toml, and Cargo.lock COPY consensus consensus COPY crates crates -COPY iota-execution iota-execution -COPY external-crates external-crates COPY docs docs +COPY external-crates external-crates +COPY iota-execution iota-execution +COPY Cargo.toml Cargo.lock ./ + +RUN cargo build --profile ${PROFILE} --bin bridge-indexer --features ${CARGO_BUILD_FEATURES:=default} + +# Copy the built binary to the working directory depending on the output folder of the profile, +# so we can copy it to the runtime image +RUN if [ -d target/release ]; then \ + TARGET_DIR="target/release"; \ +elif [ -d target/debug ]; then \ + TARGET_DIR="target/debug"; \ +else \ + echo "Error: No build directory found"; \ + exit 1; \ +fi && \ +mv $TARGET_DIR/bridge-indexer ./; -RUN cargo build --profile ${PROFILE} --bin bridge-indexer +# Production image +FROM debian:bookworm-slim AS runtime -# Copy the built binary to the working directory depending on the profile, so we can copy it to the runtime image -RUN mv target/$(if [ $PROFILE = "dev" ]; then echo "debug"; else echo "release";fi)/bridge-indexer ./ +ARG WORKDIR="/iota" +WORKDIR "$WORKDIR" -# Production Image -FROM debian:bullseye-slim AS runtime +# Install runtime dependencies and tools +RUN apt update && apt install -y libpq5 ca-certificates curl -# Use jemalloc as memory allocator -RUN apt-get update && apt-get install -y libjemalloc-dev ca-certificates curl +# Install jemalloc as the default allocator +RUN apt install -y libjemalloc-dev ENV LD_PRELOAD /usr/lib/x86_64-linux-gnu/libjemalloc.so -WORKDIR "$WORKDIR/iota" COPY --from=builder /iota/bridge-indexer /usr/local/bin -RUN apt update && apt install -y libpq5 ca-certificates libpq-dev postgresql ARG BUILD_DATE ARG GIT_REVISION diff --git a/docker/iota-bridge-indexer/build.sh b/docker/iota-bridge-indexer/build.sh index 182f6351352..4d30b49572e 100755 --- a/docker/iota-bridge-indexer/build.sh +++ b/docker/iota-bridge-indexer/build.sh @@ -1,26 +1,5 @@ -#!/bin/sh +#!/bin/bash # Copyright (c) Mysten Labs, Inc. # Modifications Copyright (c) 2024 IOTA Stiftung # 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 --abbrev=12 --dirty --exclude '*')" -BUILD_DATE="$(date -u +'%Y-%m-%d')" - -echo -echo "Building bridge-indexer 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" \ - "$@" +./../utils/build-script.sh --container-name "iotaledger/bridge-indexer" diff --git a/docker/iota-graphql-rpc/Dockerfile b/docker/iota-graphql-rpc/Dockerfile index 35328801595..b23d4215768 100644 --- a/docker/iota-graphql-rpc/Dockerfile +++ b/docker/iota-graphql-rpc/Dockerfile @@ -1,34 +1,57 @@ -# Build application -# -# Copy in all crates, Cargo.toml and Cargo.lock unmodified, -# and build the application. -FROM rust:bullseye AS builder +# Build image (the specific rust version can also be passed, e.g. "1.82-bookworm") +ARG RUST_IMAGE_VERSION=bookworm +FROM rust:${RUST_IMAGE_VERSION} AS builder + ARG PROFILE=release -ENV PROFILE=$PROFILE +ARG CARGO_BUILD_FEATURES +# The GIT_REVISION environment variable is used during build time inside the rust crates ARG GIT_REVISION ENV GIT_REVISION=$GIT_REVISION -WORKDIR "$WORKDIR/iota" -RUN apt-get update && apt-get install -y cmake clang libpq-dev -COPY Cargo.toml Cargo.lock ./ +WORKDIR "/iota" + +# Install build dependencies, including clang and lld for faster linking +RUN apt update && apt install -y cmake clang lld + +# Configure Rust to use clang and lld as the linker +RUN mkdir -p ~/.cargo && \ + echo -e "[target.x86_64-unknown-linux-gnu]\nlinker = \"clang\"\nrustflags = [\"-C\", \"link-arg=-fuse-ld=lld\"]" > ~/.cargo/config.toml + +# Install additional dependencies +RUN apt install -y libpq5 libpq-dev ca-certificates + +# Copy in all crates, Cargo.toml, and Cargo.lock COPY consensus consensus COPY crates crates -COPY iota-execution iota-execution -COPY external-crates external-crates COPY docs docs +COPY external-crates external-crates +COPY iota-execution iota-execution +COPY Cargo.toml Cargo.lock ./ + +RUN cargo build --profile ${PROFILE} --bin iota-graphql-rpc --features ${CARGO_BUILD_FEATURES:=default} + +# Copy the built binary to the working directory depending on the output folder of the profile, +# so we can copy it to the runtime image +RUN if [ -d target/release ]; then \ + TARGET_DIR="target/release"; \ +elif [ -d target/debug ]; then \ + TARGET_DIR="target/debug"; \ +else \ + echo "Error: No build directory found"; \ + exit 1; \ +fi && \ +mv $TARGET_DIR/iota-graphql-rpc ./; + +# Production image +FROM debian:bookworm-slim AS runtime -RUN cargo build --profile ${PROFILE} --bin iota-graphql-rpc +ARG WORKDIR="/iota" +WORKDIR "$WORKDIR" -# Copy the built binary to the working directory depending on the profile, so we can copy it to the runtime image -RUN mv target/$(if [ $PROFILE = "dev" ]; then echo "debug"; else echo "release";fi)/iota-graphql-rpc ./ +# Install runtime dependencies and tools +RUN apt update && apt install -y libpq5 ca-certificates curl -# Production Image -FROM debian:bullseye-slim AS runtime -WORKDIR "$WORKDIR/iota" -# Both bench and release profiles copy from release dir -RUN mkdir -p /opt/iota/bin -COPY --from=builder /iota/iota-graphql-rpc /opt/iota/bin -RUN apt-get update && apt-get install -y libpq5 ca-certificates libpq-dev postgresql +COPY --from=builder /iota/iota-graphql-rpc /usr/local/bin ARG BUILD_DATE ARG GIT_REVISION diff --git a/docker/iota-graphql-rpc/build.sh b/docker/iota-graphql-rpc/build.sh index 8c87780e6ae..77f244d55a6 100755 --- a/docker/iota-graphql-rpc/build.sh +++ b/docker/iota-graphql-rpc/build.sh @@ -1,36 +1,5 @@ -#!/bin/sh +#!/bin/bash # Copyright (c) Mysten Labs, Inc. # Modifications Copyright (c) 2024 IOTA Stiftung # 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 --abbrev=12 --dirty --exclude '*')" -BUILD_DATE="$(date -u +'%Y-%m-%d')" - -# option to build using debug symbols -if [ "$1" = "--debug-symbols" ]; then - PROFILE="bench" - echo "Building with full debug info enabled ... WARNING: binary size might significantly increase" - shift -else - PROFILE="release" -fi - -echo -echo "Building iota-graphql-rpc 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" \ - --build-arg PROFILE="$PROFILE" \ - "$@" +./../utils/build-script.sh --container-name "iotaledger/iota-graphql-rpc" diff --git a/docker/iota-indexer-tidb/Dockerfile b/docker/iota-indexer-tidb/Dockerfile index 8816caee5ac..269f4a439f8 100644 --- a/docker/iota-indexer-tidb/Dockerfile +++ b/docker/iota-indexer-tidb/Dockerfile @@ -1,40 +1,61 @@ -# Build application -# -# Copy in all crates, Cargo.toml and Cargo.lock unmodified, -# and build the application. -FROM rust:bullseye AS builder +# Build image (the specific rust version can also be passed, e.g. "1.82-bookworm") +ARG RUST_IMAGE_VERSION=bookworm +FROM rust:${RUST_IMAGE_VERSION} AS builder + ARG PROFILE=release +ARG CARGO_BUILD_FEATURES +# The GIT_REVISION environment variable is used during build time inside the rust crates ARG GIT_REVISION ENV GIT_REVISION=$GIT_REVISION -WORKDIR "$WORKDIR/iota" -RUN apt-get update && apt-get install -y cmake clang +WORKDIR "/iota" -# iota-indexer needs postgres libpq5 and ca-certificates -RUN apt update && apt install -y libpq5 ca-certificates libpq-dev postgresql +# Install build dependencies, including clang and lld for faster linking +RUN apt update && apt install -y cmake clang lld -COPY Cargo.toml Cargo.lock ./ +# Configure Rust to use clang and lld as the linker +RUN mkdir -p ~/.cargo && \ + echo -e "[target.x86_64-unknown-linux-gnu]\nlinker = \"clang\"\nrustflags = [\"-C\", \"link-arg=-fuse-ld=lld\"]" > ~/.cargo/config.toml + +# Install additional dependencies +RUN apt install -y libpq5 libpq-dev ca-certificates + +# Copy in all crates, Cargo.toml, and Cargo.lock COPY consensus consensus COPY crates crates -COPY iota-execution iota-execution -COPY external-crates external-crates COPY docs docs +COPY external-crates external-crates +COPY iota-execution iota-execution +COPY Cargo.toml Cargo.lock ./ RUN cargo build --profile ${PROFILE} --bin iota-indexer --features mysql-feature --no-default-features -# Copy the built binary to the working directory depending on the profile, so we can copy it to the runtime image -RUN mv target/$(if [ $PROFILE = "dev" ]; then echo "debug"; else echo "release";fi)/iota-indexer ./ - -# Production Image -FROM debian:bullseye-slim AS runtime - -# Use jemalloc as memory allocator -RUN apt-get update && apt-get install -y libjemalloc-dev ca-certificates curl +# Copy the built binary to the working directory depending on the output folder of the profile, +# so we can copy it to the runtime image +RUN if [ -d target/release ]; then \ + TARGET_DIR="target/release"; \ +elif [ -d target/debug ]; then \ + TARGET_DIR="target/debug"; \ +else \ + echo "Error: No build directory found"; \ + exit 1; \ +fi && \ +mv $TARGET_DIR/iota-indexer ./; + +# Production image +FROM debian:bookworm-slim AS runtime + +ARG WORKDIR="/iota" +WORKDIR "$WORKDIR" + +# Install runtime dependencies and tools +RUN apt update && apt install -y libpq5 ca-certificates curl + +# Install jemalloc as the default allocator +RUN apt install -y libjemalloc-dev ENV LD_PRELOAD /usr/lib/x86_64-linux-gnu/libjemalloc.so -WORKDIR "$WORKDIR/iota" COPY --from=builder /iota/iota-indexer /usr/local/bin -RUN apt update && apt install -y libpq5 ca-certificates libpq-dev postgresql ARG BUILD_DATE ARG GIT_REVISION diff --git a/docker/iota-indexer-tidb/build.sh b/docker/iota-indexer-tidb/build.sh index fc599bfe6bf..6181a041b52 100755 --- a/docker/iota-indexer-tidb/build.sh +++ b/docker/iota-indexer-tidb/build.sh @@ -1,26 +1,5 @@ -#!/bin/sh +#!/bin/bash # Copyright (c) Mysten Labs, Inc. # Modifications Copyright (c) 2024 IOTA Stiftung # 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 --abbrev=12 --dirty --exclude '*')" -BUILD_DATE="$(date -u +'%Y-%m-%d')" - -echo -echo "Building iota-indexer-tidb 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" \ - "$@" +./../utils/build-script.sh --container-name "iotaledger/iota-indexer-tidb" diff --git a/docker/iota-indexer/Dockerfile b/docker/iota-indexer/Dockerfile index 5f7dbb450f6..528be6a7aed 100644 --- a/docker/iota-indexer/Dockerfile +++ b/docker/iota-indexer/Dockerfile @@ -1,40 +1,61 @@ -# Build application -# -# Copy in all crates, Cargo.toml and Cargo.lock unmodified, -# and build the application. -FROM rust:bullseye AS builder +# Build image (the specific rust version can also be passed, e.g. "1.82-bookworm") +ARG RUST_IMAGE_VERSION=bookworm +FROM rust:${RUST_IMAGE_VERSION} AS builder + ARG PROFILE=release +ARG CARGO_BUILD_FEATURES +# The GIT_REVISION environment variable is used during build time inside the rust crates ARG GIT_REVISION ENV GIT_REVISION=$GIT_REVISION -WORKDIR "$WORKDIR/iota" -RUN apt-get update && apt-get install -y cmake clang +WORKDIR "/iota" -# iota-indexer needs postgres libpq5 and ca-certificates -RUN apt update && apt install -y libpq5 ca-certificates libpq-dev postgresql +# Install build dependencies, including clang and lld for faster linking +RUN apt update && apt install -y cmake clang lld -COPY Cargo.toml Cargo.lock ./ +# Configure Rust to use clang and lld as the linker +RUN mkdir -p ~/.cargo && \ + echo -e "[target.x86_64-unknown-linux-gnu]\nlinker = \"clang\"\nrustflags = [\"-C\", \"link-arg=-fuse-ld=lld\"]" > ~/.cargo/config.toml + +# Install additional dependencies +RUN apt install -y libpq5 libpq-dev ca-certificates + +# Copy in all crates, Cargo.toml, and Cargo.lock COPY consensus consensus COPY crates crates -COPY iota-execution iota-execution -COPY external-crates external-crates COPY docs docs +COPY external-crates external-crates +COPY iota-execution iota-execution +COPY Cargo.toml Cargo.lock ./ + +RUN cargo build --profile ${PROFILE} --bin iota-indexer --features ${CARGO_BUILD_FEATURES:=default} + +# Copy the built binary to the working directory depending on the output folder of the profile, +# so we can copy it to the runtime image +RUN if [ -d target/release ]; then \ + TARGET_DIR="target/release"; \ +elif [ -d target/debug ]; then \ + TARGET_DIR="target/debug"; \ +else \ + echo "Error: No build directory found"; \ + exit 1; \ +fi && \ +mv $TARGET_DIR/iota-indexer ./; -RUN cargo build --profile ${PROFILE} --bin iota-indexer +# Production image +FROM debian:bookworm-slim AS runtime -# Copy the built binary to the working directory depending on the profile, so we can copy it to the runtime image -RUN mv target/$(if [ $PROFILE = "dev" ]; then echo "debug"; else echo "release";fi)/iota-indexer ./ +ARG WORKDIR="/iota" +WORKDIR "$WORKDIR" -# Production Image -FROM debian:bullseye-slim AS runtime +# Install runtime dependencies and tools +RUN apt update && apt install -y libpq5 ca-certificates curl -# Use jemalloc as memory allocator -RUN apt-get update && apt-get install -y libjemalloc-dev ca-certificates curl +# Install jemalloc as the default allocator +RUN apt install -y libjemalloc-dev ENV LD_PRELOAD /usr/lib/x86_64-linux-gnu/libjemalloc.so -WORKDIR "$WORKDIR/iota" COPY --from=builder /iota/iota-indexer /usr/local/bin -RUN apt update && apt install -y libpq5 ca-certificates libpq-dev postgresql ARG BUILD_DATE ARG GIT_REVISION diff --git a/docker/iota-indexer/build.sh b/docker/iota-indexer/build.sh index a34a1f3f36e..e264587834f 100755 --- a/docker/iota-indexer/build.sh +++ b/docker/iota-indexer/build.sh @@ -1,26 +1,5 @@ -#!/bin/sh +#!/bin/bash # Copyright (c) Mysten Labs, Inc. # Modifications Copyright (c) 2024 IOTA Stiftung # 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 --abbrev=12 --dirty --exclude '*')" -BUILD_DATE="$(date -u +'%Y-%m-%d')" - -echo -echo "Building iota-indexer 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" \ - "$@" +./../utils/build-script.sh --container-name "iotaledger/iota-indexer" diff --git a/docker/iota-node-deterministic/Dockerfile b/docker/iota-node-deterministic/Dockerfile index 69220003dd5..ec48977018e 100644 --- a/docker/iota-node-deterministic/Dockerfile +++ b/docker/iota-node-deterministic/Dockerfile @@ -37,7 +37,7 @@ COPY --from=ca-certificates . / COPY . /iota -WORKDIR iota +WORKDIR "/iota" RUN cargo fetch diff --git a/docker/iota-node/Dockerfile b/docker/iota-node/Dockerfile index 9e6f8589172..cb935142d89 100644 --- a/docker/iota-node/Dockerfile +++ b/docker/iota-node/Dockerfile @@ -1,40 +1,60 @@ -# Build application -# -# Copy in all crates, Cargo.toml and Cargo.lock unmodified, -# and build the application. -FROM rust:bullseye AS builder +# Build image (the specific rust version can also be passed, e.g. "1.82-bookworm") +ARG RUST_IMAGE_VERSION=bookworm +FROM rust:${RUST_IMAGE_VERSION} AS builder + ARG PROFILE=release +ARG CARGO_BUILD_FEATURES +# The GIT_REVISION environment variable is used during build time inside the rust crates ARG GIT_REVISION ENV GIT_REVISION=$GIT_REVISION -WORKDIR "$WORKDIR/iota" -RUN apt-get update && apt-get install -y cmake clang +WORKDIR "/iota" -COPY Cargo.toml Cargo.lock ./ +# Install build dependencies, including clang and lld for faster linking +RUN apt update && apt install -y cmake clang lld + +# Configure Rust to use clang and lld as the linker +RUN mkdir -p ~/.cargo && \ + echo -e "[target.x86_64-unknown-linux-gnu]\nlinker = \"clang\"\nrustflags = [\"-C\", \"link-arg=-fuse-ld=lld\"]" > ~/.cargo/config.toml + +# Install additional dependencies +RUN apt install -y libpq5 libpq-dev ca-certificates + +# Copy in all crates, Cargo.toml, and Cargo.lock COPY consensus consensus COPY crates crates -COPY iota-execution iota-execution -COPY external-crates external-crates COPY docs docs +COPY external-crates external-crates +COPY iota-execution iota-execution +COPY Cargo.toml Cargo.lock ./ -RUN cargo build --profile ${PROFILE} --bin iota-node +RUN cargo build --profile ${PROFILE} --bin iota-node --features ${CARGO_BUILD_FEATURES:=default} -# Copy the built binary to the working directory depending on the profile, so we can copy it to the runtime image -RUN mv target/$(if [ $PROFILE = "dev" ]; then echo "debug"; else echo "release";fi)/iota-node ./ +# Copy the built binary to the working directory depending on the output folder of the profile, +# so we can copy it to the runtime image +RUN if [ -d target/release ]; then \ + TARGET_DIR="target/release"; \ +elif [ -d target/debug ]; then \ + TARGET_DIR="target/debug"; \ +else \ + echo "Error: No build directory found"; \ + exit 1; \ +fi && \ +mv $TARGET_DIR/iota-node ./; -# Production Image -FROM debian:bullseye-slim AS runtime +# Production image +FROM debian:bookworm-slim AS runtime -# Use jemalloc as memory allocator -RUN apt-get update && apt-get install -y libjemalloc-dev ca-certificates curl -ENV LD_PRELOAD /usr/lib/x86_64-linux-gnu/libjemalloc.so +ARG WORKDIR="/iota" +WORKDIR "$WORKDIR" -WORKDIR "$WORKDIR/iota" +# Install runtime dependencies and tools +RUN apt update && apt install -y libpq5 ca-certificates curl -# Both bench and release profiles copy from release dir -COPY --from=builder /iota/iota-node /opt/iota/bin/iota-node +# Install jemalloc as the default allocator +RUN apt install -y libjemalloc-dev +ENV LD_PRELOAD /usr/lib/x86_64-linux-gnu/libjemalloc.so -# Support legacy usages of /usr/local/bin/iota-node COPY --from=builder /iota/iota-node /usr/local/bin ARG BUILD_DATE diff --git a/docker/iota-node/build.sh b/docker/iota-node/build.sh index 2ec1541ab25..a0d732ffc24 100755 --- a/docker/iota-node/build.sh +++ b/docker/iota-node/build.sh @@ -1,36 +1,5 @@ -#!/bin/sh +#!/bin/bash # Copyright (c) Mysten Labs, Inc. # Modifications Copyright (c) 2024 IOTA Stiftung # 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 --abbrev=12 --dirty --exclude '*')" -BUILD_DATE="$(date -u +'%Y-%m-%d')" - -# option to build using debug symbols -if [ "$1" = "--debug-symbols" ]; then - PROFILE="bench" - echo "Building with full debug info enabled ... WARNING: binary size might significantly increase" - shift -else - PROFILE="release" -fi - -echo -echo "Building iota-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" \ - --build-arg PROFILE="$PROFILE" \ - "$@" +./../utils/build-script.sh --container-name "iotaledger/iota-node" diff --git a/docker/iota-rosetta-devnet/Dockerfile b/docker/iota-rosetta-devnet/Dockerfile new file mode 100644 index 00000000000..ff74ef77e5c --- /dev/null +++ b/docker/iota-rosetta-devnet/Dockerfile @@ -0,0 +1,68 @@ +# Build image (the specific rust version can also be passed, e.g. "1.82-bookworm") +ARG RUST_IMAGE_VERSION=bookworm +FROM rust:${RUST_IMAGE_VERSION} AS builder + +ARG PROFILE=release +ARG CARGO_BUILD_FEATURES +# The GIT_REVISION environment variable is used during build time inside the rust crates +ARG GIT_REVISION +ENV GIT_REVISION=$GIT_REVISION + +WORKDIR "/iota" + +# Install build dependencies, including clang and lld for faster linking +RUN apt update && apt install -y cmake clang lld git + +# Configure Rust to use clang and lld as the linker +RUN mkdir -p ~/.cargo && \ + echo -e "[target.x86_64-unknown-linux-gnu]\nlinker = \"clang\"\nrustflags = [\"-C\", \"link-arg=-fuse-ld=lld\"]" > ~/.cargo/config.toml + +# Install additional dependencies +RUN apt install -y libpq5 libpq-dev ca-certificates + +# Clone the repository and checkout the devnet branch +RUN git clone https://github.com/iotaledger/iota . +RUN git checkout devnet + +RUN cargo build --profile ${PROFILE} \ + --bin iota \ + --bin iota-rosetta \ + --features ${CARGO_BUILD_FEATURES:=default} + +# Copy the built binary to the working directory depending on the output folder of the profile, +# so we can copy it to the runtime image +RUN if [ -d target/release ]; then \ + TARGET_DIR="target/release"; \ +elif [ -d target/debug ]; then \ + TARGET_DIR="target/debug"; \ +else \ + echo "Error: No build directory found"; \ + exit 1; \ +fi && \ +mv $TARGET_DIR/iota ./ && \ +mv $TARGET_DIR/iota-rosetta ./; + +# Production image +FROM debian:bookworm-slim AS runtime + +ARG WORKDIR="/iota" +WORKDIR "$WORKDIR" + +# Install runtime dependencies and tools +RUN apt update && apt install -y libpq5 ca-certificates curl + +# Install rosetta-cli +RUN curl -sSfL https://raw.githubusercontent.com/coinbase/rosetta-cli/master/scripts/install.sh | sh -s + +# Download the genesis file and create the genesis state +RUN mkdir -p devnet && curl -fL -o devnet/genesis.blob https://github.com/iotaledger/iota-genesis/raw/main/devnet/genesis.blob + +COPY --from=builder /iota/iota /usr/local/bin +COPY --from=builder /iota/iota-rosetta /usr/local/bin +COPY --from=builder /iota/crates/iota-config/data/fullnode-template.yaml /iota/devnet/fullnode.yaml +RUN /usr/local/bin/iota genesis + +ARG BUILD_DATE +ARG GIT_REVISION +LABEL build-date=$BUILD_DATE +LABEL git-revision=$GIT_REVISION diff --git a/docker/iota-rosetta-devnet/build.sh b/docker/iota-rosetta-devnet/build.sh new file mode 100755 index 00000000000..2bbe14ee607 --- /dev/null +++ b/docker/iota-rosetta-devnet/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# Copyright (c) Mysten Labs, Inc. +# Modifications Copyright (c) 2024 IOTA Stiftung +# SPDX-License-Identifier: Apache-2.0 +./../../docker/utils/build-script.sh --container-name "iotaledger/iota-rosetta-devnet" diff --git a/crates/iota-rosetta/docker/iota-rosetta-devnet/docker-compose.yaml b/docker/iota-rosetta-devnet/docker-compose.yaml similarity index 100% rename from crates/iota-rosetta/docker/iota-rosetta-devnet/docker-compose.yaml rename to docker/iota-rosetta-devnet/docker-compose.yaml diff --git a/crates/iota-rosetta/docker/iota-rosetta-devnet/remote/docker-compose.yaml b/docker/iota-rosetta-devnet/remote/docker-compose.yaml similarity index 100% rename from crates/iota-rosetta/docker/iota-rosetta-devnet/remote/docker-compose.yaml rename to docker/iota-rosetta-devnet/remote/docker-compose.yaml diff --git a/docker/iota-rosetta-local/Dockerfile b/docker/iota-rosetta-local/Dockerfile new file mode 100644 index 00000000000..78b7ccb4317 --- /dev/null +++ b/docker/iota-rosetta-local/Dockerfile @@ -0,0 +1,69 @@ +# Build image (the specific rust version can also be passed, e.g. "1.82-bookworm") +ARG RUST_IMAGE_VERSION=bookworm +FROM rust:${RUST_IMAGE_VERSION} AS builder + +ARG PROFILE=release +ARG CARGO_BUILD_FEATURES +# The GIT_REVISION environment variable is used during build time inside the rust crates +ARG GIT_REVISION +ENV GIT_REVISION=$GIT_REVISION + +WORKDIR "/iota" + +# Install build dependencies, including clang and lld for faster linking +RUN apt update && apt install -y cmake clang lld + +# Configure Rust to use clang and lld as the linker +RUN mkdir -p ~/.cargo && \ + echo -e "[target.x86_64-unknown-linux-gnu]\nlinker = \"clang\"\nrustflags = [\"-C\", \"link-arg=-fuse-ld=lld\"]" > ~/.cargo/config.toml + +# Install additional dependencies +RUN apt install -y libpq5 libpq-dev ca-certificates + +# Copy in all crates, Cargo.toml, and Cargo.lock +COPY consensus consensus +COPY crates crates +COPY docs docs +COPY external-crates external-crates +COPY iota-execution iota-execution +COPY Cargo.toml Cargo.lock ./ + +RUN cargo build --profile ${PROFILE} \ + --bin iota \ + --bin iota-rosetta \ + --features ${CARGO_BUILD_FEATURES:=default} + +# Copy the built binary to the working directory depending on the output folder of the profile, +# so we can copy it to the runtime image +RUN if [ -d target/release ]; then \ + TARGET_DIR="target/release"; \ +elif [ -d target/debug ]; then \ + TARGET_DIR="target/debug"; \ +else \ + echo "Error: No build directory found"; \ + exit 1; \ +fi && \ +mv $TARGET_DIR/iota ./ && \ +mv $TARGET_DIR/iota-rosetta ./; + +# Production image +FROM debian:bookworm-slim AS runtime + +ARG WORKDIR="/iota" +WORKDIR "$WORKDIR" + +# Install runtime dependencies and tools +RUN apt update && apt install -y libpq5 ca-certificates curl + +# Install rosetta-cli +RUN curl -sSfL https://raw.githubusercontent.com/coinbase/rosetta-cli/master/scripts/install.sh | sh -s + +COPY --from=builder /iota/iota /usr/local/bin +COPY --from=builder /iota/iota-rosetta /usr/local/bin +COPY --from=builder /iota/crates/iota-config/data/fullnode-template.yaml /iota/devnet/fullnode.yaml +RUN /usr/local/bin/iota genesis + +ARG BUILD_DATE +ARG GIT_REVISION +LABEL build-date=$BUILD_DATE +LABEL git-revision=$GIT_REVISION diff --git a/docker/iota-rosetta-local/build.sh b/docker/iota-rosetta-local/build.sh new file mode 100755 index 00000000000..fd013bdaa4d --- /dev/null +++ b/docker/iota-rosetta-local/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# Copyright (c) Mysten Labs, Inc. +# Modifications Copyright (c) 2024 IOTA Stiftung +# SPDX-License-Identifier: Apache-2.0 +./../../docker/utils/build-script.sh --container-name "iotaledger/iota-rosetta-local" diff --git a/crates/iota-rosetta/docker/iota-rosetta-local/docker-compose.yaml b/docker/iota-rosetta-local/docker-compose.yaml similarity index 100% rename from crates/iota-rosetta/docker/iota-rosetta-local/docker-compose.yaml rename to docker/iota-rosetta-local/docker-compose.yaml diff --git a/docker/iota-services/Dockerfile b/docker/iota-services/Dockerfile deleted file mode 100644 index 70a4f1a5214..00000000000 --- a/docker/iota-services/Dockerfile +++ /dev/null @@ -1,33 +0,0 @@ -FROM rust:bullseye AS chef -WORKDIR iota -ARG GIT_REVISION -ENV GIT_REVISION=$GIT_REVISION - -RUN apt-get update && apt-get install -y cmake clang libpq5 ca-certificates libpq-dev postgresql - -# Build application -FROM chef AS builder - -COPY Cargo.toml Cargo.lock ./ -COPY consensus consensus -COPY crates crates -COPY iota-execution iota-execution -COPY external-crates external-crates -COPY docs docs - -RUN mkdir /iota/bin/ -RUN find /iota/target/release/ -maxdepth 1 -type f -executable -print -RUN find /iota/target/release/ -maxdepth 1 -type f -executable -print | xargs cp -t /iota/bin/ - -# Production Image -FROM debian:bullseye-slim AS runtime -WORKDIR iota -COPY --from=builder /iota/bin/* /usr/local/bin - -RUN apt update && apt install -y libpq5 libpq-dev postgresql - -ARG BUILD_DATE -ARG GIT_REVISION -LABEL build-date=$BUILD_DATE -LABEL git-revision=$GIT_REVISION - diff --git a/docker/iota-services/build.sh b/docker/iota-services/build.sh deleted file mode 100755 index 031ebcede71..00000000000 --- a/docker/iota-services/build.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -# Copyright (c) Mysten Labs, Inc. -# Modifications Copyright (c) 2024 IOTA Stiftung -# 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 --abbrev=12 --dirty --exclude '*')" -BUILD_DATE="$(date -u +'%Y-%m-%d')" - -echo -echo "Building iota-services 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" \ - "$@" diff --git a/docker/iota-source-service/Dockerfile b/docker/iota-source-service/Dockerfile deleted file mode 100644 index f1a93befca0..00000000000 --- a/docker/iota-source-service/Dockerfile +++ /dev/null @@ -1,31 +0,0 @@ -FROM rust:bullseye AS chef -WORKDIR iota -ARG GIT_REVISION -ENV GIT_REVISION=$GIT_REVISION - -RUN apt-get update && apt-get install -y cmake clang - -FROM chef AS builder - -# Build application -COPY Cargo.toml Cargo.lock ./ -COPY consensus consensus -COPY crates crates -COPY iota-execution iota-execution -COPY external-crates external-crates -COPY docs docs - -RUN cargo build --release \ - --bin iota-source-validation-service - -# Production Image -FROM debian:bullseye-slim AS runtime -WORKDIR iota -RUN apt update && apt install -y git -COPY --from=builder /iota/target/release/iota-source-validation-service /usr/local/bin -COPY crates/iota-source-validation-service/config.toml /var/iota/ - -ARG BUILD_DATE -ARG GIT_REVISION -LABEL build-date=$BUILD_DATE -LABEL git-revision=$GIT_REVISION diff --git a/docker/iota-source-service/build.sh b/docker/iota-source-service/build.sh deleted file mode 100755 index eff4c315369..00000000000 --- a/docker/iota-source-service/build.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -# Copyright (c) Mysten Labs, Inc. -# Modifications Copyright (c) 2024 IOTA Stiftung -# 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 --abbrev=12 --dirty --exclude '*')" -BUILD_DATE="$(date -u +'%Y-%m-%d')" - -echo -echo "Building iota-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" \ - "$@" diff --git a/docker/iota-source-validation-service/Dockerfile b/docker/iota-source-validation-service/Dockerfile new file mode 100644 index 00000000000..5d65e2b0cd4 --- /dev/null +++ b/docker/iota-source-validation-service/Dockerfile @@ -0,0 +1,60 @@ +# Build image (the specific rust version can also be passed, e.g. "1.82-bookworm") +ARG RUST_IMAGE_VERSION=bookworm +FROM rust:${RUST_IMAGE_VERSION} AS builder + +ARG PROFILE=release +ARG CARGO_BUILD_FEATURES +# The GIT_REVISION environment variable is used during build time inside the rust crates +ARG GIT_REVISION +ENV GIT_REVISION=$GIT_REVISION + +WORKDIR "/iota" + +# Install build dependencies, including clang and lld for faster linking +RUN apt update && apt install -y cmake clang lld + +# Configure Rust to use clang and lld as the linker +RUN mkdir -p ~/.cargo && \ + echo -e "[target.x86_64-unknown-linux-gnu]\nlinker = \"clang\"\nrustflags = [\"-C\", \"link-arg=-fuse-ld=lld\"]" > ~/.cargo/config.toml + +# Install additional dependencies +RUN apt install -y libpq5 libpq-dev ca-certificates + +# Copy in all crates, Cargo.toml, and Cargo.lock +COPY consensus consensus +COPY crates crates +COPY docs docs +COPY external-crates external-crates +COPY iota-execution iota-execution +COPY Cargo.toml Cargo.lock ./ + +RUN cargo build --profile ${PROFILE} --bin iota-source-validation-service --features ${CARGO_BUILD_FEATURES:=default} + +# Copy the built binary to the working directory depending on the output folder of the profile, +# so we can copy it to the runtime image +RUN if [ -d target/release ]; then \ + TARGET_DIR="target/release"; \ +elif [ -d target/debug ]; then \ + TARGET_DIR="target/debug"; \ +else \ + echo "Error: No build directory found"; \ + exit 1; \ +fi && \ +mv $TARGET_DIR/iota-source-validation-service ./; + +# Production image +FROM debian:bookworm-slim AS runtime + +ARG WORKDIR="/iota" +WORKDIR "$WORKDIR" + +# Install runtime dependencies and tools +RUN apt update && apt install -y libpq5 ca-certificates curl + +COPY --from=builder /iota/iota-source-validation-service /usr/local/bin +COPY --from=builder /iota/crates/iota-source-validation-service/config.toml /var/iota/ + +ARG BUILD_DATE +ARG GIT_REVISION +LABEL build-date=$BUILD_DATE +LABEL git-revision=$GIT_REVISION diff --git a/docker/iota-source-validation-service/build.sh b/docker/iota-source-validation-service/build.sh new file mode 100755 index 00000000000..cba260c7b5d --- /dev/null +++ b/docker/iota-source-validation-service/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# Copyright (c) Mysten Labs, Inc. +# Modifications Copyright (c) 2024 IOTA Stiftung +# SPDX-License-Identifier: Apache-2.0 +./../utils/build-script.sh --container-name "iotaledger/iota-source-validation-service" diff --git a/docker/iota-tools/Dockerfile b/docker/iota-tools/Dockerfile index 0e949e467e0..145d13c5431 100644 --- a/docker/iota-tools/Dockerfile +++ b/docker/iota-tools/Dockerfile @@ -1,51 +1,86 @@ -# Build application -# -# Copy in all crates, Cargo.toml and Cargo.lock unmodified, -# and build the application. -FROM rust:bullseye AS builder +# Build image (the specific rust version can also be passed, e.g. "1.82-bookworm") +ARG RUST_IMAGE_VERSION=bookworm +FROM rust:${RUST_IMAGE_VERSION} AS builder + ARG PROFILE=release +ARG CARGO_BUILD_FEATURES +# The GIT_REVISION environment variable is used during build time inside the rust crates ARG GIT_REVISION ENV GIT_REVISION=$GIT_REVISION -WORKDIR "$WORKDIR/iota" -RUN apt-get update && apt-get install -y cmake clang libpq5 libpq-dev +WORKDIR "/iota" -COPY Cargo.toml Cargo.lock ./ +# Install build dependencies, including clang and lld for faster linking +RUN apt update && apt install -y cmake clang lld + +# Configure Rust to use clang and lld as the linker +RUN mkdir -p ~/.cargo && \ + echo -e "[target.x86_64-unknown-linux-gnu]\nlinker = \"clang\"\nrustflags = [\"-C\", \"link-arg=-fuse-ld=lld\"]" > ~/.cargo/config.toml + +# Install additional dependencies +RUN apt install -y libpq5 libpq-dev ca-certificates + +# Copy in all crates, Cargo.toml, and Cargo.lock COPY consensus consensus COPY crates crates -COPY iota-execution iota-execution -COPY external-crates external-crates COPY docs docs +COPY external-crates external-crates +COPY iota-execution iota-execution +COPY Cargo.toml Cargo.lock ./ RUN cargo build --profile ${PROFILE} \ - --bin iota-node \ - --bin stress \ - --bin iota-bridge \ - --bin bridge-indexer \ - --bin iota-bridge-cli \ - --bin iota-analytics-indexer \ - --bin iota \ - --bin iota-faucet \ - --bin iota-cluster-test \ - --bin iota-tool - -# Production Image -FROM debian:bullseye-slim AS runtime -WORKDIR "$WORKDIR/iota" - -# iota-tool needs libpq at runtime -RUN apt-get update && apt-get install -y libpq5 libpq-dev ca-certificates - -COPY --from=builder /iota/target/release/iota-node /usr/local/bin -COPY --from=builder /iota/target/release/stress /usr/local/bin -COPY --from=builder /iota/target/release/iota-bridge /usr/local/bin -COPY --from=builder /iota/target/release/bridge-indexer /usr/local/bin -COPY --from=builder /iota/target/release/iota-bridge-cli /usr/local/bin -COPY --from=builder /iota/target/release/iota-analytics-indexer /usr/local/bin -COPY --from=builder /iota/target/release/iota /usr/local/bin -COPY --from=builder /iota/target/release/iota-faucet /usr/local/bin -COPY --from=builder /iota/target/release/iota-cluster-test /usr/local/bin -COPY --from=builder /iota/target/release/iota-tool /usr/local/bin + --bin iota-node \ + --bin stress \ + --bin iota-bridge \ + --bin bridge-indexer \ + --bin iota-bridge-cli \ + --bin iota-analytics-indexer \ + --bin iota \ + --bin iota-faucet \ + --bin iota-cluster-test \ + --bin iota-tool \ + --features ${CARGO_BUILD_FEATURES:=default} + +# Copy the built binary to the working directory depending on the output folder of the profile, +# so we can copy it to the runtime image +RUN if [ -d target/release ]; then \ + TARGET_DIR="target/release"; \ +elif [ -d target/debug ]; then \ + TARGET_DIR="target/debug"; \ +else \ + echo "Error: No build directory found"; \ + exit 1; \ +fi && \ +mv $TARGET_DIR/iota-node ./ && \ +mv $TARGET_DIR/stress ./ && \ +mv $TARGET_DIR/iota-bridge ./ && \ +mv $TARGET_DIR/bridge-indexer ./ && \ +mv $TARGET_DIR/iota-bridge-cli ./ && \ +mv $TARGET_DIR/iota-analytics-indexer ./ && \ +mv $TARGET_DIR/iota ./ && \ +mv $TARGET_DIR/iota-faucet ./ && \ +mv $TARGET_DIR/iota-cluster-test ./ && \ +mv $TARGET_DIR/iota-tool ./; + +# Production image +FROM debian:bookworm-slim AS runtime + +ARG WORKDIR="/iota" +WORKDIR "$WORKDIR" + +# Install runtime dependencies and tools +RUN apt update && apt install -y libpq5 ca-certificates curl + +COPY --from=builder /iota/iota-node /usr/local/bin +COPY --from=builder /iota/stress /usr/local/bin +COPY --from=builder /iota/iota-bridge /usr/local/bin +COPY --from=builder /iota/bridge-indexer /usr/local/bin +COPY --from=builder /iota/iota-bridge-cli /usr/local/bin +COPY --from=builder /iota/iota-analytics-indexer /usr/local/bin +COPY --from=builder /iota/iota /usr/local/bin +COPY --from=builder /iota/iota-faucet /usr/local/bin +COPY --from=builder /iota/iota-cluster-test /usr/local/bin +COPY --from=builder /iota/iota-tool /usr/local/bin ARG BUILD_DATE ARG GIT_REVISION diff --git a/docker/iota-tools/build.sh b/docker/iota-tools/build.sh index fde1f0942f8..fc57fe73260 100755 --- a/docker/iota-tools/build.sh +++ b/docker/iota-tools/build.sh @@ -1,27 +1,5 @@ -#!/bin/sh +#!/bin/bash # Copyright (c) Mysten Labs, Inc. # Modifications Copyright (c) 2024 IOTA Stiftung # 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 --abbrev=12 --dirty --exclude '*')" -BUILD_DATE="$(date -u +'%Y-%m-%d')" - -echo -echo "Building iota-tools 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" \ - --target runtime \ - "$@" +./../utils/build-script.sh --container-name "iotaledger/iota-tools" diff --git a/docker/iota/Dockerfile b/docker/iota/Dockerfile index 2eb9be64f0d..a2dcf6c33ff 100644 --- a/docker/iota/Dockerfile +++ b/docker/iota/Dockerfile @@ -1,31 +1,55 @@ -# Build application -# -# Copy in all crates, Cargo.toml and Cargo.lock unmodified, -# and build the application. -FROM rust:bullseye AS builder +# Build image (the specific rust version can also be passed, e.g. "1.82-bookworm") +ARG RUST_IMAGE_VERSION=bookworm +FROM rust:${RUST_IMAGE_VERSION} AS builder + ARG PROFILE=release +ARG CARGO_BUILD_FEATURES +# The GIT_REVISION environment variable is used during build time inside the rust crates ARG GIT_REVISION ENV GIT_REVISION=$GIT_REVISION -ARG CARGO_BUILD_FEATURES + WORKDIR "/iota" -RUN apt-get update && apt-get install -y cmake clang libpq5 libpq-dev +# Install build dependencies, including clang and lld for faster linking +RUN apt update && apt install -y cmake clang lld -COPY Cargo.toml Cargo.lock ./ +# Configure Rust to use clang and lld as the linker +RUN mkdir -p ~/.cargo && \ + echo -e "[target.x86_64-unknown-linux-gnu]\nlinker = \"clang\"\nrustflags = [\"-C\", \"link-arg=-fuse-ld=lld\"]" > ~/.cargo/config.toml + +# Install additional dependencies +RUN apt install -y libpq5 libpq-dev ca-certificates + +# Copy in all crates, Cargo.toml, and Cargo.lock COPY consensus consensus COPY crates crates -COPY iota-execution iota-execution -COPY external-crates external-crates COPY docs docs +COPY external-crates external-crates +COPY iota-execution iota-execution +COPY Cargo.toml Cargo.lock ./ RUN cargo build --profile ${PROFILE} --bin iota --features ${CARGO_BUILD_FEATURES:=default} -RUN mv target/$(if [ $PROFILE = "dev" ]; then echo "debug"; else echo "release";fi)/iota ./ -# Production Image -FROM debian:bullseye-slim AS runtime +# Copy the built binary to the working directory depending on the output folder of the profile, +# so we can copy it to the runtime image +RUN if [ -d target/release ]; then \ + TARGET_DIR="target/release"; \ +elif [ -d target/debug ]; then \ + TARGET_DIR="target/debug"; \ +else \ + echo "Error: No build directory found"; \ + exit 1; \ +fi && \ +mv $TARGET_DIR/iota ./; + +# Production image +FROM debian:bookworm-slim AS runtime + +ARG WORKDIR="/iota" +WORKDIR "$WORKDIR" -# iota-tool needs libpq at runtime -RUN apt-get update && apt-get install -y libpq5 libpq-dev curl +# Install runtime dependencies and tools +RUN apt update && apt install -y libpq5 ca-certificates curl COPY --from=builder /iota/iota /usr/local/bin diff --git a/docker/iota/build.sh b/docker/iota/build.sh index 1aac6f69769..fdd4eceb480 100755 --- a/docker/iota/build.sh +++ b/docker/iota/build.sh @@ -1,28 +1,5 @@ -#!/bin/sh +#!/bin/bash # Copyright (c) Mysten Labs, Inc. # Modifications Copyright (c) 2024 IOTA Stiftung # 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 --abbrev=12 --dirty --exclude '*')" -BUILD_DATE="$(date -u +'%Y-%m-%d')" - -echo -echo "Building iota 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" \ - --build-arg CARGO_BUILD_FEATURES="$CARGO_BUILD_FEATURES" \ - --target runtime \ - "$@" +./../utils/build-script.sh --container-name "iotaledger/iota" diff --git a/docker/pg-services-local/docker-compose.yaml b/docker/pg-services-local/docker-compose.yaml index fe8e31ab08a..e5948b54dad 100644 --- a/docker/pg-services-local/docker-compose.yaml +++ b/docker/pg-services-local/docker-compose.yaml @@ -134,7 +134,7 @@ services: - RUST_BACKTRACE=1 - RUST_LOG=info command: - - /opt/iota/bin/iota-graphql-rpc + - /usr/local/bin/iota-graphql-rpc - start-server - --db-url=postgres://postgres:postgrespw@postgres:5432/iota_indexer - --host=0.0.0.0 diff --git a/docker/stress/Dockerfile b/docker/stress/Dockerfile index d70f250ccbe..376508e30fb 100644 --- a/docker/stress/Dockerfile +++ b/docker/stress/Dockerfile @@ -4,7 +4,7 @@ FROM iotaledger/iota-tools:$IOTA_TOOLS_IMAGE_TAG ARG IOTA_TOOLS_IMAGE_TAG -RUN apt-get update && apt-get -y --no-install-recommends install wget=1.21-1+deb11u1 \ +RUN apt update && apt -y --no-install-recommends install wget=1.21-1+deb11u1 \ iputils-ping netcat procps bind9-host bind9-dnsutils curl iproute2 git ca-certificates awscli # stress needs access to examples/move/basics diff --git a/docker/utils/build-script.sh b/docker/utils/build-script.sh new file mode 100755 index 00000000000..ef526167bdd --- /dev/null +++ b/docker/utils/build-script.sh @@ -0,0 +1,80 @@ +#!/bin/bash +# Copyright (c) Mysten Labs, Inc. +# Modifications Copyright (c) 2024 IOTA Stiftung +# SPDX-License-Identifier: Apache-2.0 + +# Get the directory where build-script.sh is located +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# Source common.sh from the utils directory +source "$SCRIPT_DIR/common.sh" + +# fast fail. +set -e + +# Get the current working directory where the script was called +CURRENT_WORKING_DIR="$(pwd)" + +REPO_ROOT="$(git rev-parse --show-toplevel)" +DOCKERFILE="$CURRENT_WORKING_DIR/Dockerfile" +GIT_REVISION="$(git describe --always --abbrev=12 --dirty --exclude '*')" +BUILD_DATE="$(date -u +'%Y-%m-%d')" +PROFILE="release" +CONTAINER_NAME="" + +# Parse command line arguments +# Usage: +# --container-name - the name of the container +while [ "$#" -gt 0 ]; do + case "$1" in + --container-name=*) + CONTAINER_NAME="${1#*=}" + shift + ;; + --container-name) + CONTAINER_NAME="$2" + shift 2 + ;; + *) + print_error "Unknown argument: $1" + print_step "Usage: $0 --container-name " + exit 1 + ;; + esac +done + +# check if the container name is set +if [ -z "$CONTAINER_NAME" ]; then + print_error "Container name is not set" + print_step "Usage: $0 --container-name " + exit 1 +fi + +print_step "Parse the rust toolchain version from 'rust-toolchain.toml'..." +RUST_VERSION=$(grep -oE 'channel = "[^"]+' ${REPO_ROOT}/rust-toolchain.toml | sed 's/channel = "//') +if [ -z "$RUST_VERSION" ]; then + print_error "Failed to parse the rust toolchain version" + exit 1 +fi +RUST_IMAGE_VERSION=${RUST_VERSION}-bookworm + +echo +echo "Building \"$CONTAINER_NAME\" docker image" +echo "Dockerfile: $DOCKERFILE" +echo "docker context: $REPO_ROOT" +echo "profile: $PROFILE" +echo "builder rust image version: $RUST_IMAGE_VERSION" +echo "cargo build features: $CARGO_BUILD_FEATURES" +echo "build date: $BUILD_DATE" +echo "git revision: $GIT_REVISION" +echo + +docker build -f "$DOCKERFILE" "$REPO_ROOT" \ + -t ${CONTAINER_NAME} \ + --build-arg RUST_IMAGE_VERSION="${RUST_IMAGE_VERSION}" \ + --build-arg PROFILE="$PROFILE" \ + --build-arg CARGO_BUILD_FEATURES="$CARGO_BUILD_FEATURES" \ + --build-arg BUILD_DATE="$BUILD_DATE" \ + --build-arg GIT_REVISION="$GIT_REVISION" \ + --target runtime \ + "$@" diff --git a/docker/utils/common.sh b/docker/utils/common.sh new file mode 100755 index 00000000000..dea59dcc000 --- /dev/null +++ b/docker/utils/common.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Copyright (c) 2024 IOTA Stiftung +# SPDX-License-Identifier: Apache-2.0 + +function print_step { + echo -e "\e[32m$1\e[0m" +} + +function print_error { + echo -e "\e[31m$1\e[0m" +} + +function check_error { + if [ $? -ne 0 ]; then + print_error "$1" + exit 1 + fi +}