-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
225 lines (189 loc) · 8.32 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
################################################################################
#
# Base container which fixes CentOS EOL
FROM centos:8 AS caen-base
# Prep base environment
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/code
VOLUME /code
RUN mkdir -p /usr/um
# CentOS has been deprecated in favor of CentOS stream, so update repo list to
# search archives:
# https://forums.centos.org/viewtopic.php?f=54&t=78708
# https://www.getpagespeed.com/server-setup/how-to-fix-dnf-after-centos-8-went-eol
RUN sed -i \
-e 's/#baseurl/baseurl/g' \
-e 's/mirror.centos.org/vault.epel.cloud/g' \
-e 's/mirrorlist/#mirrorlist/g' \
/etc/yum.repos.d/CentOS-Linux-* \
&& dnf clean all \
&& dnf swap -y centos-linux-repos centos-stream-repos \
&& dnf install -y --nodocs wget bzip2 tar make
# Set bash as default
SHELL ["/bin/bash", "-c"]
################################################################################
#
# Builder stage for compiling gcc-6.2.0 compiler
FROM caen-base as gcc-6-builder
# Install pre-requisite programs for compiling gcc-6.2.0
RUN dnf update -y && dnf install -y --nodocs \
gcc-c++ \
libgcc \
glibc-devel \
epel-release \
bzip2 \
wget \
flex \
git \
openssh \
make \
&& dnf -y --nodocs --enablerepo=powertools install glibc-static libstdc++-static
# Download the archive from GNU server. Source directory will be /tmp/gcc-6.2.0/,
# object directory will be /tmp/objdir, and install directory will be /usr/um/gcc-6.2.0/
RUN mkdir -p /usr/um/gcc-6.2.0/ /tmp/objdir/ /tmp/gcc-6.2.0/ && cd /tmp \
&& wget https://ftp.gnu.org/gnu/gcc/gcc-6.2.0/gcc-6.2.0.tar.gz \
&& tar -xvf /tmp/gcc-6.2.0.tar.gz -C /tmp/ \
&& rm -f /tmp/gcc-6.2.0.tar.gz \
&& cd /tmp/gcc-6.2.0 \
&& /tmp/gcc-6.2.0/contrib/download_prerequisites
# glibc 7 introduced a different way of handling ucontext and sigalstack types,
# meaning that compilation of gcc 6 and the sanitizers will fail. gcc-7.4.0 also
# removed ustat.h for sanitizer_platform_limits_posix.cc, which was already
# deprecated so the headers simply need to be removed. See links below for
# description and workaround.
#
# Note that the build will fail if --enable-languages is not specified. Also note
# that gcc is not compiled with address sanitizers at the moment because there are
# still some bugs to squash, but the sed commands are left here as reference
#
# https://gcc.gnu.org/git/?p=gcc.git&a=commit;h=8774a9cf3435d41cd6a89e93c9d8c34b1c5edbcf
# https://stackoverflow.com/questions/46999900/how-to-compile-gcc-6-4-0-with-gcc-7-2-in-archlinux
# https://stackoverflow.com/questions/56096060/how-to-fix-the-gcc-compilation-error-sys-ustat-h-no-such-file-or-directory-i
# https://github.com/vmware/photon/blob/master/SPECS/gcc/libsanitizer-avoidustat.h-glibc-2.28.patch
WORKDIR /tmp/gcc-6.2.0
RUN sed -i \
-e 's/struct ucontext/ucontext_t/' \
./libgcc/config/i386/linux-unwind.h \
&& sed -i \
-e 's/struct sigaltstack/void/' \
./libsanitizer/sanitizer_common/sanitizer_linux.cc \
&& sed -i \
-e '/struct sigaltstack;/d' \
./libsanitizer/sanitizer_common/sanitizer_linux.h \
&& sed -i \
-e 's/struct sigaltstack/void/g' \
./libsanitizer/sanitizer_common/sanitizer_linux.h \
&& sed -i \
-e 's/struct sigaltstack/stack_t/' \
./libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc \
&& sed -i \
's/__res_state/struct __res_state/g' \
./libsanitizer/tsan/tsan_platform_linux.cc \
&& sed -i \
-e 's/sizeof(struct ustat)/32/' \
-e '/ustat.h/d' \
./libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
# Configure the Makefile and compile
WORKDIR /tmp/objdir
RUN unset C_INCLUDE_PATH CPLUS_INCLUDE_PATH CFLAGS CXXFLAGS \
&& /tmp/gcc-6.2.0/configure \
--with-pkgversion="GCC version 6.2.0 for derickson/Dockerized-CAEN" \
--with-bugurl="https://github.com/derickson2402/Dockerized-CAEN/issues" \
--with-changes-root-url="https://github.com/derickson2402/Dockerized-CAEN" \
--prefix=/usr/um/gcc-6.2.0 \
--enable-languages=c,c++,fortran \
--disable-multilib \
&& make -j 4 \
&& make install \
&& rm -rf /tmp/gcc-6.2.0 /tmp/objdir
################################################################################
#
# Development environment with basic tools installed, used for builder layers
# and for testing
FROM caen-base AS caen-dev
# Install default packages for developing these containers
RUN dnf update -y \
&& dnf --setopt=group_package_types=mandatory groupinstall --nodocs -y "Development Tools" \
&& dnf install --nodocs -y vim
CMD ["/bin/bash"]
################################################################################
#
# Builder container for compiling cppcheck
FROM caen-dev AS builder-cppcheck
# Download and compile cppcheck. Note that /usr/share/Cppcheck has an
# uppercase 'C', as this is what CAEN has for some reason
RUN wget https://github.com/danmar/cppcheck/archive/2.4.tar.gz \
-O /tmp/cppcheck-2.4.tar.gz \
&& tar -C /tmp -xzf /tmp/cppcheck-2.4.tar.gz \
&& rm -rf /tmp/cppcheck-2.4.tar.gz \
&& cd /tmp/cppcheck-2.4 \
&& FILESDIR=/usr/share/Cppcheck make install \
&& rm -rf /tmp/cppcheck-2.4
################################################################################
#
# Builder container for compiling golang
FROM caen-dev AS builder-golang
# Download and install golang
RUN wget https://dl.google.com/go/go1.16.12.linux-amd64.tar.gz \
-O /tmp/go.tar.gz \
&& tar -C /usr/um -xzf /tmp/go.tar.gz \
&& rm -rf /tmp/go.tar.gz /usr/local/go /usr/go /usr/bin/go
################################################################################
#
# Default container with all tools and supported languages
FROM caen-base
# Set up cppcheck
COPY --from=builder-cppcheck /usr/bin/cppcheck /usr/bin/cppcheck
COPY --from=builder-cppcheck /usr/share/Cppcheck /usr/share/Cppcheck
# Set up golang
COPY --from=builder-golang /usr/um/go /usr/um/go
RUN ln -s /usr/um/go/bin/go /usr/bin/go
# Set our compiled gcc to custom software location
COPY --from=gcc-6-builder /usr/um/gcc-6.2.0/ /usr/um/gcc-6.2.0/
# Install dev packages and tools, clean dnf cache to save space. Also install
# gcc-12.2.1
RUN dnf --setopt=group_package_types=mandatory \
groupinstall --nodocs -y "Development Tools" \
&& dnf install --nodocs -y \
perf \
valgrind \
git \
vim \
which \
gnupg2 \
gcc-toolset-12 \
&& dnf clean all \
&& rm -rf /var/cache/yum \
&& rm -rf /var/cache/dnf
# Configure versions of gcc. Default is 12.2.1, but gcc-12, gcc-12.2,
# gcc-12.2.1, gcc-8, gcc-8.5, gcc-8.5.0, gcc-6, gcc-6.2, gcc-6.2.0 should all
# work as expected
WORKDIR /usr/local/bin
RUN ln -s /usr/bin/gcc gcc \
&& ln -s /usr/bin/g++ g++ \
&& ln -s /opt/rh/gcc-toolset-12/root/bin/gcc gcc-12 \
&& ln -s /opt/rh/gcc-toolset-12/root/bin/gcc g++-12 \
&& ln -s /opt/rh/gcc-toolset-12/root/bin/gcc gcc-12.2 \
&& ln -s /opt/rh/gcc-toolset-12/root/bin/gcc g++-12.2 \
&& ln -s /opt/rh/gcc-toolset-12/root/bin/gcc gcc-12.2.1 \
&& ln -s /opt/rh/gcc-toolset-12/root/bin/gcc g++-12.2.1 \
&& ln -s /usr/bin/gcc gcc-8 \
&& ln -s /usr/bin/g++ g++-8 \
&& ln -s /usr/bin/gcc gcc-8.5 \
&& ln -s /usr/bin/g++ g++-8.5 \
&& ln -s /usr/bin/gcc gcc-8.5.0 \
&& ln -s /usr/bin/g++ g++-8.5.0 \
&& ln -s /usr/um/gcc-6.2.0/bin/gcc gcc-6 \
&& ln -s /usr/um/gcc-6.2.0/bin/g++ g++-6 \
&& ln -s /usr/um/gcc-6.2.0/bin/gcc gcc-6.2 \
&& ln -s /usr/um/gcc-6.2.0/bin/g++ g++-6.2 \
&& ln -s /usr/um/gcc-6.2.0/bin/gcc gcc-6.2.0 \
&& ln -s /usr/um/gcc-6.2.0/bin/g++ g++-6.2.0
# Give bash a pretty prompt
ENV PS1="\[\e[0;1;38;5;82m\]CAEN ~\[\e[0m\] "
# Configure bash to force CRLF conversions, fix Perf bug (#28)
RUN git config --global core.autocrlf true \
&& mkdir -p /usr/share/doc/perf-tip/ \
&& echo "CAEN in Docker" > /usr/share/doc/perf-tip/tips.txt
# Run the container in the user's project folder
WORKDIR /code
CMD ["/bin/bash", "-c"]