From 9df74734dd164badb834e57a2f748992a53b6dd5 Mon Sep 17 00:00:00 2001 From: Christian Glusa Date: Sat, 9 Mar 2024 20:00:14 -0700 Subject: [PATCH] Clean up Dockerfile --- .github/workflows/build.yml | 3 +- .github/workflows/container.yml | 4 ++ .github/workflows/documentation-ci.yml | 4 ++ Dockerfile | 53 ++++++++++++++------------ compose.yaml | 2 + entrypoint.sh | 13 +++++++ 6 files changed, 53 insertions(+), 26 deletions(-) create mode 100755 entrypoint.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bfb684a0..7214246e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,9 +7,8 @@ on: branches: [ "master" ] workflow_dispatch: - concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index 8576f15e..1573c001 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -7,6 +7,10 @@ on: branches: [ "master" ] workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + env: IMAGE_NAME: pynucleus IMAGE_TAGS: latest ${{ github.sha }} diff --git a/.github/workflows/documentation-ci.yml b/.github/workflows/documentation-ci.yml index 4c784f98..16bb50ad 100644 --- a/.github/workflows/documentation-ci.yml +++ b/.github/workflows/documentation-ci.yml @@ -5,6 +5,10 @@ on: branches: [ "master" ] workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + permissions: contents: read id-token: write diff --git a/Dockerfile b/Dockerfile index 387755a7..d628009e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,10 +8,12 @@ LABEL maintainer Christian Glusa # install packages needed for build RUN sed -i 's/Components: main/Components: main contrib non-free/' /etc/apt/sources.list.d/debian.sources \ - && apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y \ + && apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -y \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y \ gcc g++ make gfortran \ libssl-dev ca-certificates \ + ccache \ git less nano \ libopenblas0-serial \ libmetis-dev libparmetis-dev \ @@ -37,30 +39,33 @@ WORKDIR /pynucleus ARG PYNUCLEUS_BUILD_PARALLELISM=1 -# Build PyNucleus -RUN make prereq PIP_FLAGS="--no-cache-dir --break-system-packages" && \ - make prereq-extra PIP_FLAGS="--no-cache-dir --break-system-packages" && \ - make install PIP_INSTALL_FLAGS="--no-cache-dir --break-system-packages" && \ - make docs && \ - find . -type f -name '*.c' -exec rm {} + && \ - find . -type f -name '*.cpp' -exec rm {} + && \ - rm -rf build packageTools/build base/build metisCy/build fem/build multilevelSolver/build nl/build +# Install dependencies +# RUN --mount=type=cache,target=/root/.ccache --mount=type=cache,target=/root/.cache/pip \ +RUN \ + make prereq PIP_FLAGS=" --break-system-packages" \ + && make prereq-extra PIP_FLAGS=" --break-system-packages" -# Set up Jupyter notebooks, greeting, some bash things -RUN python -m pip install --no-cache-dir --break-system-packages ipykernel && \ - python -m ipykernel install --name=PyNucleus && \ - echo '[ ! -z "$TERM" -a -r /pynucleus/README.container.rst ] && printf "\e[32m" && cat /pynucleus/README.container.rst && printf "\e[0m"' >> /etc/bash.bashrc && \ - echo "alias ls='ls --color=auto -FN'" >> /etc/bash.bashrc && \ - echo "set completion-ignore-case On" >> /etc/inputrc +# Build PyNucleus +# RUN --mount=type=cache,target=/root/.ccache --mount=type=cache,target=/root/.cache/pip \ +RUN \ + make install PIP_INSTALL_FLAGS=" --break-system-packages" \ + && find . -type f -name '*.c' -exec rm {} + \ + && find . -type f -name '*.cpp' -exec rm {} + \ + && rm -rf build packageTools/build base/build metisCy/build fem/build multilevelSolver/build nl/build \ + && ccache -s -WORKDIR /root +# Generate documentation and examples +RUN make docs \ + && rm examples/test.hdf5 -# Copy examples and drivers to user home, launch Jupyter notebook server -ENTRYPOINT mkdir -p /root/examples && \ - mkdir -p /root/drivers && \ - cp -r --update=none /pynucleus/examples/* /root/examples && \ - cp -r --update=none /pynucleus/drivers/* /root/drivers && \ - jupyter notebook --port=8889 --no-browser --ip=0.0.0.0 --allow-root --NotebookApp.token='' --NotebookApp.password='' --notebook-dir=/root/ --KernelSpecManager.ensure_native_kernel=False --KernelSpecManager.allowed_kernelspecs=pynucleus > /dev/null 2>&1 & \ - /bin/bash +# Set up greeting, settings +RUN \ + echo '[ ! -z "$TERM" -a -r /pynucleus/README.container.rst ] && printf "\e[32m" && cat /pynucleus/README.container.rst && printf "\e[0m"' >> /etc/bash.bashrc \ + && echo "alias ls='ls --color=auto -FN'" >> /etc/bash.bashrc \ + && echo "set completion-ignore-case On" >> /etc/inputrc +# Set up entrypoint with jupyter notebook +COPY entrypoint.sh /usr/local/bin/ +ENTRYPOINT ["entrypoint.sh"] +WORKDIR /root EXPOSE 8889 diff --git a/compose.yaml b/compose.yaml index d4a25ac1..af41110b 100644 --- a/compose.yaml +++ b/compose.yaml @@ -24,7 +24,9 @@ services: # Expose a Jupyter notebook server from the container - 8889:8889 network_mode: host + user: root hostname: pynucleus-container + command: bash tests: image: ghcr.io/sandialabs/pynucleus:latest diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 00000000..76505615 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -e + +mkdir -p ~/examples +mkdir -p ~/drivers +cp -r --update=none /pynucleus/examples/* ~/examples +cp -r --update=none /pynucleus/drivers/* ~/drivers + +jupyter notebook --port=8889 --no-browser --allow-root --ip=0.0.0.0 \ + --NotebookApp.token='' --NotebookApp.password='' \ + --notebook-dir=/root > /dev/null 2>&1 & + +exec "$@"