From 193fee016b73e85392b2b26e57187861936f7cc9 Mon Sep 17 00:00:00 2001 From: vsoch Date: Sat, 4 Feb 2023 16:49:07 -0700 Subject: [PATCH] add docker container and automated build for quick demo or usage Signed-off-by: vsoch --- .github/workflows/build-deploy.yaml | 50 +++++++++++++++++++++++++++++ Dockerfile | 32 ++++++++++++++++++ README.md | 40 +++++++++++++++++++++++ entrypoint.sh | 5 +++ 4 files changed, 127 insertions(+) create mode 100644 .github/workflows/build-deploy.yaml create mode 100644 Dockerfile create mode 100755 entrypoint.sh diff --git a/.github/workflows/build-deploy.yaml b/.github/workflows/build-deploy.yaml new file mode 100644 index 00000000..70e07739 --- /dev/null +++ b/.github/workflows/build-deploy.yaml @@ -0,0 +1,50 @@ +name: Build Deploy Containers + +on: + + # Publish packages on release + release: + types: [published] + + pull_request: [] + + # On push to main we build and deploy images + push: + branches: + - main + +jobs: + build: + permissions: + packages: write + + env: + container: ghcr.io/magic-sph/magic + runs-on: ubuntu-latest + name: Build + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Build Container + run: docker build -t ${{ env.container }} . + + - name: GHCR Login + if: (github.event_name != 'pull_request') + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Tag and Push Release Image + if: (github.event_name == 'release') + run: | + tag=${GITHUB_REF#refs/tags/} + echo "Tagging and releasing ${{ env.container }}:${tag}" + docker tag ${{ env.container }}:latest ${{ env.container }}:${tag} + docker push ${{ env.container }}:${tag} + + - name: Deploy + if: (github.event_name != 'pull_request') + run: docker push ${{ env.container }}:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..c5e0907c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM ubuntu:22.04 + +# This is a demo container for testing magic! +# docker build -t magic . + +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update && apt-get install -y \ + build-essential \ + cmake \ + fftw3-dev fftw3 \ + gfortran \ + git \ + libmpich-dev \ + python3 \ + python3-matplotlib \ + python3-f2py \ + wget && \ + ln -s /usr/bin/python3 /usr/bin/python + +WORKDIR /code +COPY . /code + +# install SHTns with fft, then build magic and run (and build) samples +RUN /bin/bash -c ". sourceme.sh && \ + cd ./bin && \ + CC=gcc ./install-shtns.sh && \ + cd ../ && mkdir -p ./build && cd ./build && \ + FC=mpif90 cmake .. -DUSE_SHTNS=yes && make && \ + cd ../samples && \ + ./magic_wizard.py --use-mpi --nranks 4 --mpicmd mpiexec" + +ENTRYPOINT ["/code/entrypoint.sh"] diff --git a/README.md b/README.md index e088443d..3a6a085c 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,46 @@ # Quickly start using MagIC +## Docker + +We provide a [Dockerfile](Dockerfile) for a quick environment you can use magic! It +comes with an ubuntu base, mpich (mpif90), and installs SHTns. + +```bash +$ docker build -t magic . +``` + +Note that we build samples and run them (for testing) so the build takes a bit of time. +When it's done, let's now try interacting with the container. Note that the [entrypoint.sh](entrypoint.sh) script sources [sourceme.sh](sourceme.sh) +before executing your command, and thus will ensure the environment is ready. + +```bash +# Ensure that the file is sourced +$ docker run --rm -it magic env | grep MAGIC_HOME +``` +```console +MAGIC_HOME = +MAGIC_HOME=/code +``` + +To shell inside and interact: + +```bash +$ docker run -it magic bash +``` + +And the environment should be ready, e.g., + +```bash +cd /code/samples +./magic_wizard.py --use-mpi --nranks 4 --mpicmd mpiexec +``` + +And that's it! This container is also available via an automated build `ghcr.io/magic-sph/magic` if you want to +pull it directly. For a customized or local install, continue to the next section. + +## Local Install + ### 1) In order to check out the code, use the command ```sh diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 00000000..bb6d3166 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +. /code/sourceme.sh + +exec $@