Skip to content

Commit

Permalink
wiZZp
Browse files Browse the repository at this point in the history
  • Loading branch information
meihuisu committed Jan 18, 2025
1 parent 1721946 commit fe92252
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 62 deletions.
122 changes: 69 additions & 53 deletions ucvm_v22_7_quakeworx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ BDATE=$BDATE
# and for building the model and adding the correct date into the label
RUN echo $APP_UNAME $APP_GRPNAME $APP_UID $APP_GID $MODELID $BDATE

# Setup Owners
# Documents say this groupadd is needed when you build on linux, but not on Mac
RUN groupadd -f --non-unique --gid $APP_GID $APP_GRPNAME
RUN useradd -ms /bin/bash -g $APP_GRPNAME --uid $APP_UID $APP_UNAME

# Added explicit HOME environment variable
# /home/ucvmuser
ENV HOME=/home/$APP_UNAME

# Added steps to manage home directory permissions
RUN mkdir -p $HOME/.local \
&& chown -R $APP_UID:$APP_GID $HOME \
&& chmod -R 755 $HOME

WORKDIR /home/$APP_UNAME

RUN yum clean all && \
yum -y update && \
yum -y groupinstall "Development Tools" && \
Expand All @@ -34,73 +50,61 @@ RUN yum clean all && \
# virtual environment in this image
RUN ln -s /usr/bin/python3 /usr/bin/python

# Install JupyterLab
# RUN python -m pip install --no-cache-dir jupyterlab
# Expose the port JupyterLab will run on
EXPOSE 8888


# Create python link as root before setting user. This is needed by
# the ucvm_setup.py script which will run to the ucvm installation
# To support the python2 plotting library, we will install Anaconda with a python2
# virtual environment in this image
WORKDIR /app
RUN wget --quiet https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh -O anaconda.sh && \
WORKDIR /home/$APP_UNAME/app
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O anaconda.sh && \
mkdir /home/$APP_UNAME/.conda && \
/bin/bash anaconda.sh -b -p /usr/local/opt/conda && \
rm anaconda.sh && \
./usr/local/opt/conda/bin/activate && \
conda init bash
rm -f anaconda.sh && \
echo "Running $(conda --version)" && \
/usr/local/opt/conda/bin/conda update conda && \
/usr/local/opt/conda/bin/conda init bash

RUN /usr/local/opt/conda/bin/conda create -n Python2 python=2.7.15 scipy pip numpy matplotlib basemap basemap-data-hires
#RUN wget --quiet https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh -O anaconda.sh && \
# /bin/bash anaconda.sh -b -p /usr/local/opt/conda && \
# rm anaconda.sh && \
# ln -s /usr/local/opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
# find /usr/local/opt/conda/ -follow -type f -name '*.a' -delete && \
# find /usr/local/opt/conda/ -follow -type f -name '*.js.map' -delete && \
# /usr/local/opt/conda/bin/conda clean -afy && \
# /usr/local/opt/conda/bin/conda init bash

RUN /usr/local/opt/conda/bin/conda install jupyterlab
RUN echo "source /usr/local/opt/conda/etc/profile.d/conda.sh" >> /home/$APP_UNAME/.bashrc && \
bash /home/$APP_UNAME/.bashrc && \
/usr/local/opt/conda/bin/conda install -y pip

# Setup Owners
# Documents say this groupadd is needed when you build on linux, but not on Mac
RUN groupadd --non-unique --gid $APP_GID $APP_GRPNAME && \
useradd -ms /bin/bash -G $APP_GRPNAME --uid $APP_UID $APP_UNAME
#RUN /usr/local/opt/conda/bin/conda create -n Python2 -y python=2.7.15 scipy numpy matplotlib basemap basemap-data-hires
RUN /usr/local/opt/conda/bin/conda create -n plotPython -y numpy matplotlib basemap basemap-data-hires

RUN chmod -R og+rw /app
RUN /usr/local/opt/conda/bin/conda install -y jupyterlab


#### building user app part

# Retrieve and build UCVM
WORKDIR /app
WORKDIR /home/$APP_UNAME/app
RUN git clone https://github.com/sceccode/ucvm.git src

# An external script has selected the correct model files for this image in the largefiles dir
# by setting the model abbreviations in the largefile_inputs.txt file
WORKDIR /app/src/largefiles
WORKDIR /home/$APP_UNAME/app/src/largefiles
RUN ./get_largefiles.py -m $MODELID && ./stage_largefiles.py

WORKDIR /app/src
RUN ./ucvm_setup.py -a -d -p /app/ucvm >& ./ucvm_setup_install.log
WORKDIR /home/$APP_UNAME/app/src
RUN ./ucvm_setup.py -a -d -p /home/$APP_UNAME/app/ucvm >& ./ucvm_setup_install.log

# Remove the src directories to save space
WORKDIR /app
WORKDIR /home/$APP_UNAME/app
RUN rm -rf src

# Install plotting libraries
WORKDIR /app/ucvm
RUN echo "conda activate Python2" >> ~/.bashrc
SHELL ["/bin/bash", "--login", "-c"]

WORKDIR /home/$APP_UNAME/app/ucvm
RUN git clone https://github.com/SCECcode/ucvm_plotting.git
WORKDIR /app/ucvm/ucvm_plotting
RUN ./unpack-dist


# Define file input/output mounted disk
#
VOLUME /app/target

# Setup user with test input files
#
WORKDIR /app
COPY examples /app/examples

# Added steps to manage home directory permissions
RUN chown -R $APP_UID:$APP_GID /app && \
chmod -R og+rw /app/ucvm /app/examples && \
chmod -R +x /app/examples/*.py /app/examples/*.sh
WORKDIR /home/$APP_UNAME/app/ucvm/ucvm_plotting
##RUN ./unpack-dist

# Add metadata to dockerfile using labels
LABEL org.label-schema.build-date=$BDATE
Expand All @@ -110,19 +114,31 @@ LABEL org.scec.responsible_person="Philip Maechling"
LABEL org.scec.primary_contact="[email protected]"
LABEL version="ucvm_v22_7"

RUN echo "source /home/$APP_UNAME/app/ucvm/conf/ucvm_env.sh" >> /home/$APP_UNAME/.bashrc && \
echo "export PATH=\"/usr/local/opt/conda/bin:$PATH\"" >> /home/$APP_UNAME/.bashrc && \
echo "conda activate plotPython" >> /home/$APP_UNAME/.bashrc

# Added steps to manage home directory permissions
RUN mkdir -p $HOME/.local \
&& chown -R $APP_UID:$APP_GID $HOME \
&& chmod -R 755 $HOME

USER $APP_UNAME
RUN echo "source /usr/local/opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \
echo "source /app/ucvm/conf/ucvm_env.sh" >> ~/.bashrc && \
echo "export PATH=\"/usr/local/opt/conda/bin:$PATH\"" && \
echo "conda activate Python2" >> ~/.bashrc

ENV PATH="/usr/local/opt/conda/bin:${PATH}"
ARG PATH="/usr/local/opt/conda/bin:${PATH}"


#SHELL ["/bin/bash", "--login", "-c"]
#WORKDIR /app/target
#ENTRYPOINT ["/bin/bash"]
WORKDIR /home/$APP_UNAME

# Expose the port JupyterLab will run on
EXPOSE 8888

# Define file input/output mounted disk
VOLUME /home/$APP_UNAME/app/target

SHELL ["/bin/bash", "--login", "-c"]

ENTRYPOINT ["/bin/bash"]
# Define the command to run JupyterLab
CMD ["jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--allow-root"]
#ENTRYPOINT ["/usr/local/opt/conda/bin/jupyter", "lab", "--ip=0.0.0.0", "--no-browser", "--allow-root"]

13 changes: 7 additions & 6 deletions ucvm_v22_7_quakeworx/build_one_quakeworx.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
for m in models:
print ("building model: " + m)
cmd = "docker build --no-cache=false -f Dockerfile . -t ucvm_227_%s_quakeworx:%s " \
"--build-arg APP_UNAME=ucvmuser --build-arg APP_GRPNAME=`id -g -nr` " \
"--build-arg APP_UNAME=ucvmuser --build-arg APP_GRPNAME=ucvmuser " \
"--build-arg APP_UID=1000 --build-arg APP_GID=1000 --build-arg MODELID=%s --build-arg BDATE=%s"%(m,mdate,m,mdate)

os.system(cmd)

cmd = "docker tag ucvm_227_%s_quakeworx:%s sceccode/ucvm_227_%s_quakeworx:latest"%(m,mdate,m)
os.system(cmd)
cmd = "docker tag ucvm_227_%s:%s sceccode/ucvm_227_%s:%s"%(m,mdate,m,mdate)
print(cmd)
# os.system(cmd)

print("pushing models: " + m + " with sceccode/ucvm_227_%s_quakeworx:%s" % (m,mdate))
cmd = "docker push sceccode/ucvm_227_%s_quakeworx:latest" % (m)
os.system(cmd)
cmd = "docker push sceccode/ucvm_227_%s_quakeworx:%s" % (m,mdate)
print(cmd)
# os.system(cmd)
5 changes: 2 additions & 3 deletions ucvm_v22_7_quakeworx/r
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
#docker pull sceccode/ucvm_227_cvmh_quakeworx:latest
#docker rm $(docker ps -a | grep Exit | cut -d ' ' -f 1)

#docker run -p 8888:8888 --rm -it --mount type=bind,source="$(pwd)"/target,destination=/app/target ucvm_227_cvmh_quakeworx:0116

docker run -p 8888:8888 --rm -it --mount type=bind,source="$(pwd)"/target,destination=/app/target sceccode/ucvm_227_cvmh_quakeworx:latest
docker run -p 8888:8888 --rm -it --mount type=bind,source="$(pwd)"/target,destination=/app/target sceccode/ucvm_227_cvmh_quakeworx:0117
#sceccode/ucvm_227_cvmh_quakeworx:latest

#docker run -p 8888:8888 --rm -it --mount type=bind,source="$(pwd)"/target,destination=/home/ucvmuser/target sceccode/ucvm_227_cvmh:0710
#
Expand Down

0 comments on commit fe92252

Please sign in to comment.