diff --git a/.github/workflows/build-container.yaml b/.github/workflows/build-container.yaml index 86c0d7bd601..53aa46a3114 100644 --- a/.github/workflows/build-container.yaml +++ b/.github/workflows/build-container.yaml @@ -27,7 +27,8 @@ jobs: matrix: # Dockerfiles to build, a matrix supports future expanded builds - container: [["config/docker/Dockerfile", "ghcr.io/mfem/mfem-ubuntu-base"]] + container: [["config/docker/Dockerfile.base", "ghcr.io/mfem/mfem-ubuntu-base"], + ["config/docker/Dockerfile", "ghcr.io/mfem/mfem-ubuntu"]] runs-on: ubuntu-latest name: Build diff --git a/config/docker/Dockerfile b/config/docker/Dockerfile index 55ebc2d1d37..e5788c3087a 100644 --- a/config/docker/Dockerfile +++ b/config/docker/Dockerfile @@ -1,30 +1,26 @@ -FROM ghcr.io/rse-ops/cuda-ubuntu-20.04:cuda-11.0.3 +FROM ghcr.io/mfem/mfem-ubuntu-base:latest as builder -# docker build -t ghcr.io/mfem/mfem-ubuntu-base . +# docker build -t ghcr.io/mfem/mfem-ubuntu . + +COPY ./spack.yaml /opt/mfem-env/spack.yaml +RUN apt-get install -y python3 && \ + cd /opt/mfem-env && \ + . /opt/spack/share/spack/setup-env.sh && \ + spack env activate . && \ + spack env view regenerate + +FROM ubuntu:22.04 + +COPY --from=builder /opt/view /opt/view +COPY --from=builder /opt/mfem-view /opt/mfem-view RUN apt-get update && \ apt-get install -y unzip gfortran && \ - spack compiler find && \ apt-get install -y libcurl4-openssl-dev libssl-dev -# /code is the working directory for code -WORKDIR /code -COPY . /code - -# This is for a spack environment/view to install from there -WORKDIR /opt/mfem-env -RUN . /opt/spack/share/spack/setup-env.sh && \ - spack env create -d . && \ - echo " concretization: together" >> spack.yaml && \ - spack env activate . && \ - spack develop --path /code mfem@master+examples+miniapps && \ - spack add mfem@master+examples+miniapps && \ - spack install - -# ensure mfem always on various paths -RUN cd /opt/mfem-env && \ - spack env activate --sh -d . >> /etc/profile.d/z10_spack_environment.sh +ENV PATH=$PATH:/opt/mfem-view/bin +ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/mfem-view/lib:/opt/mfem-view/lib64 # The user will see the view on shell into the container -WORKDIR /opt/mfem-env/.spack-env/view/ -ENTRYPOINT ["/bin/bash", "--rcfile", "/etc/profile", "-l", "-c"] +WORKDIR /opt/mfem-view +ENTRYPOINT ["/bin/bash"] diff --git a/config/docker/Dockerfile.base b/config/docker/Dockerfile.base new file mode 100644 index 00000000000..9dc8b2c13ed --- /dev/null +++ b/config/docker/Dockerfile.base @@ -0,0 +1,47 @@ +FROM ghcr.io/rse-ops/cuda-ubuntu-20.04:cuda-11.0.3 + +# docker build -f Dockerfile.base -t ghcr.io/mfem/mfem-ubuntu-base . + +RUN apt-get update && \ + apt-get install -y unzip gfortran && \ + spack compiler find && \ + apt-get install -y libcurl4-openssl-dev libssl-dev + +# /code is the working directory for code +WORKDIR /code +COPY . /code + +# This is for a spack environment/view to install from there +RUN mkdir -p /opt/mfem-env \ +&& (echo "spack:" \ +&& echo " view:" \ +&& echo " mfem:" \ +&& echo " root: /opt/mfem-view" \ +&& echo " link_type: copy" \ +&& echo " packages:" \ +&& echo " all:" \ +&& echo " target:" \ +&& echo " - x86_64_v3" \ +&& echo " config:" \ +&& echo " concretizer: clingo" \ +&& echo " compiler:" \ +&& echo " target:" \ +&& echo " - x86_64_v3" \ +&& echo " install_missing_compilers: true" \ +&& echo " concretization: together") > /opt/mfem-env/spack.yaml + +RUN cd /opt/mfem-env && \ + . /opt/spack/share/spack/setup-env.sh && \ + spack env activate . && \ + spack develop --path /code mfem@master+examples+miniapps && \ + spack add mfem@master+examples+miniapps # && \ +# spack install + +# ensure mfem always on various paths +#RUN cd /opt/mfem-env && \ +# spack env activate --sh -d . >> /etc/profile.d/z10_spack_environment.sh + +# Present the software install when we shell in +# The view is at /opt/mfem-env/.spack-env/view +#WORKDIR /opt/software +#ENTRYPOINT ["/bin/bash", "--rcfile", "/etc/profile", "-l", "-c"] diff --git a/config/docker/README.md b/config/docker/README.md index 8d943b27d9b..ed4c965dfbd 100644 --- a/config/docker/README.md +++ b/config/docker/README.md @@ -1,7 +1,8 @@ # mfem Docker -We provide a [Dockerfile](Dockerfile) to build an ubuntu base image. You can use -this image for a demo of using mfem! 🎉️ +We provide a [Dockerfile.base](Dockerfile.base) to build an ubuntu base image, +and a [Dockerfile](Dockerfile) to build a smaller one with a multi-stage build. +You can use this image for a demo of using mfem! 🎉️ Updated containers are built and deployed on merges to the main branch and releases. If you want to request a build on demand, you can [manually run the workflow](https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow) thanks to the workflow dispatch event. @@ -14,18 +15,40 @@ is the [GitHub packages](https://github.com/features/packages) registry that sup Docker images and other OCI artifacts. From the root of the repository: ```bash -$ docker build -f config/docker/Dockerfile -t ghcr.io/mfem/mfem-ubuntu-base . +$ docker build -f config/docker/Dockerfile -t ghcr.io/mfem/mfem-ubuntu . +$ docker build -f config/docker/Dockerfile.base -t ghcr.io/mfem/mfem-ubuntu-base . ``` or this directory: ```bash -$ docker build -f Dockerfile -t ghcr.io/mfem/mfem-ubuntu-base ../../ +$ docker build -f Dockerfile -t ghcr.io/mfem/mfem-ubuntu ../../ +$ docker build -f Dockerfile.base -t ghcr.io/mfem/mfem-ubuntu-base ../../ ``` -### Shell +### Shell Ubuntu -To shell into a container (here is an example with ubuntu): +To shell into the container: + +```bash +$ docker run -it ghcr.io/mfem/mfem-ubuntu +``` + +This smaller image has a view where everything is installed. + +```bash +$ ls +bin etc include lib libexec sbin share var +``` + + - Examples are in share/mfem/examples + - Examples are in share/mfem/miniapps + +You can read more about interaction with these examples and miniapps below. + +### Shell Ubuntu Base + +To shell into the container: ```bash $ docker run -it ghcr.io/mfem/mfem-ubuntu-base bash @@ -128,3 +151,4 @@ $ docker run -it ghcr.io/mfem/mfem-ubuntu-base -v $PWD:/src bash In the above, we can pretend your project is in the present working directory (PWD) and we are binding to source. You can then use the mfem in the container for development, and if you want to distribute your library or app in a container, you can use the mfem container as the base. + diff --git a/config/docker/spack.yaml b/config/docker/spack.yaml new file mode 100644 index 00000000000..596d5c900b4 --- /dev/null +++ b/config/docker/spack.yaml @@ -0,0 +1,11 @@ +spack: + specs: [mfem@master+examples+miniapps] + view: + mfem: + root: /opt/mfem-view + link_type: copy + concretization: together + develop: + mfem: + path: /code + spec: mfem@master+examples+miniapps