-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
200 lines (166 loc) · 7.19 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
FROM debian:buster-slim
#MAINTAINER Valentino Lauciani <[email protected]>
#
ENV DEBIAN_FRONTEND=noninteractive
ENV INITRD No
ENV FAKE_CHROOT 1
# Set Shakemap checkout: https://github.com/usgs/shakemap.git
#680fce15728e1d06c1616f4bd18d5dafb030de9a
ENV SHAKEMAP_COMMIT=a12d0dc5204e3dff1f7848fcea4c29836cf15d2e
# Make RUN commands use `bash --login`:
SHELL ["/bin/bash", "--login", "-c"]
# Set 'root' pwd
RUN echo root:toor | chpasswd
# install packages
RUN apt-get update \
&& apt-get dist-upgrade -y --no-install-recommends \
&& apt-get install -y \
build-essential \
vim \
bc \
git \
curl \
clang \
&& apt-get clean
# Set .bashrc for root user
RUN echo "" >> /root/.bashrc \
&& echo "##################################" >> /root/.bashrc \
&& echo "alias ll='ls -l --color'" >> /root/.bashrc \
&& echo "" >> /root/.bashrc \
&& echo "export LC_ALL=\"C\"" >> /root/.bashrc \
&& echo "" >> /root/.bashrc \
&& echo "caption always" >> /root/.screenrc \
&& echo "caption string '%{+b b}%H: %{= .W.} %{b}%D %d-%M %{r}%c %{k}%?%F%{.B.}%?%2n%? [%h]%? (%w)'" >> /root/.screenrc
##################################
# Set User and Group variabls
ENV GROUP_NAME=shake
ENV USER_NAME=shake
ENV HOMEDIR_USER=/home/${USER_NAME}
# Set default User and Group id from arguments
# If UID and/or GID are equal to zero then new user and/or group are created
ARG ENV_UID=0
ARG ENV_GID=0
RUN echo ENV_UID=${ENV_UID}
RUN echo ENV_GID=${ENV_GID}
RUN \
if (( ${ENV_UID} == 0 )) || (( ${ENV_GID} == 0 )); \
then \
echo ""; \
echo "WARNING: when passing UID or GID equal to zero, new user and/or group are created."; \
echo " On Linux, if you run docker image by different UID or GID you could not able to write in docker mount data directory."; \
echo ""; \
fi
# Check if GID already exists
RUN cat /etc/group
RUN \
if (( ${ENV_GID} == 0 )); \
then \
addgroup --system ${GROUP_NAME}; \
elif grep -q -e "[^:][^:]*:[^:][^:]*:${ENV_GID}:.*$" /etc/group; \
then \
GROUP_NAME_ALREADY_EXISTS=$(grep -e "[^:][^:]*:[^:][^:]*:${ENV_GID}:.*$" /etc/group | cut -f 1 -d':'); \
echo "GID ${ENV_GID} already exists with group name ${GROUP_NAME_ALREADY_EXISTS}"; \
groupmod -n ${GROUP_NAME} ${GROUP_NAME_ALREADY_EXISTS}; \
else \
echo "GID ${ENV_GID} does not exist"; \
addgroup --gid ${ENV_GID} --system ${GROUP_NAME}; \
fi
# Check if UID already exists
RUN cat /etc/passwd
RUN \
if (( ${ENV_UID} == 0 )); \
then \
useradd --system -d ${HOMEDIR_USER} -g ${GROUP_NAME} -s /bin/bash ${USER_NAME}; \
elif grep -q -e "[^:][^:]*:[^:][^:]*:${ENV_UID}:.*$" /etc/passwd; \
then \
USER_NAME_ALREADY_EXISTS=$(grep -e "[^:][^:]*:[^:][^:]*:${ENV_UID}:.*$" /etc/passwd | cut -f 1 -d':'); \
echo "UID ${ENV_UID} already exists with user name ${USER_NAME_ALREADY_EXISTS}"; \
usermod -d ${HOMEDIR_USER} -g ${ENV_GID} -l ${USER_NAME} ${USER_NAME_ALREADY_EXISTS}; \
else \
echo "UID ${ENV_UID} does not exist"; \
useradd --system -u ${ENV_UID} -d ${HOMEDIR_USER} -g ${ENV_GID} -G ${GROUP_NAME} -s /bin/bash ${USER_NAME}; \
fi
# adduser -S -h ${HOMEDIR_USER} -G ${GROUP_NAME} -s /bin/bash ${USER_NAME}; \
# adduser --uid ${ENV_UID} --home ${HOMEDIR_USER} --gid ${ENV_GID} --shell /bin/bash ${USER_NAME}; \
# Create home directory
RUN mkdir ${HOMEDIR_USER}
###########################################
# Copy some files
RUN cp /root/.bashrc ${HOMEDIR_USER}/
RUN cp /root/.screenrc ${HOMEDIR_USER}/
# Copy entrypoint file
COPY ./entrypoint.sh ${HOMEDIR_USER}/
RUN chmod 755 ${HOMEDIR_USER}/entrypoint.sh
# Set home directory own
RUN chown -R ${USER_NAME}:${GROUP_NAME} ${HOMEDIR_USER}
# Change default user
USER ${USER_NAME}:${GROUP_NAME}
# Get shakemap software
WORKDIR ${HOMEDIR_USER}
RUN mkdir gitwork \
&& cd gitwork \
&& git config --global user.email "[email protected]" \
&& git config --global user.name "Valentino Lauciani" \
&& git clone https://github.com/usgs/shakemap.git shakemap_src \
&& cd shakemap_src \
&& git checkout ${SHAKEMAP_COMMIT}
# Copy modified plotregr.py (issue: https://gitlab.rm.ingv.it/shakemap/shakemap4/-/issues/5)
COPY ./ext/plotregr.py ${HOMEDIR_USER}/gitwork/shakemap_src/shakemap/coremods/
# Add 'conda' source in the '.bashrc' file - It must be run BEFORE to install shakemap software; because, if not exists, the intalleer will add '. /etc/profile.d/conda.sh' that doesn't exist.
RUN echo ". ${HOMEDIR_USER}/miniconda/etc/profile.d/conda.sh" >> ${HOMEDIR_USER}/.bashrc
# BUGFIX 1/3
#WORKDIR ${HOMEDIR_USER}/gitwork/shakemap_src
#RUN mv install.sh install.sh.original \
# && sed -e 's/curl -L/curl --tls-max 1.2 -L/' install.sh.original > install.sh
# BUGFIX 2/3 - il paccketto 'numpy' se installato nei 'package_list', da errore; se installato singolarmente successivamente a 'bash install.sh', va bene... boh!
#WORKDIR ${HOMEDIR_USER}/gitwork/shakemap_src
#RUN mv install.sh install.sh.original \
# && sed -e 's/"numpy==1.20"//' install.sh.original > install.sh
# Install shakemap software
WORKDIR ${HOMEDIR_USER}/gitwork/shakemap_src
RUN bash install.sh
# BUGFIX 3/3
#RUN . ${HOMEDIR_USER}/miniconda/etc/profile.d/conda.sh \
# && conda install -n shakemap numpy==1.20 -y
# 1) Source variables
# 2) Add python modules 'basemap' and 'seaborn'. Issue: #20
RUN . ${HOMEDIR_USER}/miniconda/etc/profile.d/conda.sh \
&& conda info --envs \
&& conda activate shakemap \
&& pip install basemap \
&& pip install seaborn \
&& sm_profile -c world -a -n
# Copy own libs
#COPY ./ext/gmice.py ${HOMEDIR_USER}/gitwork/shakemap_src/shakelib/gmice/
COPY ./ext/fm10.py ${HOMEDIR_USER}/gitwork/shakemap_src/shakelib/gmice/
COPY ./ext/ofm22.py ${HOMEDIR_USER}/gitwork/shakemap_src/shakelib/gmice/
COPY ./ext/fm11_ch.py ${HOMEDIR_USER}/gitwork/shakemap_src/shakelib/gmice/
# Copy 'tusa_langer_2016.py'
COPY ./ext/tusa_langer_2016.py /tmp/
# COPY ./ext/pasolini_2008_ipe.py /tmp/
#RUN for TUSA in $(find ${HOMEDIR_USER}/miniconda/ -name tusa_langer_2016.py); do cp -v /tmp/tusa_langer_2016.py ${TUSA}; done
RUN PATHTUSA=$( find ${HOMEDIR_USER}/miniconda/ -name tusa_langer_2016.py ) \
&& DIRNAME_PATHTUSA=$( dirname ${PATHTUSA} ) \
&& cp -v /tmp/tusa_langer_2016.py ${DIRNAME_PATHTUSA}/
# && cp -v /tmp/pasolini_2008_ipe.py ${DIRNAME_PATHTUSA}/
#
WORKDIR ${HOMEDIR_USER}
# Create shakemap_dat
RUN mkdir -p shakemap_data/topo
RUN mkdir -p shakemap_data/vs30
RUN curl -o shakemap_data/vs30/Hellas-geology_18-30_34-43_30s_NoNan.grd "https://webservices.ingv.it/Hellas-geology_18-30_34-43_30s_NoNan.grd"
RUN curl -o shakemap_data/vs30/global_italy_vs30_clobber.grd "https://webservices.ingv.it/global_italy_vs30_clobber.grd"
RUN curl -o shakemap_data/topo/topo_30sec.grd "https://webservices.ingv.it/topo_30sec.grd"
# Fix permissions
USER root
RUN chown -R ${USER_NAME}:${GROUP_NAME} shakemap_data/
RUN chown -R ${USER_NAME}:${GROUP_NAME} gitwork/
# Change default user
USER ${USER_NAME}:${GROUP_NAME}
#
RUN echo "conda activate base" >> ${HOMEDIR_USER}/.bashrc
RUN echo "source activate shakemap" >> ${HOMEDIR_USER}/.bashrc
ENV PATH ${HOMEDIR_USER}/miniconda/envs/env/bin:$PATH
# Set entrypoint
ENTRYPOINT ["./entrypoint.sh"]
#CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--allow-root"]