From 05b61f6756836a5187f6f25bfa6196199127337f Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Thu, 15 Feb 2024 21:58:23 +0100 Subject: [PATCH] Add docker file and update README --- .github/workflows/docker-image.yml | 74 ++++++++++++++++++++++++++++++ Dockerfile | 0 README.md | 18 +++++++- docker/Dockerfile | 27 +++++++++++ runtime.txt | 1 + 5 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/docker-image.yml delete mode 100644 Dockerfile create mode 100644 docker/Dockerfile create mode 100644 runtime.txt diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..f814331 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,74 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Create and publish a Docker image + +on: + push: + branches: + - "!*" + tags: + - "v*" + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + LAB_NAME: lab + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for base-image + id: meta-base + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name == 'push' }} + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta-base.outputs.tags }} + labels: ${{ steps.meta-base.outputs.labels }} + target: base + + - name: Extract metadata (tags, labels) for lab images + id: meta-lab + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ env.LAB_NAME }} + + - name: Build and push Docker lab image + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name == 'push' }} + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta-lab.outputs.tags }} + labels: ${{ steps.meta-lab.outputs.labels }} + target: lab diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index e69de29..0000000 diff --git a/README.md b/README.md index 1ba64c2..a722dad 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,11 @@ This repository contains supplementary code for reproducing results in the paper The code is heavily based on the library [`mps-motion`](https://github.com/ComputationalPhysiology/mps_motion). Please check out the [documentation](https://computationalphysiology.github.io/mps_motion/) in that library for more details. ## Running with binder -If you want to run the examples without installing anything you can launch an interactive environment with Binder, by clicking the following button: TODO: Add button +If you want to run the examples without installing anything you can launch an interactive environment with Binder, by clicking the following button [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/ComputationalPhysiology/automatic-motion-estimation-hiPSC-CM/HEAD) ## Running locally + +### Python virtual environment To run the notebooks locally, you first need to install the necessary requirements. There are two options. Either, you can create a virtual environment with python ``` python3 -m venv venv @@ -26,3 +28,17 @@ Next you install the dependencies ``` python3 -m pip install -r requirements.txt ``` + +### Docker + +We also provide two different docker images for you. In order to start a container you can use the docker run command. For example the command +``` +docker run --rm -v $(pwd):/home/shared -w /home/shared -ti ghcr.io/computationalphysiology/automatic-motion-estimation-hiPSC-CM:latest +``` +will run the latest version and share your current working directory with the container. The source code of the repository is located at `/repo` in the docker container. + +To run the notebooks, one can use `ghcr.io/computationalphysiology/automatic-motion-estimation-hiPSC-CM-lab:latest`, i.e +``` +docker run -ti -p 8888:8888 --rm ghcr.io/computationalphysiology/automatic-motion-estimation-hiPSC-CM-lab:latest +``` +to run interactively with Jupyter lab in browser. diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..d5a78a7 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,27 @@ +from ubuntu:22.04 as base + +RUN apt-get update && apt-get install -y python3-pip gcc python3-dev && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /repo + +COPY requirements.txt /repo + +RUN python3 -m pip install --upgrade pip +RUN python3 -m pip install --no-cache-dir -r requirements.txt +# Install the headless version of opencv in docker +RUN python3 -m pip uninstall -y opencv-python opencv-contrib-python +RUN python3 -m pip install --no-cache-dir opencv-python-headless opencv-contrib-python-headless + + +COPY . /repo + +FROM base as lab + +# Had some issues with psutil (needed by jupyter) on aarch64, so need to install it from source +RUN python3 -m pip install --no-cache-dir psutil --no-binary=psutil +RUN python3 -m pip install --no-cache-dir jupyter + +EXPOSE 8888/tcp +ENTRYPOINT [ "jupyter", "lab", "--ip", "0.0.0.0", "--port", "8888", "--no-browser", "--allow-root"] diff --git a/runtime.txt b/runtime.txt new file mode 100644 index 0000000..5509089 --- /dev/null +++ b/runtime.txt @@ -0,0 +1 @@ +python-3.10