Skip to content

Commit

Permalink
update docker
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuminjie committed Nov 30, 2020
1 parent 1f0e5c7 commit a8220fc
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 53 deletions.
3 changes: 2 additions & 1 deletion openseespy-docker/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
openseespy-pip
openseespy-pip
opensees
46 changes: 31 additions & 15 deletions openseespy-docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,43 +1,59 @@
FROM ubuntu:18.04 AS compile
########################################################
## compile petsc
FROM ubuntu:18.04 AS ubuntu-petsc

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y
RUN apt-get -y install make gcc g++ gfortran git tcl8.6 tcl8.6-dev libboost-all-dev libblas-dev python3.8 python3.8-dev python3-pip


WORKDIR /home

RUN git clone https://github.com/OpenSees/OpenSees.git openseespy && \
git clone -b release https://gitlab.com/petsc/petsc.git petsc && \
mkdir /home/bin && \
mkdir /home/lib

COPY Makefile.def /home/openseespy/
RUN git clone -b release https://gitlab.com/petsc/petsc.git petsc

WORKDIR /home/petsc
RUN ./configure --download-cmake --download-mpich --download-fblaslapack --download-scalapack --download-mumps --download-metis --download-parmetis --with-shared-libraries=0 --with-debugging=0 COPTFLAGS='-O3 -march=native -mtune=native -fPIC' CXXOPTFLAGS='-O3 -march=native -mtune=native -fPIC' FOPTFLAGS='-O3 -march=native -mtune=native -fPIC'
########################################################

########################################################
## compile openseespy
FROM ubuntu-petsc AS ubuntu-openseespy

ENV DEBIAN_FRONTEND=noninteractive

WORKDIR /home/openseespy
WORKDIR /home
COPY opensees /home/opensees
COPY Makefile.def /home/opensees/

RUN mkdir /home/bin && \
mkdir /home/lib

WORKDIR /home/opensees
RUN make -j python
########################################################

########################################################
## compile openseespy-pip
FROM ubuntu-openseespy AS ubuntu-pip

## Build openseespy package
# Build openseespy package
COPY openseespy-pip /home/openseespy-pip/

WORKDIR /home/openseespy-pip
RUN python3.8 build_pip.py build \
../openseespy/SRC/interpreter/opensees.so \
../opensees/SRC/interpreter/opensees.so \
copy_dep \
python3.8
########################################################


#######################################################
# openseespy
FROM ubuntu:18.04 AS openseespy
# install openseespy
FROM ubuntu:18.04 AS ubuntu-install
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y
RUN apt-get -y install python3.8 python3-pip
WORKDIR /home
COPY --from=0 /home/openseespy-pip/dist/openseespy-*.whl /home/
COPY --from=2 /home/openseespy-pip/dist/openseespy-*.whl /home/
COPY --from=0 /home/petsc/arch-linux-c-opt/bin/mpiexec* /usr/local/bin/
COPY --from=0 /home/petsc/arch-linux-c-opt/bin/hydra_* /usr/local/bin/
COPY hello.py /home/
Expand All @@ -49,7 +65,7 @@ CMD python3.8

#######################################################
# openseespy
FROM openseespy AS openseespy-notebook
FROM ubuntu-install AS ubuntu-notebook
RUN python3.8 -m pip install notebook
WORKDIR /
CMD jupyter notebook --ip=0.0.0.0 --no-browser --allow-root
Expand Down
2 changes: 1 addition & 1 deletion openseespy-docker/Makefile.def
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# that will be created (if this all works!)
binpath = /home/bin
paralleldir = /home/petsc/arch-linux-c-opt
minjie = /home/openseespy
minjie = /home/opensees
libpath = /home/lib

OpenSees_PROGRAM = $(binpath)/openseestcl
Expand Down
68 changes: 32 additions & 36 deletions openseespy-docker/build_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys


def build_docker(dry_run=True, push=False):
def build_docker(push=False):

# change to script's folder
os.chdir(os.path.dirname(os.path.abspath(__file__)))
Expand All @@ -17,51 +17,47 @@ def build_docker(dry_run=True, push=False):

shutil.copytree('../openseespy-pip', 'openseespy-pip')

# opensees
if os.path.exists('opensees'):
print('removing opensees')
shutil.rmtree('opensees')

shutil.copytree('../opensees', 'opensees')

# version
about = {}
with open('openseespy-pip/openseespy/version.py') as fp:
exec(fp.read(), about)
version = about['version']

# tag
tag_compile = f'compile:{version}'
tag_openseespy = f'zhuminjie/openseespy:{version}'
tag_notebook = f'zhuminjie/openseespy:{version}-notebook'
if not dry_run:
subprocess.run(['docker',
'build', '--target', 'compile',
'-t', tag_compile, '.'])
subprocess.run(['docker',
'build', '--target', 'openseespy',
'-t', tag_openseespy, '.'])
subprocess.run(['docker',
'build', '--target',
'openseespy_notebook',
'-t', tag_notebook, '.'])

if push:
subprocess.run(['docker', 'login'])
subprocess.run(['docker', 'image',
'push', tag_openseespy])
subprocess.run(['docker', 'image',
'push', tag_notebook])
else:
print(f'docker build --target compile -t {tag_compile} .')
print(f'docker build --target openseespy -t {tag_openseespy} .')
print(f'docker build --target openseespy_notebook -t {tag_notebook} .')

if push:
print(f'docker login')
print(f'docker image push {tag_openseespy}')
print(f'docker image push {tag_notebook}')
subprocess.run(['docker',
'build', '--target', 'ubuntu-petsc',
'-t', f'ubuntu-petsc:{version}', '.'])
subprocess.run(['docker',
'build', '--target', 'ubuntu-openseespy',
'-t', f'ubuntu-openseespy:{version}', '.'])
subprocess.run(['docker',
'build', '--target', 'ubuntu-pip',
'-t', f'ubuntu-pip:{version}', '.'])
subprocess.run(['docker',
'build', '--target', 'ubuntu-install',
'-t', f'zhuminjie/openseespy:{version}', '.'])
subprocess.run(['docker',
'build', '--target', 'ubuntu-notebook',
'-t', f'zhuminjie/openseespy:{version}-notebook', '.'])

if push:
subprocess.run(['docker', 'login'])
subprocess.run(['docker', 'image',
'push', tag_openseespy])
subprocess.run(['docker', 'image',
'push', tag_notebook])


if __name__ == "__main__":
dry_run = False
push = False
for i in range(1, len(sys.argv)):
if sys.argv[i] == '-dry-run':
dry_run = True
elif sys.argv[i] == '-push':
if sys.argv[i] == '-push':
push = True
build_docker(dry_run, push)
build_docker(push)

0 comments on commit a8220fc

Please sign in to comment.