Skip to content

Commit

Permalink
adding multistage-build for slimmer container
Browse files Browse the repository at this point in the history
I am currently running into an issue where when I shell inside my backspace turns
into a forward space, and I am hoping someone can reproduce to determine if there
is a bug we need to track down or if I am just a nut :)

Signed-off-by: vsoch <[email protected]>
  • Loading branch information
vsoch committed May 16, 2022
1 parent aef9723 commit bc5fbe7
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build-container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 18 additions & 22 deletions config/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
47 changes: 47 additions & 0 deletions config/docker/Dockerfile.base
Original file line number Diff line number Diff line change
@@ -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"]
36 changes: 30 additions & 6 deletions config/docker/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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.

11 changes: 11 additions & 0 deletions config/docker/spack.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bc5fbe7

Please sign in to comment.