From 5b2fd4ac2c1dbbfc076aa0b5c9f28ee173e17897 Mon Sep 17 00:00:00 2001
From: B13nch3n <b13nch3n_01@theb-si.de>
Date: Thu, 6 Oct 2022 17:50:49 +0200
Subject: [PATCH] Start Docker Readme

---
 projects/.dockerignore           | 10 ++++
 projects/README.md               |  2 +
 projects/docker/Dockerfile       | 80 ++++++++++++++++++++++++++++++++
 projects/docker/README.md        | 51 ++++++++++++++++++++
 projects/docker/requirements.txt |  2 +
 5 files changed, 145 insertions(+)
 create mode 100644 projects/.dockerignore
 create mode 100644 projects/docker/Dockerfile
 create mode 100644 projects/docker/README.md
 create mode 100644 projects/docker/requirements.txt

diff --git a/projects/.dockerignore b/projects/.dockerignore
new file mode 100644
index 0000000..124498b
--- /dev/null
+++ b/projects/.dockerignore
@@ -0,0 +1,10 @@
+# Exclude files from build context that are not used to build the Docker image.
+# Helps speeding up a build since less files are copied.
+# Only works when this directory is build context.
+
+# Exclude all kinds of README
+**/README*
+
+# Exclude any "test*" directories & files in the individual project directories.
+# Test data is not part of the Docker image. If needed, mount at run time.
+**/test*
diff --git a/projects/README.md b/projects/README.md
index 46c4ba9..0954308 100644
--- a/projects/README.md
+++ b/projects/README.md
@@ -4,5 +4,7 @@ This directory tree contains tools/ code from past modelling projects converted
 
 Each project should come with a small README explaining the modelling project. This will help you checking if your project is of same kind.
 
+The [`docker`](projects/docker/) directory does not host a modelling project. It keeps the set up of a [Docker](https://www.docker.com) image that can be used to run the converter tools from the various projects.
+
 <!--  LocalWords:  README
  -->
diff --git a/projects/docker/Dockerfile b/projects/docker/Dockerfile
new file mode 100644
index 0000000..6aea2ac
--- /dev/null
+++ b/projects/docker/Dockerfile
@@ -0,0 +1,80 @@
+ARG VERSION_OST="2.3.0"
+FROM registry.scicore.unibas.ch/schwede/openstructure:${VERSION_OST}
+## We need to declare ARGs again which were declared before the build stage
+## (FROM directive), otherwise they won't be available in this stage.
+ARG VERSION_OST
+
+
+## Set up environment
+ENV SRC_DIR="/tmp" \
+    VERSION_OST=${VERSION_OST} \
+    PYTHONUNBUFFERED=1 \
+    PYTHONDONTWRITEBYTECODE=1
+
+
+LABEL org.openstructure.base-image="${VERSION_OST}"
+LABEL maintainer="Stefan Bienert <stefan.bienert@unibas.ch>"
+LABEL vendor1="Schwede Group (schwedelab.org)"
+LABEL vendor2="SIB - Swiss Institute of Bioinformatics (sib.swiss)"
+LABEL vendor3="Biozentrum - University of Basel (biozentrum.unibas.ch)"
+
+
+## Install python-modelcif and python-ihm
+COPY docker/requirements.txt ${SRC_DIR}
+WORKDIR ${SRC_DIR}
+RUN set -e pipefail; \
+    apt-get update -y; \
+    apt-get install -y git pip; \
+    pip install -r requirements.txt; \
+    ## use the python-ihm latest
+    git clone https://github.com/ihmwg/python-ihm.git ihm.git; \
+    cd ihm.git; \
+    python3 setup.py build; \
+    python3 setup.py install; \
+    cd ${SRC_DIR}; \
+    rm -rf ${SRC_DIR}/ihm.git; \
+    ## use python-modelcif latest
+    git clone https://github.com/ihmwg/python-modelcif.git modelcif.git; \
+    cd modelcif.git; \
+    python3 setup.py build; \
+    python3 setup.py install; \
+    cd ${SRC_DIR}; \
+    rm -rf ${SRC_DIR}/modelcif.git; \
+    rm -rf /var/lib/apt/lists/*; \
+    apt-get purge -y --auto-remove git pip gcc
+
+## Add a dedicated user
+## MMCIF_USER_ID can be used to avoid file permission issues.
+ARG MMCIF_USER_ID=501
+RUN adduser --system -u ${MMCIF_USER_ID} mmcif
+
+
+COPY --chmod=755 docker/entrypoint.sh /
+
+
+## Copy tool(s)
+ARG CONVERTERSCRIPT=CoFFE-sponge-proteins/translate2modelcif.py
+COPY --chmod=755 $CONVERTERSCRIPT /usr/local/bin/convert2modelcif
+
+
+## Add development setup
+ARG ADD_DEV
+RUN set -e pipefail; \
+    if test xYES = x`echo ${ADD_DEV} | tr '[:lower:]' '[:upper:]'`; then \
+      apt-get update -y; \
+      apt-get install -y emacs; \
+      pip install pylint black; \
+      apt-get purge -y --auto-remove pip; \
+    fi
+
+
+USER mmcif
+
+
+ENTRYPOINT ["/entrypoint.sh"]
+
+# LocalWords:  ARG OST ARGs ENV SRC tmp PYTHONUNBUFFERED Schwede schwedelab py
+# LocalWords:  PYTHONDONTWRITEBYTECODE Bioinformatics sib swiss Biozentrum ihm
+# LocalWords:  modelcif txt WORKDIR pipefail chmod adduser mmcif ENTRYPOINT cd
+# LocalWords:  pylint rf entrypoint gcc CONVERTERSCRIPT CoFFE DEV xYES emacs
+# LocalWords:  fi
diff --git a/projects/docker/README.md b/projects/docker/README.md
new file mode 100644
index 0000000..36a0d91
--- /dev/null
+++ b/projects/docker/README.md
@@ -0,0 +1,51 @@
+# Docker container (base) for the converter software
+
+This directory contains all the files needed to create the base [Docker](https://www.docker.com) image used for the converter software in [`projects`](projects/).
+
+A specific project's translation script can be executed either in an app like manner (*I.O.U. a link to the anchor here*), calling it directly from within the container, using a local copy executed by the container (*I.O.U. a link to the anchor here*), or in an interactive shell within the container (*I.O.U. a link to the anchor here*).
+
+[[_TOC_]]
+
+
+## Building & running the Docker container
+
+This is a quick tour on how to build and run the Docker container through different scenarios. This is not a lecture on containerisation in general, nor Linux/ Unix, shell scripting or programming. But if you encounter a specific problem, feel free to ping the [MA team](https://modelarchive.org/contact).
+
+This section describes three use cases of the Docker container (including a build-how to per use case) but starts with a short primer of what is common to all scenarios described here.
+
+
+### Prerequisites
+
+<!--
+- Do single example call
+- show how to loop
+
+1. App like
+- special build
+- own run command
+2. Local copy
+- works with every build
+- own run command
+3. Interactive shell
+- works with every build
+- most complicated run bit
+-->
+
+<!--
+build:
+- go into repo projects dir
+- execute: docker build -f docker/Dockerfile -t mmcifconverter:20220427 .
+- explain how to install a dedicated converter script in the container
+- mention how to change user
+- mention dev stuff
+- mention script is copied to a unified name for the container to work with a single entrypoint script
+
+run interactive shell for development:
+- make sure files exist: /Users/stefan/Projects/ma-converters.git/projects/pointmutations-haddock/.docker-bash-history
+- execute:
+docker run --rm -i -v /Users/stefan/.bash_profile:/home/mmcif/.bash_profile -v /Users/stefan/.bash_aliases:/home/mmcif/.bash_aliases -v /Users/stefan/.bashrc:/home/mmcif/.bashrc -v /Users/stefan/Projects/ma-converters.git/projects/pointmutations-haddock/.docker-bash-history:/home/mmcif/.bash_history -v /Users/stefan/Projects/ma-converters.git/:/develop -t mmcifconverter:20220427 bash
+
+ -->
+
+<!--  LocalWords:  TOC
+ -->
diff --git a/projects/docker/requirements.txt b/projects/docker/requirements.txt
new file mode 100644
index 0000000..2abd7d3
--- /dev/null
+++ b/projects/docker/requirements.txt
@@ -0,0 +1,2 @@
+requests
+ujson
-- 
GitLab