Last active
May 19, 2024 13:20
-
-
Save appleparan/fbcfaa59ff57ea818c467b80e6f0b3a1 to your computer and use it in GitHub Desktop.
Docker image for ecCodes (CentOS 7.8). Use linuxbrew to avoid glibc dependency hell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM centos:centos7.8.2003 | |
# Install required packages | |
RUN yum groupinstall -y 'Development Tools' | |
RUN yum install -y gcc \ | |
make \ | |
patch \ | |
zlib-devel \ | |
bzip2 \ | |
bzip2-devel \ | |
readline-devel \ | |
sqlite \ | |
sqlite-devel \ | |
openssl-devel \ | |
tk-devel \ | |
libffi-devel \ | |
xz-devel \ | |
expat-devel \ | |
ncurses-devel \ | |
gdbm-devel \ | |
bison \ | |
cmake \ | |
gmake \ | |
wget \ | |
curl \ | |
file \ | |
procps-ng \ | |
git \ | |
vim \ | |
python3 \ | |
make \ | |
autoconf \ | |
unzip | |
# Install recent version of curl from source | |
RUN cd /usr/src && \ | |
wget --no-check-certificate https://curl.se/download/curl-8.7.1.tar.gz && \ | |
tar xzf curl-8.7.1.tar.gz && \ | |
cd curl-8.7.1 && \ | |
./configure --prefix=/usr/local --with-openssl && \ | |
make -j 8 && \ | |
make install && \ | |
/usr/local/bin/curl --version && \ | |
make clean | |
# Install recent version of Git from source | |
# CentOS7 needs to add flag -std=gnu99 to CFLAGS | |
# https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/5948/diffs#diff-content-054ca14425c992bdc139dfcd41557e9509b6a51d | |
RUN yum remove -y git && \ | |
cd /usr/src && \ | |
wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.45.1.tar.gz && \ | |
tar xzf git-2.45.1.tar.gz && \ | |
cd git-2.45.1 && \ | |
make configure && \ | |
./configure --prefix=/usr/local CFLAGS="-std=gnu99" && \ | |
make all -j 8 && \ | |
make install && \ | |
git --version && \ | |
make clean | |
# Install GNU Make (gmake) from source | |
# RUN cd /usr/src && \ | |
# wget https://ftp.gnu.org/gnu/make/make-4.3.tar.gz && \ | |
# tar xzf make-4.3.tar.gz && \ | |
# cd make-4.3 && \ | |
# ./configure --prefix=/usr/local && \ | |
# make -j4 && \ | |
# make install && \ | |
# /usr/local/bin/make --version | |
# # Install custom glibc | |
# RUN cd /usr/src && \ | |
# wget http://ftp.gnu.org/gnu/libc/glibc-2.35.tar.gz && \ | |
# tar xzf glibc-2.35.tar.gz && \ | |
# cd glibc-2.35 && \ | |
# mkdir build && cd build && \ | |
# PATH="/usr/local/bin/:$PATH" ../configure --prefix=/usr/local/glibc-2.35 && \ | |
# /usr/local/bin/make -j 8 && \ | |
# /usr/local/bin/make install | |
# I can't install linuxbrew as root, so I need to create a new user | |
RUN useradd -m -s /bin/bash linuxbrew && \ | |
echo 'linuxbrew ALL=(ALL) NOPASSWD:ALL' >>/etc/sudoers | |
# Install Linuxbrew | |
USER linuxbrew | |
# Set environment variables for Homebrew to use custom glibc | |
# ENV HOMEBREW_LIBRARY_PATHS="/usr/local/glibc-2.35/lib" | |
# ENV HOMEBREW_INCLUDE_PATHS="/usr/local/glibc-2.35/include" | |
# ENV LDFLAGS="-Wl,-rpath=/usr/local/glibc-2.35/lib -L/usr/local/glibc-2.35/lib" | |
# ENV CPPFLAGS="-I/usr/local/glibc-2.35/include" | |
# ENV PATH="/usr/local/glibc-2.35/bin:$PATH:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" | |
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)" && \ | |
echo 'eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)' >> ~/.bash_profile && \ | |
echo 'eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)' >> ~/.bashrc && \ | |
source ~/.bash_profile | |
ENV PATH="/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:${PATH}" | |
ENV SHELL="/bin/bash" | |
RUN test -d ~/.linuxbrew && eval "$(~/.linuxbrew/bin/brew shellenv)" && \ | |
test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" && \ | |
echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.bashrc && \ | |
echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.bash_profile && \ | |
source ~/.bash_profile | |
# Install required packages from Linuxbrew | |
# Fix gcc@13 to install Python 3.12 | |
# RUN brew install cmake gnu-which vim \ | |
# openssl readline sqlit`e3 xz lzip ncurses xml-coreutils tcl-tk zlib [email protected] | |
RUN brew install openssl readline sqlite3 xz lzip ncurses xml-coreutils tcl-tk zlib [email protected] | |
RUN brew install netcdf libaec jpeg png++ eccodes | |
# Set up the environment | |
ENV ECCODES_DIR=/home/linuxbrew/.linuxbrew/Cellar/eccodes/2.35.0/ | |
RUN echo 'export ECCODES_DIR=/home/linuxbrew/.linuxbrew/Cellar/eccodes/2.35.0' >> ~/.bashrc && \ | |
echo 'export ECCODES_DIR=/home/linuxbrew/.linuxbrew/Cellar/eccodes/2.35.0' >> ~/.bash_profile | |
WORKDIR /home/linuxbrew/ | |
RUN mkdir env && \ | |
cd env && \ | |
python3 -m venv . && \ | |
source ./bin/activate && \ | |
pip install --upgrade pip setuptools wheel && \ | |
pip install numpy scipy matplotlib pandas netCDF4 cfgrib xarray joblib eccodes-python | |
# Test the environment | |
# https://github.com/ecmwf/cfgrib | |
WORKDIR /home/linuxbrew/env | |
RUN wget https://get.ecmwf.int/repository/test-data/cfgrib/era5-levels-members.grib && \ | |
source ./bin/activate && \ | |
python -c "import xarray as xr; ds = xr.open_dataset('era5-levels-members.grib', engine='cfgrib'); ds" | |
RUN brew cleanup | |
# Set the working directory | |
USER root | |
RUN mkdir /workspace | |
WORKDIR /workspace | |
RUN yum clean all && \ | |
rm -rf /var/cache/yum | |
# Command to keep the container running | |
CMD ["/bin/bash"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment