Skip to content

Commit a649c36

Browse files
committed
Copy GCC from official image
1 parent 50c7046 commit a649c36

File tree

4 files changed

+133
-43
lines changed

4 files changed

+133
-43
lines changed

docker/debian/Dockerfile

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
# ====================== BASE IMAGE ======================
1+
# Define the source image from which we will copy GCC. This is needed because
2+
# the `COPY --from XXX` command used in a stage below does not allow `XXX` to
3+
# contain dynamic values supplied via an argument.
24
ARG DEBIAN_VERSION=bookworm
5+
ARG GCC_VERSION=12
6+
FROM gcc:${GCC_VERSION}-${DEBIAN_VERSION} AS gcc-src
7+
8+
# ====================== BASE IMAGE ======================
39
FROM debian:${DEBIAN_VERSION} AS base
410

511
# Associate the image with the repository.
@@ -9,30 +15,30 @@ LABEL org.opencontainers.image.source=https://github.com/${GITHUB_REPO}
915
# Ensure any packages installed directly or indirectly via dpkg do not require
1016
# manual interaction.
1117
ARG DEBIAN_FRONTEND=noninteractive
12-
RUN apt update && apt upgrade -y && \
13-
ln -fs /usr/share/zoneinfo/America/Los_Angeles /etc/localtime && \
14-
apt install tzdata && \
18+
RUN apt update && apt upgrade -y
19+
RUN set -ex ;\
20+
ln -fs /usr/share/zoneinfo/America/Los_Angeles /etc/localtime ;\
21+
apt install tzdata ;\
1522
dpkg-reconfigure --frontend noninteractive tzdata
1623

1724
# Install tools that are shared by all stages.
1825
RUN apt install -y build-essential \
19-
ca-certificates \
20-
cmake \
21-
curl \
22-
git \
23-
gpg \
24-
libssl-dev \
25-
libprotobuf-dev \
26-
ninja-build \
27-
protobuf-compiler
26+
ca-certificates \
27+
cmake \
28+
curl \
29+
git \
30+
gpg \
31+
libssl-dev \
32+
libprotobuf-dev \
33+
ninja-build \
34+
protobuf-compiler
2835

2936
# Install Conan.
3037
RUN apt install -y pipx
3138
RUN PIPX_HOME=/opt/pipx \
32-
PIPX_BIN_DIR=/usr/bin \
33-
PIPX_MAN_DIR=/usr/share/man \
34-
pipx install conan
35-
RUN apt purge -y pipx && apt autoremove -y
39+
PIPX_BIN_DIR=/usr/bin \
40+
PIPX_MAN_DIR=/usr/share/man \
41+
pipx install conan
3642

3743
# Create the user to switch to, once all packages have been installed.
3844
ARG NONROOT_USER=ci
@@ -41,11 +47,28 @@ RUN useradd -ms /bin/bash ${NONROOT_USER}
4147
# ====================== GCC IMAGE ======================
4248
FROM base AS gcc
4349

44-
# Install GCC.
45-
ARG GCC_VERSION=12
46-
RUN apt install -y gcc-${GCC_VERSION} g++-${GCC_VERSION}
47-
ENV CC=/usr/bin/gcc-${GCC_VERSION}
48-
ENV CXX=/usr/bin/gcc-${GCC_VERSION}
50+
# Copy GCC from the source image, make the package manager aware of its
51+
# existence, and create the necessary symlinks.
52+
COPY --from=gcc-src /usr/local/ /usr/local/
53+
COPY --from=gcc-src /etc/ld.so.conf.d/*.conf /etc/ld.so.conf.d/
54+
RUN set -ex ;\
55+
ldconfig -v ;\
56+
dpkg-divert --divert /usr/bin/gcc.orig --rename /usr/bin/gcc ;\
57+
dpkg-divert --divert /usr/bin/g++.orig --rename /usr/bin/g++ ;\
58+
dpkg-divert --divert /usr/bin/gfortran.orig --rename /usr/bin/gfortran ;\
59+
update-alternatives --install /usr/bin/cc cc /usr/local/bin/gcc 999 ;\
60+
update-alternatives --install \
61+
/usr/bin/gcc gcc /usr/local/bin/gcc 100 \
62+
--slave /usr/bin/g++ g++ /usr/local/bin/g++ \
63+
--slave /usr/bin/gcc-ar gcc-ar /usr/local/bin/gcc-ar \
64+
--slave /usr/bin/gcc-nm gcc-nm /usr/local/bin/gcc-nm \
65+
--slave /usr/bin/gcc-ranlib gcc-ranlib /usr/local/bin/gcc-ranlib \
66+
--slave /usr/bin/gcov gcov /usr/local/bin/gcov \
67+
--slave /usr/bin/gcov-tool gcov-tool /usr/local/bin/gcov-tool \
68+
--slave /usr/bin/gcov-dump gcov-dump /usr/local/bin/gcov-dump \
69+
--slave /usr/bin/lto-dump lto-dump /usr/local/bin/lto-dump ;\
70+
update-alternatives --auto cc ;\
71+
update-alternatives --auto gcc
4972

5073
# Clean up unnecessary files to reduce image size.
5174
RUN rm -rf /var/lib/apt/lists/* && apt autoremove -y && apt clean
@@ -54,6 +77,9 @@ RUN rm -rf /var/lib/apt/lists/* && apt autoremove -y && apt clean
5477
USER ${NONROOT_USER}
5578
WORKDIR /home/${NONROOT_USER}
5679

80+
# Create a default Conan profile.
81+
RUN conan profile detect
82+
5783
# ===================== CLANG IMAGE =====================
5884
FROM base AS clang
5985

@@ -78,3 +104,6 @@ RUN rm -rf /var/lib/apt/lists/* && apt autoremove -y && apt clean
78104
# Switch to the non-root user.
79105
USER ${NONROOT_USER}
80106
WORKDIR /home/${NONROOT_USER}
107+
108+
# Create a default Conan profile.
109+
RUN conan profile detect

docker/debian/README.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Debian: A Docker image used to build and test rippled
22

3-
The code in this repository creates a locked-down Debuan image for building and
3+
The code in this repository creates a locked-down Debian image for building and
44
testing rippled in the GitHub CI pipelines.
55

66
Although the images will be built by a CI pipeline in this repository, if
@@ -39,7 +39,7 @@ registry.
3939
```shell
4040
DEBIAN_VERSION=bookworm
4141
GCC_VERSION=12
42-
DOCKER_IMAGE=xrplf/ci/${DEBIAN_VERSION}:gcc${GCC_VERSION}
42+
DOCKER_IMAGE=xrplf/ci/debian-${DEBIAN_VERSION}:gcc${GCC_VERSION}
4343

4444
DOCKER_BUILDKIT=1 docker build . \
4545
--target gcc \
@@ -60,7 +60,7 @@ registry.
6060
```shell
6161
DEBIAN_VERSION=bookworm
6262
CLANG_VERSION=16
63-
DOCKER_IMAGE=xrplf/ci/${DEBIAN_VERSION}:clang${CLANG_VERSION}
63+
DOCKER_IMAGE=xrplf/ci/debian-${DEBIAN_VERSION}:clang${CLANG_VERSION}
6464

6565
DOCKER_BUILDKIT=1 docker build . \
6666
--target clang \
@@ -72,3 +72,33 @@ DOCKER_BUILDKIT=1 docker build . \
7272

7373
docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}
7474
```
75+
76+
#### Running the Docker image
77+
78+
If you want to run the image locally using a cloned `rippled` repository, you
79+
can do so with the following command:
80+
81+
```shell
82+
CODEBASE=<path to the rippled repository>
83+
docker run --rm -it -v ${CODEBASE}:/rippled ${DOCKER_REGISTRY}/${DOCKER_IMAGE}
84+
```
85+
86+
Once inside the container you can run the following commands to build `rippled`:
87+
88+
```shell
89+
BUILD_TYPE=Debug
90+
cd /rippled
91+
# Remove any existing data from previous builds on the host machine.
92+
rm -rf CMakeCache.txt CMakeFiles build || true
93+
# Install dependencies via Conan.
94+
conan install . --build missing --settings build_type=${BUILD_TYPE} \
95+
-o xrpld=True -o tests=True -o unity=True
96+
# Configure the build with CMake.
97+
cd build
98+
cmake -DCMAKE_TOOLCHAIN_FILE:FILEPATH=build/generators/conan_toolchain.cmake \
99+
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} ..
100+
# Build rippled.
101+
cmake --build . -j $(nproc)
102+
# Run the tests.
103+
./rippled --unittest --unittest-jobs $(nproc)
104+
```

docker/ubuntu/Dockerfile

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,30 @@ LABEL org.opencontainers.image.source=https://github.com/${GITHUB_REPO}
99
# Ensure any packages installed directly or indirectly via dpkg do not require
1010
# manual interaction.
1111
ARG DEBIAN_FRONTEND=noninteractive
12-
RUN apt update && apt upgrade -y && \
13-
ln -fs /usr/share/zoneinfo/America/Los_Angeles /etc/localtime && \
14-
apt install tzdata && \
12+
RUN apt update && apt upgrade -y
13+
RUN set -ex ;\
14+
ln -fs /usr/share/zoneinfo/America/Los_Angeles /etc/localtime ;\
15+
apt install tzdata ;\
1516
dpkg-reconfigure --frontend noninteractive tzdata
1617

1718
# Install tools that are shared by all stages.
1819
RUN apt install -y build-essential \
19-
ca-certificates \
20-
cmake \
21-
curl \
22-
git \
23-
gpg \
24-
libssl-dev \
25-
libprotobuf-dev \
26-
ninja-build \
27-
protobuf-compiler
20+
ca-certificates \
21+
cmake \
22+
curl \
23+
git \
24+
gpg \
25+
libssl-dev \
26+
libprotobuf-dev \
27+
ninja-build \
28+
protobuf-compiler
2829

2930
# Install Conan.
3031
RUN apt install -y pipx
3132
RUN PIPX_HOME=/opt/pipx \
32-
PIPX_BIN_DIR=/usr/bin \
33-
PIPX_MAN_DIR=/usr/share/man \
34-
pipx install conan
35-
RUN apt purge -y pipx && apt autoremove -y
33+
PIPX_BIN_DIR=/usr/bin \
34+
PIPX_MAN_DIR=/usr/share/man \
35+
pipx install conan
3636

3737
# Create the user to switch to, once all packages have been installed.
3838
ARG NONROOT_USER=ci

docker/ubuntu/README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ registry.
3939
```shell
4040
UBUNTU_VERSION=noble
4141
GCC_VERSION=14
42-
DOCKER_IMAGE=xrplf/ci/${UBUNTU_VERSION}:gcc${GCC_VERSION}
42+
DOCKER_IMAGE=xrplf/ci/ubuntu-${UBUNTU_VERSION}:gcc${GCC_VERSION}
4343

4444
DOCKER_BUILDKIT=1 docker build . \
4545
--target gcc \
@@ -60,7 +60,7 @@ registry.
6060
```shell
6161
UBUNTU_VERSION=noble
6262
CLANG_VERSION=18
63-
DOCKER_IMAGE=xrplf/ci/${UBUNTU_VERSION}:clang${CLANG_VERSION}
63+
DOCKER_IMAGE=xrplf/ci/ubuntu-${UBUNTU_VERSION}:clang${CLANG_VERSION}
6464

6565
DOCKER_BUILDKIT=1 docker build . \
6666
--target clang \
@@ -72,3 +72,34 @@ DOCKER_BUILDKIT=1 docker build . \
7272

7373
docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}
7474
```
75+
76+
#### Running the Docker image
77+
78+
If you want to run the image locally using a cloned `rippled` repository, you
79+
can do so with the following command:
80+
81+
```shell
82+
CODEBASE=<path to the rippled repository>
83+
docker run --rm -it -v ${CODEBASE}:/rippled ${DOCKER_REGISTRY}/${DOCKER_IMAGE}
84+
```
85+
86+
Once inside the container you can run the following commands to build `rippled`:
87+
88+
```shell
89+
BUILD_TYPE=Debug
90+
cd /rippled
91+
# Remove any existing data from previous builds on the host machine.
92+
rm -rf CMakeCache.txt CMakeFiles build || true
93+
# Install dependencies via Conan.
94+
conan install . --build missing --settings build_type=${BUILD_TYPE} \
95+
-o xrpld=True -o tests=True -o unity=True
96+
# Configure the build with CMake.
97+
cd build
98+
cmake -DCMAKE_TOOLCHAIN_FILE:FILEPATH=build/generators/conan_toolchain.cmake \
99+
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} ..
100+
# Build and test rippled. Setting the parallelism too high, e.g. to $(nproc),
101+
# can result in an error like "gmake[2]: ...... Killed".
102+
PARALLELISM=4
103+
cmake --build . -j ${PARALLELISM}
104+
./rippled --unittest --unittest-jobs ${PARALLELISM}
105+
```

0 commit comments

Comments
 (0)