Skip to content

Instantly share code, notes, and snippets.

@KonstantinSchubert
Last active January 13, 2016 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KonstantinSchubert/9c6802753f67e7d19dfe to your computer and use it in GitHub Desktop.
Save KonstantinSchubert/9c6802753f67e7d19dfe to your computer and use it in GitHub Desktop.
Script that generates Dockerfiles containting an ubuntu 14.04 with different versions of CERN's ROOT. The Dockerfiles are stored in this repository: https://github.com/KonstantinSchubert/ROOT_Dockerfiles And the resulting images can be found on https://hub.docker.com/r/schubertkonstantin/cern_root/
import subprocess
import os
import re
dockerfile_template = \
"""FROM schubertkonstantin/root:dependencies
MAINTAINER Konstantin Schubert <schubert.konstantin@gmail.com>
# based on a Dockerfile by Sebastian Neubert
USER root
#trying to fix failing installs
RUN apt-get -y install ncurses-dev libncurses5
WORKDIR /tmp
# clone ROOT
# By cloning all branches, we get the same base image for all builds
RUN git clone --depth 1 --branch {root_version} http://root.cern.ch/git/root.git
# install ROOT
RUN mkdir root-build \
&& cd root-build \
&& cmake ../root -Dmathmore=ON -Dminuit2=ON -Droofit=ON -Dhdfs=OFF -Dbuiltin_xrootd=ON -DCMAKE_INSTALL_PREFIX=/usr/local \
&& make -j3 \
&& cmake --build . --target install \
&& cd .. \
&& rm -rf root root-build
ENV LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH
ENV PYTHONPATH /usr/local/lib:$PYTHONPATH
"""
# clone or update the root repo
if os.path.exists("root"):
p = subprocess.Popen(["git", "pull" ], cwd="./root/")
p.communicate()
else:
p = subprocess.Popen(["git", "clone", "http://root.cern.ch/git/root.git"], cwd=".")
p.communicate()
# collect branches
p = subprocess.Popen(["git", "branch", "-a" ], cwd="./root/", stdout=subprocess.PIPE)
out, _ = p.communicate()
regex = re.compile(r'(v\d-\d\d-\d\d?\S+)')
root_branches = regex.findall(out)
# clone or update the dockerfile repo
if os.path.exists("./ROOT_Dockerfiles/"):
p = subprocess.Popen(["git", "pull" ], cwd="./ROOT_Dockerfiles/")
p.communicate()
else:
subprocess.check_output(["git", "clone", "git@github.com:KonstantinSchubert/ROOT_Dockerfiles.git"])
# collect branches
p = subprocess.Popen(["git", "branch" ], cwd="./ROOT_Dockerfiles/", stdout=subprocess.PIPE)
out, _ = p.communicate()
regex = re.compile(r'(v\d-\d\d-\d\d?\S+)')
dockerfile_branches = regex.findall(out)
print root_branches
print dockerfile_branches
# for branches that have no branches yet, create branches and dockerfiles
for branch in root_branches:
if branch in dockerfile_branches:
p = subprocess.Popen(["git", "checkout", branch ], cwd="./ROOT_Dockerfiles/")
p.communicate()
else:
p = subprocess.Popen(["git", "checkout", "-b", branch ], cwd="./ROOT_Dockerfiles/")
p.communicate()
for file_name in os.listdir("./ROOT_Dockerfiles"):
if "dockerignore" not in file_name and ".git" not in file_name:
os.remove("./ROOT_Dockerfiles/"+file_name)
with open("./ROOT_Dockerfiles/Dockerfile","w") as dockerfile:
dockerfile.write(dockerfile_template.replace("{root_version}",branch))
p = subprocess.Popen(["git", "add", "--all"], cwd="./ROOT_Dockerfiles/")
p.communicate()
p = subprocess.Popen(["git", "commit", "-m", "automatic commit for "+branch], cwd="./ROOT_Dockerfiles/")
p.communicate()
p = subprocess.Popen(["git", "push", "--set-upstream", "origin", branch], cwd="./ROOT_Dockerfiles/")
p.communicate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment