Skip to content

Commit 13de17a

Browse files
committed
Re-enable entrypoint, add GCC and Clang version checks, fix RHEL GCC
1 parent a494f1e commit 13de17a

File tree

3 files changed

+96
-17
lines changed

3 files changed

+96
-17
lines changed

docker/debian/Dockerfile

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ FROM gcc:${GCC_VERSION}-${DEBIAN_VERSION} AS gcc-src
1414
FROM debian:${DEBIAN_VERSION} AS base
1515

1616
# Use Bash as the default shell for RUN commands, using the options
17-
# `set -o errexit -o pipefail`.
17+
# `set -o errexit -o pipefail`, and as the entrypoint.
1818
SHELL ["/bin/bash", "-e", "-o", "pipefail", "-c"]
19+
ENTRYPOINT ["/bin/bash"]
1920

2021
# Ensure any packages installed directly or indirectly via dpkg do not require
2122
# manual interaction.
@@ -95,6 +96,25 @@ EOF
9596
ENV CC=/usr/bin/gcc
9697
ENV CXX=/usr/bin/g++
9798

99+
# Check that the installed GCC version matches the expected version. We must
100+
# repeat the GCC_VERSION argument here, as it is not inherited from the source
101+
# image.
102+
ARG GCC_VERSION
103+
RUN <<EOF
104+
CC_VER=$(${CC} -dumpversion)
105+
CC_VER=${CC_VER%%.*}
106+
if [[ "${CC_VER}" != "${GCC_VERSION}" ]]; then
107+
echo "ERROR: 'gcc -dumpversion' gives '${CC_VER}', which does not match expected version '${GCC_VERSION}'."
108+
exit 1
109+
fi
110+
CXX_VER=$(${CXX} -dumpversion)
111+
CXX_VER=${CXX_VER%%.*}
112+
if [[ "${CXX_VER}" != "${GCC_VERSION}" ]]; then
113+
echo "ERROR: g++ -dumpversion gives '${CXX_VER}', which does not match expected version '${GCC_VERSION}'."
114+
exit 1
115+
fi
116+
EOF
117+
98118
# Switch to the non-root user.
99119
USER ${NONROOT_USER}
100120
WORKDIR /home/${NONROOT_USER}
@@ -129,7 +149,7 @@ FROM base AS clang
129149

130150
# Install Clang. Use the LLVM apt repository to access the latest versions. We
131151
# must repeat the DEBIAN_VERSION argument here, as it is not inherited from the
132-
# base image.
152+
# base or source images.
133153
ARG DEBIAN_VERSION
134154
ARG CLANG_VERSION
135155
RUN <<EOF
@@ -145,6 +165,22 @@ EOF
145165
ENV CC=/usr/bin/clang-${CLANG_VERSION}
146166
ENV CXX=/usr/bin/clang++-${CLANG_VERSION}
147167

168+
# Check that the installed Clang version matches the expected version.
169+
RUN <<EOF
170+
CC_VER=$(${CC} -dumpversion)
171+
CC_VER=${CC_VER%%.*}
172+
if [[ "${CC_VER}" != "${CLANG_VERSION}" ]]; then
173+
echo "ERROR: 'clang -dumpversion' gives '${CC_VER}', which does not match expected version '${GCC_VERSION}'."
174+
exit 1
175+
fi
176+
CXX_VER=$(${CXX} -dumpversion)
177+
CXX_VER=${CXX_VER%%.*}
178+
if [[ "${CXX_VER}" != "${CLANG_VERSION}" ]]; then
179+
echo "ERROR: clang++ -dumpversion gives '${CXX_VER}', which does not match expected version '${GCC_VERSION}'."
180+
exit 1
181+
fi
182+
EOF
183+
148184
# Switch to the non-root user.
149185
USER ${NONROOT_USER}
150186
WORKDIR /home/${NONROOT_USER}
@@ -166,11 +202,11 @@ cat >>~/.conan2/profiles/default <<EOT
166202
[conf]
167203
tools.build:compiler_executables={"c": "${CC}", "cpp": "${CXX}"}
168204
EOT
169-
if [[ $(clang-${CLANG_VERSION} --version | head -1 | grep -Po 'version \K[0-9]{2}') -ge 20 ]]; then
205+
if [[ ${CC_VER} -ge 20 ]]; then
170206
cat >>~/.conan2/profiles/default <<EOT
171207
tools.build:cxxflags=['-Wno-missing-template-arg-list-after-template-kw', '-Wno-deprecated-declarations']
172208
EOT
173-
elif [[ $(clang-${CLANG_VERSION} --version | head -1 | grep -Po 'version \K[0-9]{2}') -eq 19 ]]; then
209+
elif [[ ${CC_VER} -eq 19 ]]; then
174210
cat >>~/.conan2/profiles/default <<EOT
175211
tools.build:cxxflags=['-Wno-missing-template-arg-list-after-template-kw']
176212
EOT

docker/rhel/Dockerfile

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# ====================== BASE IMAGE ======================
2+
ARG RHEL_VERSION
23
FROM registry.redhat.io/ubi${RHEL_VERSION%.*}/s2i-base:${RHEL_VERSION} AS base
34

45
# Use Bash as the default shell for RUN commands, using the options
5-
# `set -o errexit -o pipefail`.
6+
# `set -o errexit -o pipefail`, and as the entrypoint.
67
SHELL ["/bin/bash", "-e", "-o", "pipefail", "-c"]
8+
ENTRYPOINT ["/bin/bash"]
79

810
# Update the packages installed on the system.
911
RUN dnf update-minimal -y --security --sec-severity=Important --sec-severity=Critical
@@ -41,15 +43,34 @@ RUN useradd -ms /bin/bash ${NONROOT_USER}
4143
# ====================== GCC IMAGE ======================
4244
FROM base AS gcc
4345

44-
# Install GCC.
46+
# Install GCC. Red Hat installs GCC as a Software Collection (SCL) package,
47+
# where typically you would run `scl enable gcc-toolset-X` to open another Bash
48+
# shell with the GCC toolset enabled. To avoid having to do so, we just directly
49+
# point to the binaries.
4550
ARG GCC_VERSION
4651
RUN <<EOF
4752
dnf install -y --setopt=tsflags=nodocs gcc-toolset-${GCC_VERSION}-gcc gcc-toolset-${GCC_VERSION}-gcc-c++
4853
dnf clean -y all
4954
rm -rf /var/cache/dnf/*
5055
EOF
51-
ENV CC=/usr/bin/gcc
52-
ENV CXX=/usr/bin/g++
56+
ENV CC=/opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcc
57+
ENV CXX=/opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/g++
58+
59+
# Check that the installed GCC version matches the expected version.
60+
RUN <<EOF
61+
CC_VER=$(${CC} -dumpversion)
62+
CC_VER=${CC_VER%%.*}
63+
if [[ "${CC_VER}" != "${GCC_VERSION}" ]]; then
64+
echo "ERROR: 'gcc -dumpversion' gives '${CC_VER}', which does not match expected version '${GCC_VERSION}'."
65+
exit 1
66+
fi
67+
CXX_VER=$(${CXX} -dumpversion)
68+
CXX_VER=${CXX_VER%%.*}
69+
if [[ "${CXX_VER}" != "${GCC_VERSION}" ]]; then
70+
echo "ERROR: g++ -dumpversion gives '${CXX_VER}', which does not match expected version '${GCC_VERSION}'."
71+
exit 1
72+
fi
73+
EOF
5374

5475
# Switch to the non-root user.
5576
USER ${NONROOT_USER}

docker/ubuntu/Dockerfile

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ ARG UBUNTU_VERSION
33
FROM ubuntu:${UBUNTU_VERSION} AS base
44

55
# Use Bash as the default shell for RUN commands, using the options
6-
# `set -o errexit -o pipefail`.
6+
# `set -o errexit -o pipefail`, and as the entrypoint.
77
SHELL ["/bin/bash", "-e", "-o", "pipefail", "-c"]
8+
ENTRYPOINT ["/bin/bash"]
89

910
# Ensure any packages installed directly or indirectly via dpkg do not require
1011
# manual interaction.
@@ -58,7 +59,7 @@ RUN useradd -ms /bin/bash ${NONROOT_USER}
5859
# ====================== GCC IMAGE ======================
5960
FROM base AS gcc
6061

61-
# Install GCC.
62+
# Install GCC and create the necessary symlinks.
6263
ARG GCC_VERSION
6364
RUN <<EOF
6465
apt-get update
@@ -77,14 +78,19 @@ update-alternatives \
7778
EOF
7879
ENV CC=/usr/bin/gcc
7980
ENV CXX=/usr/bin/g++
80-
# Sanity check.
81+
82+
# Check that the installed GCC version matches the expected version.
8183
RUN <<EOF
82-
if [[ "$(${CC} -dumpversion)" != "${GCC_VERSION}" ]]; then
83-
echo "ERROR: gcc -dumpversion does not match expected version '${GCC_VERSION}'"
84+
CC_VER=$(${CC} -dumpversion)
85+
CC_VER=${CC_VER%%.*}
86+
if [[ "${CC_VER}" != "${GCC_VERSION}" ]]; then
87+
echo "ERROR: 'gcc -dumpversion' gives '${CC_VER}', which does not match expected version '${GCC_VERSION}'."
8488
exit 1
8589
fi
86-
if [[ "$(${CXX} -dumpversion)" != "${GCC_VERSION}" ]]; then
87-
echo "ERROR: g++ -dumpversion does not match expected version '${GCC_VERSION}'"
90+
CXX_VER=$(${CXX} -dumpversion)
91+
CXX_VER=${CXX_VER%%.*}
92+
if [[ "${CXX_VER}" != "${GCC_VERSION}" ]]; then
93+
echo "ERROR: g++ -dumpversion gives '${CXX_VER}', which does not match expected version '${GCC_VERSION}'."
8894
exit 1
8995
fi
9096
EOF
@@ -134,6 +140,22 @@ EOF
134140
ENV CC=/usr/bin/clang-${CLANG_VERSION}
135141
ENV CXX=/usr/bin/clang++-${CLANG_VERSION}
136142

143+
# Check that the installed Clang version matches the expected version.
144+
RUN <<EOF
145+
CC_VER=$(${CC} -dumpversion)
146+
CC_VER=${CC_VER%%.*}
147+
if [[ "${CC_VER}" != "${CLANG_VERSION}" ]]; then
148+
echo "ERROR: 'clang -dumpversion' gives '${CC_VER}', which does not match expected version '${GCC_VERSION}'."
149+
exit 1
150+
fi
151+
CXX_VER=$(${CXX} -dumpversion)
152+
CXX_VER=${CXX_VER%%.*}
153+
if [[ "${CXX_VER}" != "${CLANG_VERSION}" ]]; then
154+
echo "ERROR: clang++ -dumpversion gives '${CXX_VER}', which does not match expected version '${GCC_VERSION}'."
155+
exit 1
156+
fi
157+
EOF
158+
137159
# Switch to the non-root user.
138160
USER ${NONROOT_USER}
139161
WORKDIR /home/${NONROOT_USER}
@@ -155,11 +177,11 @@ cat >>~/.conan2/profiles/default <<EOT
155177
[conf]
156178
tools.build:compiler_executables={"c": "${CC}", "cpp": "${CXX}"}
157179
EOT
158-
if [[ $(clang-${CLANG_VERSION} --version | head -1 | grep -Po 'version \K[0-9]{2}') -ge 20 ]]; then
180+
if [[ ${CC_VER} -ge 20 ]]; then
159181
cat >>~/.conan2/profiles/default <<EOT
160182
tools.build:cxxflags=['-Wno-missing-template-arg-list-after-template-kw', '-Wno-deprecated-declarations']
161183
EOT
162-
elif [[ $(clang-${CLANG_VERSION} --version | head -1 | grep -Po 'version \K[0-9]{2}') -eq 19 ]]; then
184+
elif [[ ${CC_VER} -eq 19 ]]; then
163185
cat >>~/.conan2/profiles/default <<EOT
164186
tools.build:cxxflags=['-Wno-missing-template-arg-list-after-template-kw']
165187
EOT

0 commit comments

Comments
 (0)