Skip to content

Commit

Permalink
feat(docker): cleanup docker files (#4044)
Browse files Browse the repository at this point in the history
* feat(docker): use one common build script for most containers

* feat(docker): cleanup and unify docker files (clang, target, flags)

* remove(docker): remove unused `iota-services` docker files

* rename(docker): rename `iota-source-service` to `iota-source-validation-service`

* feat(workflow): add toolchain version to docker build workflow

* chore(docker): move rosetta docker files to root docker folder

* fix(docker): small cleanups and fixes

---------

Co-authored-by: Bing-Yang <51323441+bingyanglin@users.noreply.github.com>
  • Loading branch information
muXxer and bingyanglin authored Dec 4, 2024
1 parent 82c06b3 commit cac0f0b
Showing 38 changed files with 697 additions and 586 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/release_docker.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion crates/iota-rosetta/README.md
Original file line number Diff line number Diff line change
@@ -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 <iota project directory>/crate/iota-rosetta/docker/iota-rosetta-local
cd <iota project directory>/docker/iota-rosetta-local
```

#### 2. Build the image
33 changes: 0 additions & 33 deletions crates/iota-rosetta/docker/iota-rosetta-devnet/Dockerfile

This file was deleted.

27 changes: 0 additions & 27 deletions crates/iota-rosetta/docker/iota-rosetta-devnet/build.sh

This file was deleted.

35 changes: 0 additions & 35 deletions crates/iota-rosetta/docker/iota-rosetta-local/Dockerfile

This file was deleted.

27 changes: 0 additions & 27 deletions crates/iota-rosetta/docker/iota-rosetta-local/build.sh

This file was deleted.

63 changes: 42 additions & 21 deletions docker/iota-bridge-indexer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
25 changes: 2 additions & 23 deletions docker/iota-bridge-indexer/build.sh
Original file line number Diff line number Diff line change
@@ -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"
Loading

0 comments on commit cac0f0b

Please sign in to comment.