Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the size of the clp container images. #288

Merged
merged 7 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
FROM ghcr.io/y-scope/clp/clp-core-dependencies-x86-ubuntu-focal:main
FROM ubuntu:focal AS BASE

# Install runtime dependencies
# TODO: Investigate why libssl-dev is a hidden dependency of clp-s
RUN apt-get update \
&& apt-get install -y \
libmariadb-dev \
libssl-dev

# Remove cached files
RUN apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

WORKDIR /clp

Expand All @@ -8,4 +19,10 @@ ADD ./clp-s ./
ADD ./glt ./
ADD ./make-dictionaries-readable ./

# Flatten the image
FROM scratch
COPY --from=BASE / /

WORKDIR /clp

CMD bash
17 changes: 17 additions & 0 deletions components/core/tools/docker-images/clp-core-ubuntu-focal/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

# Exit on any error
set -e

# Error on undefined variable
set -u

cUsage="Usage: ${BASH_SOURCE[0]} <clp-core-build-dir>"
if [ "$#" -lt 1 ]; then
echo "${cUsage}"
exit
fi
build_dir="$1"

script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
docker build -t clp-core-x86-ubuntu-focal:dev "${build_dir}" --file "${script_dir}/Dockerfile"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM centos:centos7.4.1708
FROM centos:centos7.4.1708 AS BASE

WORKDIR /root

Expand All @@ -10,9 +10,6 @@ ADD ./tools/scripts/lib_install ./tools/scripts/lib_install

RUN ./tools/scripts/lib_install/centos7.4/install-all.sh

# Set PKG_CONFIG_PATH since CentOS doesn't look in /usr/local by default
ENV PKG_CONFIG_PATH /usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig

# Enable gcc 10 in login shells and non-interactive non-login shells
RUN ln -s /opt/rh/devtoolset-10/enable /etc/profile.d/devtoolset.sh

Expand All @@ -21,9 +18,16 @@ RUN ln -s /opt/rh/devtoolset-10/enable /etc/profile.d/devtoolset.sh
# cannot be forced to use a bash shell that loads .bashrc
RUN cp ./tools/docker-images/clp-env-base-centos7.4/setup-scripts/git /usr/bin/git

# Remove cached files
RUN yum clean all \
&& rm -rf /tmp/* /var/tmp/*

# Flatten the image
FROM scratch
COPY --from=BASE / /

# Set PKG_CONFIG_PATH since CentOS doesn't look in /usr/local by default
ENV PKG_CONFIG_PATH /usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig

# Load .bashrc for non-interactive bash shells
ENV BASH_ENV=/etc/bashrc

# Reset the working directory so that it's accessible by any user who runs the
# container
WORKDIR /
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
FROM ubuntu:focal
FROM ubuntu:focal AS BASE

WORKDIR /root

RUN mkdir -p ./tools/scripts/lib_install
ADD ./tools/scripts/lib_install ./tools/scripts/lib_install

RUN ./tools/scripts/lib_install/ubuntu-focal/install-all.sh
# NOTE: We can't use the `install-all.sh` script since we need to configure the compiler in between
# `install-prebuilt-packages.sh` and `install-packages-from-source.sh`.
RUN ./tools/scripts/lib_install/ubuntu-focal/install-prebuilt-packages.sh

# Set the compiler to gcc-10
# Set gcc/g++ 10 as the default compiler
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually feel the original way we wrote it is more readable. is there a reason why you turn it into a one line command?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to reduce the number of generated layers since each RUN command generates a separate layer; but I guess we can keep them separate since we're flattening the image in the end.

RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10
RUN update-alternatives --set gcc /usr/bin/gcc-10
RUN update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-10 20
RUN update-alternatives --set cc /usr/bin/gcc-10
RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10
RUN update-alternatives --set g++ /usr/bin/g++-10
RUN update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-10 20
RUN update-alternatives --set c++ /usr/bin/g++-10

RUN ./tools/scripts/lib_install/ubuntu-focal/install-packages-from-source.sh

# Remove cached files
RUN apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Reset the working directory so that it's accessible by any user who runs the
# container
WORKDIR /
# Flatten the image
FROM scratch
COPY --from=BASE / /
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:jammy
FROM ubuntu:jammy AS BASE

WORKDIR /root

Expand All @@ -7,6 +7,10 @@ ADD ./tools/scripts/lib_install ./tools/scripts/lib_install

RUN ./tools/scripts/lib_install/ubuntu-jammy/install-all.sh

# Reset the working directory so that it's accessible by any user who runs the
# container
WORKDIR /
# Remove cached files
RUN apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Flatten the image
FROM scratch
COPY --from=BASE / /
20 changes: 11 additions & 9 deletions components/core/tools/scripts/lib_install/centos7.4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ These same steps are used by our Docker containers.

# Installing dependencies

Before you run any commands below, you should review the scripts to ensure they
will not install any dependencies you don't expect.
> [!WARNING]
> Before you run any commands below, you should review the scripts to ensure they will not install
> any dependencies or apply any configurations that you don't expect.

* Install all dependencies:
* ⚠ NOTE: The packages built from source (`install-packages-from-source.sh`)
are installed without using a packager. So if you ever need to uninstall
them, you will need to do so manually.
To install all dependencies, run:

```bash
./install-all.sh
```
> [!NOTE]
> The packages built from source (`install-packages-from-source.sh`) are installed without using a
> packager. So if you ever need to uninstall them, you will need to do so manually.

```bash
./install-all.sh
```

# Setup dependencies

Expand Down
31 changes: 25 additions & 6 deletions components/core/tools/scripts/lib_install/ubuntu-focal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,33 @@ These same steps are used by our Docker containers.

# Installing dependencies

Before you run any commands below, you should review the scripts to ensure they
will not install any dependencies you don't expect.
> [!WARNING]
> Before you run any commands below, you should review the scripts to ensure they will not install
> any dependencies or apply any configurations that you don't expect.

* Install all dependencies:
To install all dependencies, run:

```bash
./install-all.sh
```
```bash
./install-all.sh
```

# Setup dependencies

Enable GCC 10 as the default compiler by running:

```bash
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10
update-alternatives --set gcc /usr/bin/gcc-10

update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-10 20
update-alternatives --set cc /usr/bin/gcc-10

update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10
update-alternatives --set g++ /usr/bin/g++-10

update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-10 20
update-alternatives --set c++ /usr/bin/g++-10
```

# Building CLP

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ set -e
set -u

apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
ca-certificates \
checkinstall \
cmake \
curl \
build-essential \
git \
g++-10 \
gcc-10 \
Expand All @@ -21,9 +20,9 @@ DEBIAN_FRONTEND=noninteractive apt-get install -y \
libboost-program-options-dev \
libmariadb-dev \
libssl-dev \
make \
openjdk-11-jdk \
pkg-config \
python3 \
python3-pip \
rsync \
zlib1g-dev
13 changes: 7 additions & 6 deletions components/core/tools/scripts/lib_install/ubuntu-jammy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ These same steps are used by our Docker containers.

# Installing dependencies

Before you run any commands below, you should review the scripts to ensure they
will not install any dependencies you don't expect.
> [!WARNING]
> Before you run any commands below, you should review the scripts to ensure they will not install
> any dependencies or apply any configurations that you don't expect.

* Install all dependencies:
To install all dependencies, run:

```bash
./install-all.sh
```
```bash
./install-all.sh
```

# Building CLP

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -e
set -u

apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
ca-certificates \
checkinstall \
cmake \
Expand All @@ -23,5 +23,4 @@ DEBIAN_FRONTEND=noninteractive apt-get install -y \
pkg-config \
python3 \
python3-pip \
rsync \
software-properties-common
12 changes: 8 additions & 4 deletions tools/docker-images/clp-execution-base-focal/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:focal
FROM ubuntu:focal AS BASE

WORKDIR /root

Expand All @@ -7,6 +7,10 @@ ADD ./tools/docker-images/clp-execution-base-focal/setup-scripts ./tools/docker-

RUN ./tools/docker-images/clp-execution-base-focal/setup-scripts/install-prebuilt-packages.sh

# Reset the working directory so that it's accessible by any user who runs the
# container
WORKDIR /
# Remove cached files
RUN apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Flatten the image
FROM scratch
COPY --from=BASE / /
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ set -e
set -u

apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
checkinstall \
curl \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add libssl-dev here unless we plan to remove the dependency in the short term?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

libmariadb-dev \
libssl-dev \
python3 \
rsync \
zstd
12 changes: 8 additions & 4 deletions tools/docker-images/clp-execution-base-jammy/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:jammy
FROM ubuntu:jammy AS BASE

WORKDIR /root

Expand All @@ -7,6 +7,10 @@ ADD ./tools/docker-images/clp-execution-base-jammy/setup-scripts ./tools/docker-

RUN ./tools/docker-images/clp-execution-base-jammy/setup-scripts/install-prebuilt-packages.sh

# Reset the working directory so that it's accessible by any user who runs the
# container
WORKDIR /
# Remove cached files
RUN apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Flatten the image
FROM scratch
COPY --from=BASE / /
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ set -e
set -u

apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment for libssl-dev

checkinstall \
curl \
libmariadb-dev \
libssl-dev \
python3 \
rsync \
zstd
Loading